Unit prefixes
In some languages inflections pluralize differently with and without unit prefix. For example, in french language "1.2M" pluralizes differently from "1 200 000".
If unit fixes are used, then argument must first be presented to .Pluralize(format, arguments) in compat decimal format "1.2c6", and then to .Print(format, arguments) with the unit prefixed argument "1,2M".
// Create localization context
ILocalization localization = Localization.CreateDefault();
// Localize to 'fr'
ILocalizedText pommes = localization.LocalizedTextCached[("fr", "Namespace.Apples")];
// 1200000
string print = pommes.Pluralize(CultureInfo.InvariantCulture, new object[] { "1200000" }).Print(null, new object[] { "1200000" });
WriteLine(print); // "Vous avez 1200000 pommes."
// 1,2M
print = pommes.Pluralize(CultureInfo.InvariantCulture, new object[] { "1.2c6" }).Print(null, new object[] { "1,2M" });
WriteLine(print); // "Vous avez 1,2M de pommes."
Example: Resources/fr/Namespace.l.yaml
TemplateFormat: Brace
PluralRules: Unicode.CLDR41
French:
- Culture: fr
Items:
- Key: Namespace.Apples
Cases:
- Text: "Tu n'as pas de pommes."
Plurals: "0:cardinal:zero"
- Text: "Vous avez une pomme."
Plurals: "0:cardinal:one"
- Text: "Vous avez {0} de pommes."
Plurals: "0:cardinal:many"
- Text: "Vous avez {0} pommes."
Plurals: "0:cardinal:other"
Note
Avalanche.Localization does not have utilities for printing and parsing SI units, and therefore the compacted decimal format must be formulated by the caller.
Full Example
Full example
using System.Globalization;
using Avalanche.Localization;
using static System.Console;
class unitprefix
{
public static void Run()
{
{
// <01>
// Create localization context
ILocalization localization = Localization.CreateDefault();
// Localize to 'fr'
ILocalizedText pommes = localization.LocalizedTextCached[("fr", "Namespace.Apples")];
// 1200000
string print = pommes.Pluralize(CultureInfo.InvariantCulture, new object[] { "1200000" }).Print(null, new object[] { "1200000" });
WriteLine(print); // "Vous avez 1200000 pommes."
// 1,2M
print = pommes.Pluralize(CultureInfo.InvariantCulture, new object[] { "1.2c6" }).Print(null, new object[] { "1,2M" });
WriteLine(print); // "Vous avez 1,2M de pommes."
// </01>
}
}
}