The FOSSBilling Forum Support Support - Bugs & Errors [Localization Issue] Incorrect pluralization by adding 's' to non-English languages

[Localization Issue] Incorrect pluralization by adding 's' to non-English languages

[Localization Issue] Incorrect pluralization by adding 's' to non-English languages

 
  • 0 Vote(s) - 0 Average
 
feldman982
Junior Member

1
5 hours ago #1
Hello Developer Team,

I am reporting a localization issue where the system incorrectly applies English pluralization rules to non-English languages. It appears the logic for pluralization is hardcoded to append an "s" to a word, which causes grammatical errors in languages that have different pluralization rules.


Problem Description:

When the user interface is set to a language other than English, strings that involve a number and a noun are often incorrect. The system adds an "s" to the translated noun, assuming it's the correct way to form a plural.

A specific example in Ukrainian (uk_UA):

In the notification message "Ticket #2 was replied to 16 хвилинs тому.", the word "хвилин" is the correct plural form for "minutes" when used with the number 16 in the Ukrainian language.
  • Current (Incorrect) Output: 16 хвилинs тому
  • The Issue: The system incorrectly adds an "s" to the end of the word "хвилин".

       

             

Expected Behavior:

The system should use the grammatically correct plural form provided by the translation files without appending an extra "s".
  • Correct (Expected) Output: 16 хвилин тому

This issue likely affects numerous other languages where pluralization is not formed by simply adding an "s".


Suggested Solution:

The logic that automatically appends an "s" should be removed. Instead, the application should rely on a standard internationalization (i18n) library that properly handles CLDR (Common Locale Data Repository) plural rules. This would allow the system to use the correct word form based on the quantity and the specific rules of each language.
This change will significantly improve the grammatical accuracy and quality of the localization for all non-English speaking users.
Thank you for your attention to this matter.
---
How can this function twig_timeago_filter($iso8601) be fixed to add English language verification and resolve this issue for other languages on the website?

TwigExtensions.php
public function twig_timeago_filter($iso8601)


    {

        $cur_tm = time();
        $dif = $cur_tm - strtotime($iso8601);
        $pds = [__trans('second'), __trans('minute'), __trans('hour'), __trans('day'), __trans('week'), __trans('month'), __trans('year'), __trans('decade')];
        $lngh = [1, 60, 3600, 86400, 604800, 2_630_880, 31_570_560, 315_705_600];
        $no = 0;

        for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); --$v) {
        }

        if ($v < 0) {
            $v = 0;
        }

        $_tm = $cur_tm - ($dif % $lngh[$v]);

        $no = floor($no);

        if ($no != 1) {
            $pds[$v] .= 's';
        }

        return sprintf('%d %s ', $no, $pds[$v]);
    }

Thanks.

FOSSBilling Running version   0.7.1
Edited 5 hours ago by feldman982.
feldman982
5 hours ago #1

Hello Developer Team,

I am reporting a localization issue where the system incorrectly applies English pluralization rules to non-English languages. It appears the logic for pluralization is hardcoded to append an "s" to a word, which causes grammatical errors in languages that have different pluralization rules.


Problem Description:

When the user interface is set to a language other than English, strings that involve a number and a noun are often incorrect. The system adds an "s" to the translated noun, assuming it's the correct way to form a plural.

A specific example in Ukrainian (uk_UA):

In the notification message "Ticket #2 was replied to 16 хвилинs тому.", the word "хвилин" is the correct plural form for "minutes" when used with the number 16 in the Ukrainian language.

  • Current (Incorrect) Output: 16 хвилинs тому
  • The Issue: The system incorrectly adds an "s" to the end of the word "хвилин".

       

             

Expected Behavior:

The system should use the grammatically correct plural form provided by the translation files without appending an extra "s".
  • Correct (Expected) Output: 16 хвилин тому

This issue likely affects numerous other languages where pluralization is not formed by simply adding an "s".


Suggested Solution:

The logic that automatically appends an "s" should be removed. Instead, the application should rely on a standard internationalization (i18n) library that properly handles CLDR (Common Locale Data Repository) plural rules. This would allow the system to use the correct word form based on the quantity and the specific rules of each language.
This change will significantly improve the grammatical accuracy and quality of the localization for all non-English speaking users.
Thank you for your attention to this matter.
---
How can this function twig_timeago_filter($iso8601) be fixed to add English language verification and resolve this issue for other languages on the website?

TwigExtensions.php
public function twig_timeago_filter($iso8601)


    {

        $cur_tm = time();
        $dif = $cur_tm - strtotime($iso8601);
        $pds = [__trans('second'), __trans('minute'), __trans('hour'), __trans('day'), __trans('week'), __trans('month'), __trans('year'), __trans('decade')];
        $lngh = [1, 60, 3600, 86400, 604800, 2_630_880, 31_570_560, 315_705_600];
        $no = 0;

        for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); --$v) {
        }

        if ($v < 0) {
            $v = 0;
        }

        $_tm = $cur_tm - ($dif % $lngh[$v]);

        $no = floor($no);

        if ($no != 1) {
            $pds[$v] .= 's';
        }

        return sprintf('%d %s ', $no, $pds[$v]);
    }

Thanks.

FOSSBilling Running version   0.7.1

 
  • 0 Vote(s) - 0 Average
Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)