osu-framework
osu-framework copied to clipboard
Introduce a pluralisable string type
PRing this in a working state to discuss about integrating this in the localisation pipeline.
This implements a PluralisableString
type deriving from TranslatableString
, that can display a pluralised variant of a translation according to the plural context.
I initially had the 'separator character' delimiting two variants in localised text as a ctor parameter but I guess it should be fine to have it be hardcoded as a '|' for now, which corresponds to what's used on web-side to separate plural variants altough I'm opened to make it a parameter again.
The integration should be transparent on osu!-side with required changes being on osu-localisation-analyzer
end.
Plans to do so sum up to adding heuristics to detect strings which support pluralisation (contains the |
delimiter) and use PluralisableString
in place of TranslatableString
in that case. I'll mention that I haven't delved into it yet but according to my memory from a previous look at the source, that should be pretty straightforward.
The diffstat makes this PR looks big where in fact more than half of it comes from the locale -> plural count mapping.
Implementation references
https://github.com/laravel/framework/blob/f60d3da8f9ad236d339562cd89eb5dfde4eb7dce/src/Illuminate/Translation/MessageSelector.php#L99 for code-based plural rules Spec at : https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_plural_rules.html
Not 100% on the
PluralisableString : TranslatableString
inheritance. Feels it complicates code and maybe it may be easier to duplicate the pieces that need to be duplicated for it to work, dunno.
On a second thought, reverting the inheritance and simply copying over the format logic sounds cleaner, as that would remove the need to override the equal checks which are becoming messy. Will do that instead.
would this allow for omitting variables (including cases with multiple ones)?
o ora ({1}) | {0} ore ({1}) | {0} de ore ({1})
would be required for languages such as romanian
As far as I can tell this PR already supports that, yes. (see getPluralIndex()
).