public void TestInvariantLocalization() { CultureInfo ci = CultureInfo.InvariantCulture; string key = "TestLocalization_Key"; var expectedValue = "TestLocalization_Key"; // Test Localization Key string propNameAsKey = "MyPropertyName"; string propNameAsKeyTranslated = "MyPropertyName"; // My Property Name string literalPropName = "Literal Value"; // not in string reources string value; value = LocalizedStrings.GetString(key, literalPropName, ci); Assert.AreEqual(literalPropName, value, "HappyPath Lookup"); var lookupValue = value; value = LocalizedStrings.GetString(key + "BAD", literalPropName, ci); Assert.AreEqual(literalPropName, value, "Bad Key Lookup"); value = LocalizedStrings.GetString(key.ToLower(), literalPropName, ci); Assert.AreEqual(literalPropName, value, "Case-Insensitive Key Lookup"); value = LocalizedStrings.GetString(null, literalPropName, ci); Assert.AreEqual(literalPropName, value, "Null or empty key Lookup"); value = LocalizedStrings.GetString(key + "BAD", propNameAsKey, ci); Assert.AreEqual(propNameAsKeyTranslated, value, "Missing key, Lookup by propertyName"); value = LocalizedStrings.ReverseLookup(lookupValue, ci); Assert.AreEqual(lookupValue, value, "Reverse lookup by value"); value = LocalizedStrings.ReverseLookup(lookupValue.ToLower(), ci); Assert.AreEqual(lookupValue.ToLower(), value, "Reverse lookup by value (case-insensitive)"); key = "Dict1"; expectedValue = "Dict1"; var dict = new Dictionary <string, string>() { { key, "This is dictionary value 1" }, { "Dict2", "This is dictionary value 2" } }; LocalizedStrings.AddCustomResource(ci, dict); value = LocalizedStrings.GetString(key, ci); Assert.AreEqual(expectedValue, value, "Custom lookup by value"); value = LocalizedStrings.GetString(key.ToLower(), ci); Assert.AreEqual(expectedValue.ToLower(), value, "Custom Case-Insensitive Key Lookup"); lookupValue = value; value = LocalizedStrings.ReverseLookup(lookupValue.ToLower(), ci); Assert.AreEqual(lookupValue.ToLower(), value, "Custom Reverse lookup by value (case-insensitive)"); }
private static void TestLocalization(CultureInfo ci) { string key = "MyDateTime"; string propName = "MyPropertyName"; string value; value = LocalizedStrings.GetString(key, propName, ci); Console.WriteLine($"HappyPath Lookup {key} = {value}"); var lookupValue = value; value = LocalizedStrings.GetString(key + "BAD", propName, ci); Console.WriteLine($"Bad Key Lookup {key + "BAD"} = {value}"); value = LocalizedStrings.GetString(key.ToLower(), propName, ci); Console.WriteLine($"Case-Insensitive Key Lookup {key.ToLower()} = {value}"); value = LocalizedStrings.GetString(null, propName, ci); Console.WriteLine($"Null or empty key Lookup null = {value}"); value = LocalizedStrings.GetString(key + "BAD", key, ci); Console.WriteLine($"Bad key, Lookup by propertyName = {value}"); value = LocalizedStrings.ReverseLookup(lookupValue, ci); Console.WriteLine($"Reverse lookup by value \"{lookupValue}\" = {value}"); value = LocalizedStrings.ReverseLookup(lookupValue.ToLower(), ci); Console.WriteLine($"Reverse lookup by value (case-insensitive) \"{lookupValue.ToLower()}\" = {value}"); key = "Dict1"; var dict = new Dictionary <string, string>() { { key, "This is dictionary value 1" }, { "Dict2", "This is dictionary value 2" } }; LocalizedStrings.AddCustomResource(ci, dict); value = LocalizedStrings.GetString(key, ci); Console.WriteLine($"Custom lookup by value \"{key}\" = {value}"); value = LocalizedStrings.GetString(key.ToLower(), ci); Console.WriteLine($"Custom lookup by value \"{key.ToLower()}\" = {value}"); lookupValue = value; value = LocalizedStrings.ReverseLookup(lookupValue.ToLower(), ci); Console.WriteLine($"Reverse lookup by value (case-insensitive) \"{lookupValue.ToLower()}\" = {value}"); }