Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: file globbing #272

Open
paususe opened this issue Sep 30, 2020 · 2 comments
Open

Feature request: file globbing #272

paususe opened this issue Sep 30, 2020 · 2 comments

Comments

@paususe
Copy link
Collaborator

paususe commented Sep 30, 2020

(Per our discussion on IRC)

Please implement file globbing in po4a configuration files.

Sometimes you have a lot of source files and listing them one by one, and keeping the list updated, is cumbersome and prone to failure.

As an example, in some of the documentation guides in Uyuni we have 170+ source AsciiDoc files. Instead of listing each and every .adoc file under e. g. modules/reference (including subdirectories!):

[type: asciidoc] modules/administration/_attributes.adoc $lang:translations/$lang/modules/administration/_attributes.adoc
[type: asciidoc] modules/administration/pages/live-patching.adoc $lang:translations/$lang/modules/administration/pages/live-patching.adoc
[type: asciidoc] modules/administration/pages/master-fingerprint.adoc $lang:translations/$lang/modules/administration/pages/master-fingerprint.adoc
[type: asciidoc] modules/administration/pages/mirror-sources.adoc $lang:translations/$lang/modules/administration/pages/mirror-sources.adoc
...(imagine 175 lines like that)...

it would be so much easier and convenient to be able to say

[type: asciidoc opt=recurse] modules/administration/*.adoc $lang:translations/$lang/modules/administration/*.adoc

Sample po4a config files here:
https://github.com/paususe/uyuni-docs/tree/paususe-po4a-config-file/l10n-weblate

@mquinson
Copy link
Owner

mquinson commented Oct 1, 2020

Hello, thanks for the report.

Indeed, that would be very possible to do, for example using this tutorial. I would probably use this syntax instead (no recurse option which meaning is not clear to me, $master component in the translation filename instead):

[type: asciidoc] modules/administration/*.adoc $lang:translations/$lang/modules/administration/$master

The only question is about when I'll find the time to implement it because things are really crazy IRL for me. Help would be welcome.

I guess that I would search in po4a where the config file is parsed (where the $document hash table is populated), and then, I'd add some code just before the hash initialization, to iterate over all globbed files. I guess it's here: https://github.com/mquinson/po4a/blob/master/po4a#L1197

In that location, I'd detect whether the master file contains a * in its name while the translation file contains a $master in its name (if only one of these conditions is met, make an error message). Something like

  if ($master =~ m/\*/ && $master =~ m/\$master/) # both * and $ need to be protected in the regular expression

If so, populate an array with all the matching file names using the previously cited tutorial.

Then the whole code block that populates the $document hash would need to be enclosed in a loop traversing the previously populated array of all actual master file. Here is an example of such a loop in Perl.

Then, the doc would need to be updated, probably at the end of this paragraph.

And finally, a new test case should be added, for example copying this one into a multidoc directory, renaming all the files from multiple to multidoc, and then adding this new test case in the corresponding test suite description. Or maybe you want to create a new test suite description (simply creating a new similar file which name ends with .t should enroll it in the test suite). Maybe derivating the single test case instead of multiple is better because you don't necessary want to test with multiple languages. I'm not sure.
If you want to make the things perfect, you could add several multidoc tests, similarly to the existing multiple or single ones: when nor the PO nor the POT files exist; when only one of them exist; when the PO content needs to be fuzzied according to the master doc; when the translation file does not exist yet; when everything is already uptodate, etc.

@petterreinholdtsen
Copy link

For the record, while implementing use of po4a for linuxcnc (LinuxCNC/linuxcnc#1356), I felt the need for such file globbing feature too. :)

mquinson added a commit that referenced this issue Dec 1, 2021
This is a pity that we missed them. We really need
#272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants