October: Lang::choice() is not working properly

Created on 30 Dec 2019  路  4Comments  路  Source: octobercms/october

  • OctoberCMS Build: 462
  • PHP Version: 7.4
  • Database Engine: mysql
  • Plugins Installed: Flynsarmy.IdeHelper-v1.0.9

Description:

The choice() function of the October\Rain\Translation\Translator class (accessed through the Lang facade) is not working properly for languages with a language-code containing a dash (like en-uk or es-ar).

It calls the Symfony\Component\Translation\MessageSelector::choose() function to choose the correct plural form for a localization string. This function does in turn call the Symfony\Component\Translation\PluralizationRules::get() function, which chooses the correct plural position for the given locale. When it detects a locale code with more than 3 characters like en-uk, it tries to strip it down to just en, but it just searches for underscores, not dashes.
So the Symfony classes expect locales like en_UK instead. The october backend localization system does therefore not work properly with pluralization, when a locale like en-uk is selected. It just prints the singular version every time.

Steps To Reproduce:

  • Create a plugin with a navigation where the label is set as Lang::choice('author.plugin::lang.navigation.foo', 2).
  • Create a language file for English, where the navigation.foo string is set to 'Bar|Bars'.
  • Set the locale 'English (United Kingdom)' in the user back-end preferences.
Completed Bug

Most helpful comment

All 4 comments

This issue will be closed and archived in 3 days, as there has been no activity in the last 30 days.

  • If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. - If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

This issue will be closed and archived in 3 days, as there has been no activity in the last 30 days.

  • If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. - If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

This issue will be closed and archived in 3 days, as there has been no activity in the last 30 days.
If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue.
If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

Was this page helpful?
0 / 5 - 0 ratings