WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.64k stars 1.02k forks source link

Introduce plurality handling based on message format for ngx-translate schema #2967

Open rhofer opened 5 years ago

rhofer commented 5 years ago

Situation

Having angular applications where ngx-translate is used as translation handler, the basic JSON output is used as translation resource. This itself does not support pluralization. Therefore, plug-ins are available to properly handle this based on ICU MessageFormat.

Request

In order to use ngx-translate with proper pluralization, the schema needs to follow MessageFormat according ICU. Reference:

Example

English source

{
"TIMECOUNT": {
    "YEAR": "{count, plural, one{year} other{years}}"
    }
}

Czech translation

{
"TIMECOUNT": {
    "YEAR": "{count, plural, one{rok} few{roky} other{let}}"
    }
}

Requires

Follow-up to #2855

Artoria2e5 commented 5 years ago

Should Weblate consider the case where messageformat keys are used only for part of the string, for example with {count, plural, one{One year} other{# years}} ago? What about strings controlled by more than one plurals?

MessageFormat people seems to think that it is a good idea, at least with the myriad possible plural or gender input combinations required. This would mean a very different UI: instead of giving one input boxes for each plural form, Weblate will need to come up with something that lets the user deal with this complexity, preferably visually. For now we can, of course, just treat these as any other variable format string and check for them as such...

nijel commented 5 years ago

First step should be syntax validation. That way we ensure that translators get correct feedback in case they mess up something. The similar feature will be needed for Fluent (see https://github.com/WeblateOrg/weblate/issues/1926), but using different syntax.

The UI might come later, once we switch to some rich editor (what is needed for things like https://github.com/WeblateOrg/weblate/issues/1930 or https://github.com/WeblateOrg/weblate/issues/443).

nijel commented 4 years ago

There is even existing Python parser for the syntax: https://github.com/rolepoint/pyseeyou

Artoria2e5 commented 4 years ago

The pyseeyou grammar has lagged quite a bit compared to the js messageformat PEG. Among other things, we are likely to bump into problems with escapes and general function formatters. There is also a new ordinal class to take care of (I think.) I was planning to update it.

nijel commented 4 years ago

Thanks for insight, I just found this library when looking for something else and did not investigate it at all. For the reference the related issue is https://github.com/rolepoint/pyseeyou/issues/11

nijel commented 4 years ago

See also #2856

berserkwarwolf commented 3 years ago

Any news regarding #3286 ?

nijel commented 3 years ago

ICU support is being developed in #2856, that could be baseline for implementing this.