Search code examples
localizationinternationalizationgettextpo

Combining keys and full text when working with gettext and .po files


I am looking at gettext and .po files for creating a multilingual application. My understanding is that in the .po file msgid is the source and msgstr is the translation. Accordingly I see 2 ways of defining msgid:

Using full text (e.g. "My name is %s.\n") with the following advantages:

  • when calling gettext you can clearly see what is about to be translated
  • it's easier to translate .po files because they contain the actual content to be translated

Using a key (e.g. my-name %s) with the following advantages:

  • when the source text is long (e.g. paragraph about company), gettext calls are more concise which makes your views cleaner
  • easier to maintain several .po files and views, because the key is less likely to change (e.g. key of company-description far less likely to change than the actual company description)

Hence my question:
Is there a way of working with gettext and .po files that allows combining the advantages of both methods, that is:
-usage of a keys for gettext calls
-ability for the translator to see the full text that needs to be translated?


Solution

  • I just answered a similar (much older) question here.

    Short version:

    The PO file format is very simple, so it is possible to generate PO/MO files from another workflow that allows the flexibility you're asking for. (your devs want identifiers, your translators want words)

    You could roll this solution yourself, or use a cloud-based app like Loco to manage your translations and export a Gettext file with identifiers when your devs need them.