Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to use Gettext and ICU MessageFormat combined?

When I read about Gettext and ICU MessageFormat, both are always described as being opposed approaches to localization.

But I thought, that a combination of both would be an interesting idea: Use MessageFormat for formatting and Gettext to choose the right template based on the language. Along the lines of:

setlocale(LC_ALL, lang)
output = MessageFormat(lang, gettext("There is {number 1} Foo in bar."), [1])

Are there obvious (or not so obvious) drawbacks of this method? Am I missing a central part of MessageFormat on how the translated templates are selected otherwise?

like image 528
Boldewyn Avatar asked Oct 05 '22 18:10

Boldewyn


1 Answers

The obvious problem with your method is how plural forms would be handled. Although ICU has built-in support for CLDR's plural rules, it is not as easy and flexible, as the one that gettext is using.
Basically, in gettext the translators may add as many plural forms as they need and it is governed by the selection rule in .po file header. It is both more flexible and more correct approach than using CLDR rules (which might be incorrect depending on the CLDR version).

like image 57
Paweł Dyda Avatar answered Oct 11 '22 13:10

Paweł Dyda