コード例 #1
0
        public void TestFormatComplexStringUsesFallbackFormatWithTranslatedParts()
        {
            const string nested_key = FakeStorage.LOCALISABLE_NUMBER_FORMAT_STRING_EN;

            manager.AddLanguage("fr", new FakeStorage("fr"));

            var text = manager.GetLocalisedBindableString(LocalisableString.Format("{0} / {1} / {2}",
                                                                                   LocalisableString.Interpolate($"{12.34:0.00}"),
                                                                                   new TranslatableString(nested_key, nested_key, LocalisableString.Interpolate($"{0.9876:0.00%}")),
                                                                                   new TranslatableString(nested_key, nested_key, new RomanisableString("unicode", "romanised"))));

            Assert.AreEqual("12.34 / number 98.76% EN / number unicode EN", text.Value);

            config.SetValue(FrameworkSetting.Locale, "fr");

            Assert.AreEqual("12,34 / number 98,76% FR / number unicode FR", text.Value);

            config.SetValue(FrameworkSetting.ShowUnicode, false);

            Assert.AreEqual("12,34 / number 98,76% FR / number romanised FR", text.Value);

            config.SetValue(FrameworkSetting.Locale, "en");

            Assert.AreEqual("12.34 / number 98.76% EN / number romanised EN", text.Value);
        }
コード例 #2
0
        public void TestLocalisableStringEqualsLocalisableFormattable()
        {
            LocalisableString localisable = LocalisableString.Format(makeStringA, makeStringB);

            testEquals(true, localisable, LocalisableString.Format(makeStringA, makeStringB));
            testEquals(false, localisable, LocalisableString.Format(makeStringB, makeStringA));
        }
コード例 #3
0
        public void TestLocalisableFormattableEqualsLocalisableFormattable()
        {
            var str1 = LocalisableString.Format(makeStringA, makeStringB);
            var str2 = LocalisableString.Format(makeStringB, makeStringA);

            testEquals(true, str1, str1);
            testEquals(true, str1, LocalisableString.Format(makeStringA, makeStringB));
            testEquals(false, str1, str2);
        }
コード例 #4
0
 public void GlobalSetup()
 {
     string1             = "a";
     string2             = "b";
     localisableString1  = "a";
     localisableString2  = "b";
     romanisableString1  = new RomanisableString("a", "b");
     romanisableString2  = new RomanisableString("c", "d");
     translatableString1 = new TranslatableString("e", "f");
     translatableString2 = new TranslatableString("g", "h");
     formattableString1  = LocalisableString.Format("({0})", "j");
     formattableString2  = LocalisableString.Format("[{0}]", "l");
 }
コード例 #5
0
        public void TestFormattedAndLocalisedUsingFormat()
        {
            var formattable   = LocalisableString.Format("{0:0.00%}", 0.1234);
            var translatable1 = new TranslatableString(FakeStorage.LOCALISABLE_STRING_EN, FakeStorage.LOCALISABLE_STRING_EN);
            var translatable2 = new TranslatableString(FakeStorage.LOCALISABLE_FORMAT_STRING_EN, FakeStorage.LOCALISABLE_FORMAT_STRING_EN, formattable);

            manager.AddLanguage("ja", new FakeStorage("ja"));
            config.SetValue(FrameworkSetting.Locale, "ja");

            var formattedText = manager.GetLocalisedBindableString(LocalisableString.Format("{0} -> {1}", translatable1, translatable2));

            Assert.AreEqual("localised JA -> 12.34% localised JA", formattedText.Value);
        }
コード例 #6
0
        public void TestTranslatableEvaluatingLocalisableFormattableString()
        {
            const string key = FakeStorage.LOCALISABLE_NUMBER_FORMAT_STRING_EN;

            manager.AddLanguage("fr", new FakeStorage("fr"));

            var arg  = LocalisableString.Format("{0:0.00%}", 0.1234);
            var text = manager.GetLocalisedBindableString(new TranslatableString(key, key, arg));

            Assert.AreEqual("number 12.34% EN", text.Value);

            config.SetValue(FrameworkSetting.Locale, "fr");

            Assert.AreEqual("number 12,34% FR", text.Value);
        }
コード例 #7
0
 /// <summary>
 /// Returns a <see cref="LocalisableFormattableString"/> formatting the given <paramref name="value"/> to a string, along with an optional <paramref name="format"/> string.
 /// </summary>
 /// <param name="value">The value to format.</param>
 /// <param name="format">The format string.</param>
 public static LocalisableString ToLocalisableString(this IFormattable value, string?format = null) => LocalisableString.Format($"{{0:{format}}}", value);