Closed bastihilger closed 7 years ago
As per the contribution guidelines, please provide the exact steps you are taking for the issue to occur. This will be used for peer review.
The reported problem occurs when I add the language with the default code used in octobercms to pt-br, the plurization does not work for vojtasvoboda-twigextensions time_diff plugin. Change the language aqui to pt-br the plurization will not work for the date of the post, returning the singular version of the translation.
When I add the language with the code to pt_br, and rename the language directory of the plugin to pt_br, the plurization works correctly for plugin vojtasvoboda-twigextensions time_diff filter plugin. Change the language here to en or to pt_br the plurization will work correctly or the date of the post.
Now we have a problem, because if we change both the language code and its directory to pt_br, we break the compatibility with Octobercms it uses pt-br
This problem occurs (as reported manogi) because OctoberCMS translations make use of this Symfony Pluralization class. But have a look at line 38: it checks if the locale name is longer than 3 characters and then tries to split it at the "_" sign. After that, the locale is basically empty, and the translation falls back to taking the first part of the string in your translation file.
/**
* Returns the plural position to use for the given locale and number.
*
* @param int $number The number
* @param string $locale The locale
*
* @return int The plural position
*/
public static function get($number, $locale)
{
if ('pt_BR' === $locale) { // SEE THAT IT VERIFIES (pt_BR) AND DOES NOT (pt-br)
// temporary set a locale for brazilian
$locale = 'xbr';
}
if (strlen($locale) > 3) {
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
}
if (isset(self::$rules[$locale])) {
$return = call_user_func(self::$rules[$locale], $number);
if (!is_int($return) || $return < 0) {
return 0;
}
return $return;
}
@ribsousa If we were to modify the pluralization rules class so that it followed October's approach of using '-' instead of '_' as the locale separator, would that resolve the problem?
Also, I'm not overly familiar with the pluralization aspect of the language library, what exactly calls the Symphony pluralization class?
@LukeTowers, Well I changed my language in octobercms backend rainlab translate pugin from pt-br to pt_br and I renamed my language folder to "pt_br", and it worked perfectly. So I think the problem really is "_".
When I mentioned Symphony pluralization class, I referred to the Sessions Lab product that octobercms uses to translate content.
Concisely what action needs to come of this?
I believe the problem is that October doesn't properly support pluralized translations because we use -
to separate our language from dialect in the folder naming convention; whereas the Symphony code that would have handled that expects _
. I'd need to test it myself, none of my current translations use pluralization either.
@LukeTowers, from what I've tested here, it's just that -
the problem.
Is it possible to implement our own version of PluralizationRules
?
Closing as it has been over a month since any activity on this occurred.
I hope "Issues" ist the right place for this:
OctoberCMS translations make use of this Symfony Pluralization class. But have a look at line 38: it checks if the locale name is longer than 3 characters and then tries to split it at the "_" sign. After that, the locale is basically empty, and the translation falls back to taking the first part of the string in your translation file.
So basically pluralization of strings in lang folder like "pt-br" does not work.
This probably never caused problems so far, because none of the core language files seem to use pluralization. But now a problem appeared in this Twig Extensions plugin repository here by @vojtasvoboda where pluralization is used and a pt-br language was added.
The dilemma is now: either change the folder name to pt_br and make it work for this plugin and break compatibility with the core language files, or...?
I don't know if Symfony will change the behavior of their pluralization class to make it work for dashes as well as underscores?
Well, I hope someone will have something smart to say about this ;-)
Cheers, Sebastian