public void LocalizedString2() { #if NET string s = main.GetLocalizedString(null, "value"); Assert.That(s, Is.EqualTo("value"), "key"); #else string s = main.LocalizedString(null, "comment"); Assert.That(s, Is.Empty, "key"); #endif s = main.GetLocalizedString("key", null); Assert.That(s, Is.EqualTo("key"), "key"); s = main.GetLocalizedString(null, null); Assert.That(s, Is.Empty, "all-null"); }
public void GetLocalizedString() { // null values are fine using (var l = main.GetLocalizedString(null, null, null)) Assert.That(l.Length, Is.EqualTo(0), "null,null,null"); // NoKey does not exists so the same string is returned using (var l = main.GetLocalizedString("NoKey", null, null)) Assert.That(l.ToString(), Is.EqualTo("NoKey"), "string,null,null"); using (var key = new NSString("NoKey")) using (var l = main.GetLocalizedString(key, null, null)) Assert.That(l.ToString(), Is.EqualTo("NoKey"), "NString,null,null"); // TestKey exists (Localizable.strings) and returns TestValue using (var l = main.GetLocalizedString("TestKey", null, null)) Assert.That(l.ToString(), Is.EqualTo("TestValue"), "string,null,null-2"); using (var key = new NSString("TestKey")) using (var l = main.GetLocalizedString(key, null, null)) Assert.That(l.ToString(), Is.EqualTo("TestValue"), "NString,null,null-2"); }
private string GetLocalizedStringOrDefault(string id, NSBundle bundle) { // From Apple doc : // If key is nil and value is nil, returns an empty string. // If key is nil and value is non-nil, returns value. // If key is not found and value is nil or an empty string, returns key. // If key is not found and value is non-nil and not empty, return value. #if NET6_0_OR_GREATER var localizedString = bundle.GetLocalizedString(id, KeyNotFoundValue, null); #else #pragma warning disable CS0618 // Type or member is obsolete var localizedString = bundle.LocalizedString(id, KeyNotFoundValue, null); #pragma warning restore CS0618 // Type or member is obsolete #endif if (localizedString == KeyNotFoundValue) { return(null); } return(localizedString); }
public string LocalizedString(string key, string defaultText = null) { return(__LanguageBundle.GetLocalizedString(key, defaultText)); }