angular-gettext-tools
angular-gettext-tools copied to clipboard
Make alphabetic sorting optional when extracting
Strings are sorted here: https://github.com/rubenv/angular-gettext-tools/blob/master/lib/extract.js#L272
Please make this optional, as it is much easier to insert translations in translation software from already translated documents when they appear in the same order as in the original document.
This should be an option for the grunt and gulp plugins as well of course.
For now, I'll just locally comment it out, extract and comment it back in :)
How about going one further and allowing custom sorting functions? This way you could sort by file first and then by msgid, or apply whatever sorting algo your tooling is using.
And of course you could also apply a NOOP sorting function.
I am having an issue here as well.
Strings are sorted alphabetically by msgid in the extracted .POT file.
I have a long string with two plurals to replace, so I have broken this string into two (one part for each plural replacement), and left a comment above each to notify the translator that they are part of the same string (i.e. part-a and part-b).
However, instead of the resulting .POT file being ordered by line-number and allowing these comments to form a context/story for the translator about where these strings fit into the file, they are ordered alphabetically and the comments have lost meaning.
Is there no way of ordering the resulting msgid's in the .POT by line-number?
What we can do is sort the strings by what file and line they're found in. For example, a string in file A line 1 would come before a string in file A line 2 which would come before a string in file B in the POT.
But what about strings that occur multiple times? Those strings will be combined into one msgid, thus messing up your ordering.
Also, what do other implementations of xgettext do in terms of sorting? I think last I looked sorting alphabetically was the norm.
On Wednesday, December 9, 2015, Dan May [email protected] wrote:
I am having an issue here as well.
Strings are sorted alphabetically by msgid in the extracted .POT file.
I have a long string with two plurals to replace, so I have broken this string into two (one part for each plural replacement), and left a comment above each to notify the translator that they are part of the same string (i.e. part-a and part-b).
However, instead of the resulting .POT file being ordered by line-number and allowing these comments to form a context/story for the translator about where these strings fit into the file, they are ordered alphabetically and the comments have lost meaning.
Is there no way of ordering the resulting msgid's in the .POT by line-number?
— Reply to this email directly or view it on GitHub https://github.com/rubenv/angular-gettext-tools/issues/62#issuecomment-163206821 .
For comparison:
I also have Flask-Babel installed in my project, for Python files and Jinja2 html templates. The resulting .POT is sorted by file, then by line number, using the bog-standard extract method.
I think the likelihood of a complex string that is broken into two parts, appearing identically in another file is unlikely. Of course not impossible, and in cases where it does happen I don't think it can be avoided to have the ordering of comments altered. For the majority of use cases I think it would be preferable to have file ordering, then line number ordering for each file.
e.g.
This code:
# NOTE: part a
comment_test = _(u'first part')
# NOTE: part b
comment_test_2 = _(u'second part')
context_test = pgettext(u'One', u'first part')
context_test2 = pgettext(u'Two', u'second part')
Exists somewhere else as:
# NOTE: part a1
comment_test = _(u'first part')
# NOTE: part b1
comment_test_2 = _(u'second part')
context_test = pgettext(u'Three', u'first part')
context_test2 = pgettext(u'Four', u'second part')
Results in:
#. NOTE: part a1 #. NOTE: part a #: test_strings.py:6 views.py:56 msgid "first part" msgstr ""
#. NOTE: part b1 #. NOTE: part b #: test_strings.py:9 views.py:59 msgid "second part" msgstr ""
#: test_strings.py:11 msgctxt "Three" msgid "first part" msgstr ""
#: test_strings.py:12 msgctxt "Four" msgid "second part" msgstr ""
#: views.py:61 msgctxt "One" msgid "first part" msgstr ""
#: views.py:62 msgctxt "Two" msgid "second part" msgstr ""
So it looks like it's doing alphabetical order for files, then by line-number.
In the GNU gettext tools (where gettext was made up originally) sorting alphabetically is supported but not promoted as the default method. With the --sort-output parameter the output of xgettext (which extracts the Strings) is sorted. However in their documentation the GNU gettext authors issue the following warning: 'Note that using this option makes it much harder for the translator to understand each message’s context.' (see https://www.gnu.org/software/gettext/manual/html_node/xgettext-Invocation.html).
So from the view of the original authors the alphabetical sorting in the .pot file is rather a possible but not promoted solution than wanted default behaviour.
If you could make the solution "sort the strings by what file and line they're found in" work ,this would be a great enhancement for use cases in which the translators only have a working app as reference. So for example if they have a web form to be translated they can go through that form field by field and more or less have the matching order in the .po file instead of having to find out for each field where the corresponding string is in the .po file. I know that this is not 100% sure because strings can be in multiple files and so on, but for a great percentage it will work.