potools icon indicating copy to clipboard operation
potools copied to clipboard

Add correct relative paths to source files.

Open eliocamp opened this issue 4 years ago • 7 comments

I'm starting to use this package. I created the .pot file to my package and I noticed that the way it writes source file locations is not compatible with poedit.

For instance if a string is in R/Derivate.R, the generated .pot looks like this:

#: Derivate.R:102
msgid "One boundary condition per variable needed."
msgstr ""

If I open the file on poedit and right click on the string, it cannot open the sour cefile. If I change it to this, however:

#: R/Derivate.R:102
msgid "One boundary condition per variable needed."
msgstr ""

Now it works.

eliocamp avatar Jul 08 '21 19:07 eliocamp

Thanks for the first external issue report!

I'm a bit torn on this one... the current behavior is designed around how base R does things, e.g.

https://github.com/wch/r-source/blob/3a8ed6e19950cd62721648b6470dd0c8106baf29/src/library/stats/po/fr.po#L21

By your suggestion, the path would have to be src/Srunmed.c.

The situation for base is even worse, where the .pot file is at $R_DEVEL/src/library/base/po/*.pot and the source references there are relative to $R_DEVEL.

Is there an option to set the relative directory for poedit, or to run poedit from inside the R directory to begin with?

If not, I can try to think of an option that would either let the user pick a directory relative to which the paths are given, or more simplistically to toggle paths to be relative to the dir argument.

I will also try and find some other projects & see what they've done on this front. We might be better tailoring to how .pot files are usually handled & even file a bug with R to get them to conform to that if there seems to be a consensus.

(PS, note that base R doesn't provide any source markers in the R-*.pot files, so I'm glad we're seeing some payoff already to my efforts to include them!)

MichaelChirico avatar Jul 09 '21 00:07 MichaelChirico

FIRST! :woman_dancing: :

Is it different between C files and R files? I'm looking at here, for example, and source files paths are written relative to the root directory.

#: src/appl/optim.c:60
msgid "non-finite value supplied by 'optim'"
msgstr "nicht endlicher Wert von 'optim' übergeben"

I don't know how poedit figures out the root directory, though, but with these files, I can just double click on them and it automatically works. I tried to to the same with the file you highlighted and poedit didn't find the source file, though.

EDIT: After looking at other files, it seems that base is the only package that writes source files relative to root. All the others I've looked at have just the name. Seems to be because the files listed on base are outside the base folder.

eliocamp avatar Jul 09 '21 12:07 eliocamp

yep the base case is unique -- base includes the files in po/POTFILES (that po is TLD of r-devel).

and yes, R & C sides are different using the base R tooling because gettext doesn't have direct support for R -- instead R has tools::xgettext2pot() for writing (very minimalist) .pot files.

potools tries to eliminate the divergence of the two

MichaelChirico avatar Jul 09 '21 15:07 MichaelChirico

Would something like #194 be a good backup here?

I can relatively easily run

rstudioapi::sourceMarkers()

Which we can click through to the source. I'm still not sure how exactly to use that/combine it with the interactive translation workflow but it's there...

MichaelChirico avatar Jul 12 '21 07:07 MichaelChirico

That would work only during interactive translation in potools, but it won't solve any issues with other tooling, if understand correctly?

eliocamp avatar Jul 12 '21 13:07 eliocamp

right... lateral progress :)

MichaelChirico avatar Jul 12 '21 15:07 MichaelChirico

That would work wonderfully for correcting problematic strings, I think.

eliocamp avatar Jul 12 '21 16:07 eliocamp