lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.54k stars 380 forks source link

Add default message to PO file #319

Closed tricoder42 closed 6 years ago

tricoder42 commented 6 years ago

Is your feature request related to a problem? Please describe. While working with PO files I've found that

  1. catalog for source locale has filled translations with default message. I'm not arguing if it's good or bad, but it's definitely different than how lingui or minimal format works. These formats have empty translations in source locale catalog and default message is used during compile.

  2. It's hard to translate other locales if I use custom IDs:

msgid "msg.hello"
msgstr ""

I completely miss the default message here.

Describe the solution you'd like I think we could use #| comment, which means previous untranslated string:

#| msgid "Hello world"
msgid "msg.hello"
msgstr ""

Describe alternatives you've considered The only alternative is lookup msgid in source calog catalog, which has default translations or use external editing tool.

Additional context If we figure out how to pass default message to catalogs, then we could remove the default translations and leave them empty (point 1).

In the future I would also like to add fuzzy matching of changed message IDs. Right now if you change message ID, new entry appears in catalog and the old one becomes obsolete. You have to copy any existing translations manually.

It would be great to detect these changes by comparing origin and create "fuzzy" entries:

#| msgid "Hello world"
#, fuzzy
msgid "msg.hello_changed"
msgstr ""

Fuzzy entry must be reviewed by translator (will raise error in lingui compile --check), but otherwise it works as regular message. This concept is borrowed from Django web framework.

Question is: Do we need the previous msgid here? If so, we can't use #| msgid for default message, because it would be used here. For example, if we change msg.hello to msg.hi, the entry would look like this (the default message Hello world is missing):

#| msgid "msg.hello"
#, fuzzy
msgid "msg.hi"
msgstr "Ahoj světe"

@FredyC Since you improved the PO file integration, what's your opinion on this?

danielkcz commented 6 years ago

Um, maybe I am missing something here, but wasn't you actually planning to do a POT approach? To have a template with extracted default messages. As far as I know, any decent PO editor/platform should allow to use such template and display default messages from it while translating a different catalog.

I've basically done a same thing by adding en-dev locale which is a sourceLocale so it contains default messages. Even the old POEdit allows using such file along with translation PO file.

I suppose your solution would not hurt either but feels unnecessary.

tricoder42 commented 6 years ago

Ah, cool! I didn't know that!

I'll check it out. We'll add previously untranslated message when we add fuzzy matching.