Hi everyone!
Historically, Flarum has used Symfony for backend translations, and a semi-port for frontend translations to keep format consistent. There are a few limitations to this approach though:
- Developers need to decide between using
trans
or transChoice
for pluralization
- The pluralization format is proprietary to Symfony
- We have to maintain the JS port ourselves
- Keys for values provided to backend translations need to be wrapped in curly braces. (e.g.
$this->translator->trans('some.translation', ['{username}' => 'Some Username!'])
).
- There's no support for complex applications (nested pluralization, non-number-based selection)
- As a result of the previous point, genderization is impossible. And that's kinda important for a lot of languages.
In v5, Symfony dropped their proprietary transChoice
system in favor of the more-or-less standard ICU MessageFormat. This solves pretty much every single one of the aforementioned issues. In the next release, Flarum will be fully switching to ICU MessageFormat as well. What does this mean for extensions?
transChoice
should not be used at all; instead, the variable passed for pluralization should be included in the data
- Keys for backend translations no longer need to be surrounded by curly braces.
- Translations can now use the
select
and plural
formatter syntaxes. For the plural
formatter, the offset
parameter and #
magic variables are supported
- These
select
and plural
syntaxes can be nested to arbitrary depth. This is often a bad idea though (beyond, say, 2 levels), as things can get unnecessarily complex.
No change to translation file naming is necessary (Symfony docs say that an +intl-icu
suffix is necessary, but Flarum will now interpret all translation files as internationalized).
In the future, this will serve as a basis for additional features:
- Translator preprocessors will allow extensions to modify arguments passed to translations. This will enable genderization (extensions could automatically extract a gender field from any objects of type "user" passed in).
- We could support internationalized "magic variables" for numbers: currently,
one
is supported, but others (few
, many
, etc) currently aren't.
- We could support ordinal formatting in additional to just plural formatting.
Anyways, these changes are currently planned for the next release. The GitHub PR and genderization discussion provide a bit more information.
Please feel free to voice any comments, questions, or concerns!