Parameter emplacement
.Place(parameterName, localizableText, ...) embeds a localizble text into placeholder.
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
// "{0_count} cats and {1_count} dogs"
ILocalizableText catAndDog = (ILocalizableText) and.Place("0", cat, "1", dog);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
foreach(int dogCount in new int[] { 0, 1, 2 })
WriteLine(catAndDog.Print(en, new object[] { catCount, dogCount }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
foreach(int dogCount in new int[] { 0, 1, 2 })
WriteLine(catAndDog.Print(fi, new object[] { catCount, dogCount }));
no cats and no dogs no cats and a dog no cats and 2 dogs a cat and no dogs a cat and a dog a cat and 2 dogs 2 cats and no dogs 2 cats and a dog 2 cats and 2 dogs 0 kissaa ja 0 koiraa 0 kissaa ja koira 0 kissaa ja 2 koiraa kissa ja 0 koiraa kissa ja koira kissa ja 2 koiraa 2 kissaa ja 0 koiraa 2 kissaa ja koira 2 kissaa ja 2 koiraa
docs/emplacement/index.l.yaml:
TemplateFormat: BraceAlphaNumeric
PluralRules: Unicode.CLDR41
Invariant:
- Culture: ""
Items:
- Key: docs.emplacement.index.and
Text: "{0} and {1}"
- Key: docs.emplacement.index.cat
Cases:
- Text: "no cats"
Plurals: "count:cardinal:zero:en"
- Text: "a cat"
Plurals: "count:cardinal:one:en"
- Text: "{count} cats"
Plurals: "count:cardinal:other:en"
- Key: docs.emplacement.index.dog
Cases:
- Text: "no dogs"
Plurals: "count:cardinal:zero:en"
- Text: "a dog"
Plurals: "count:cardinal:one:en"
- Text: "{count} dogs"
Plurals: "count:cardinal:other:en"
- Key: docs.emplacement.index.pony
Text: "a pony"
Finnish:
- Culture: fi
Items:
- Key: docs.emplacement.index.and
Text: "{0} ja {1}"
- Key: docs.emplacement.index.cat
Cases:
- Text: "kissa"
Plurals: "count:cardinal:one"
- Text: "{count} kissaa"
Plurals: "count:cardinal:other"
- Key: docs.emplacement.index.dog
Cases:
- Text: "koira"
Plurals: "count:cardinal:one"
- Text: "{count} koiraa"
Plurals: "count:cardinal:other"
- Key: docs.emplacement.index.pony
Text: "poni"
Parameter signature is modified by the parameters in the emplacements.
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"]; // "a pony"
// "{0_count} cats and a pony"
ILocalizableText catAndPony = (ILocalizableText) and.Place("0", cat, "1", pony);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAndPony.Print(en, new object[] { catCount }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAndPony.Print(fi, new object[] { catCount }));
no cats and a pony a cat and a pony 2 cats and a pony 0 kissaa ja poni kissa ja poni 2 kissaa ja poni
ILocalizableText can be used as argument as is. It localized to the requested language.
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"]; // "a pony"
// "{0_count} cats and {1}"
ILocalizableText catAnd = (ILocalizableText) and.Place("0", cat);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAnd.Print(en, new object[] { catCount, pony }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAnd.Print(fi, new object[] { catCount, pony }));
no cats and a pony a cat and a pony 2 cats and a pony 0 kissaa ja poni kissa ja poni 2 kissaa ja poni
ParameterlessText can be used for emplacing an argument permanently. Localizable text localizes to the requested culture when used as argument.
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
// Create localizable "2 cats", "3 dogs"
ILocalizableText cats2 = (ILocalizableText)cat.Place("count", new ParameterlessText("2"));
ILocalizableText dogs3 = (ILocalizableText)dog.Place("count", new ParameterlessText("3"));
// Print "{0} and {1}"
WriteLine(and.Print(null, new object[] { cats2, dogs3 })); // "2 cats and 3 dogs"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
WriteLine(and.Print(fi, new object[] { cats2, dogs3 })); // "2 kissaa ja 3 koiraa"
Read more about template emplacement.
Full Example
Full example
using System.Globalization;
using Avalanche.Localization;
using Avalanche.Template;
using static System.Console;
class emplacement // emplacement
{
public static void Run()
{
{
// <01>
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
// "{0_count} cats and {1_count} dogs"
ILocalizableText catAndDog = (ILocalizableText) and.Place("0", cat, "1", dog);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
foreach(int dogCount in new int[] { 0, 1, 2 })
WriteLine(catAndDog.Print(en, new object[] { catCount, dogCount }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
foreach(int dogCount in new int[] { 0, 1, 2 })
WriteLine(catAndDog.Print(fi, new object[] { catCount, dogCount }));
// </01>
}
{
// <02>
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"]; // "a pony"
// "{0_count} cats and a pony"
ILocalizableText catAndPony = (ILocalizableText) and.Place("0", cat, "1", pony);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAndPony.Print(en, new object[] { catCount }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAndPony.Print(fi, new object[] { catCount }));
// </02>
}
{
// <03>
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText pony = localization.LocalizableTextCached["docs.emplacement.index.pony"]; // "a pony"
// "{0_count} cats and {1}"
ILocalizableText catAnd = (ILocalizableText) and.Place("0", cat);
// Print "en"
CultureInfo en = CultureInfo.GetCultureInfo("en");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAnd.Print(en, new object[] { catCount, pony }));
WriteLine();
// Print "fi"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
foreach (int catCount in new int[] { 0, 1, 2 })
WriteLine(catAnd.Print(fi, new object[] { catCount, pony }));
// </03>
}
{
// <04>
// Create localization
ILocalization localization = Localization.CreateDefault();
// Get texts
ILocalizableText and = localization.LocalizableTextCached["docs.emplacement.index.and"]; // "{0} and {1}"
ILocalizableText cat = localization.LocalizableTextCached["docs.emplacement.index.cat"]; // "{count} cats"
ILocalizableText dog = localization.LocalizableTextCached["docs.emplacement.index.dog"]; // "{count} dogs"
// Create localizable "2 cats", "3 dogs"
ILocalizableText cats2 = (ILocalizableText)cat.Place("count", new ParameterlessText("2"));
ILocalizableText dogs3 = (ILocalizableText)dog.Place("count", new ParameterlessText("3"));
// Print "{0} and {1}"
WriteLine(and.Print(null, new object[] { cats2, dogs3 })); // "2 cats and 3 dogs"
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
WriteLine(and.Print(fi, new object[] { cats2, dogs3 })); // "2 kissaa ja 3 koiraa"
// </04>
}
}
}