smhg / gettext-parser

Parse and compile gettext po and mo files, nothing more, nothing less
MIT License
158 stars 43 forks source link

lowercase header transformation destroys custom headers of translation software #52

Closed Connum closed 4 years ago

Connum commented 4 years ago

When parsing a pot file with this package, all header names are transformed to lowercase first, then upon saving, each letter after a dash in the name is transformed to uppercase. However, some translation software writes custom headers that are case-sensitive, like Poedit:

"X-Poedit-KeywordsList: "
"__;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,"
"2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__"
"ngettext_noop:1,2\n"
"X-Source-Language: en\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.min.js\n"

After handling my pot file with this package, I'm no longer able to update the translation strings from source in Poedit, because they are now written like this:

"X-Poedit-Keywordslist: "
"__;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,"
"2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__"
"ngettext_noop:1,2\n"
"X-Source-Language: en\n"
"X-Poedit-Searchpath-0: .\n"
"X-Poedit-Searchpathexcluded-0: *.min.js\n"

Could you add an option to keep the header names untouched (or it might be a good idea not transforming any custom headers starting with X- by default?)? Or is Poedit simply violating some standards regarding header naming convention in pot files?

smhg commented 4 years ago

Which version of gettext-parser are you using?

Connum commented 4 years ago

The latest version on npm, 4.0.2

vslavik commented 4 years ago

Or is Poedit simply violating some standards regarding header naming convention in pot files?

Poedit developer here: GNU gettext headers are case sensitive. E.g. changing Language to language will cause all GNU gettext tools such as msgfmt to warn about missing Language header.

smhg commented 4 years ago

@Connum I can't reproduce this with 4.0.2. Previous versions had this behavior though. Can you please make sure (npm ls gettext-parser) you are not using multiple versions?

Since v4 custom headers should not be touched. Only for a fixed list of predefined gettext headers casing is enforced.

Please feel free to send a PR containing a test that replicates this behavior. Or at least attach a valid PO(T) file. I'll investigate further.

Connum commented 4 years ago

Ha! I'm also using the package po2json and it turns out I missed that it's using gettext-parser 2.0.0 as a dependency. That might be the issue, although I think I'm just using this to convert translations to jed and not for saving that data back to the pot file. I'll see if I can create a simple example repo to reproduce this.

Connum commented 4 years ago

Sorry for my stupidity and wasting your time... It was indeed a package using an older version of gettext-parser that caused the trouble.

smhg commented 4 years ago

No problem! Thanks for the update!