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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With