private string[] InternalGetAll(string key, LanguageCode code) { string[] parts = key.Split('#'); if (parts.Length == 2) { if (this.Cache.TryGetValue(code, out var data) && data.TryGetValue(parts[0], out var token)) { token = token.SelectToken(parts[1]); if (token != null) { var type = token.Type; if (type == JTokenType.String) { return(new[] { token.ToObject <string>() }); } if (type == JTokenType.Array) { try { return(token.ToObject <string[]>()); } catch { } } return(new[] { "(invalid key: " + key.Replace('#', '/') + ')' }); } } return(null); } return(new[] { "(invalid key: " + key.Replace('#', '/') + ')' }); }
private void LoadLanguage(LanguageCode language) { if (!this.Cache.ContainsKey(language)) { var dir = new DirectoryInfo(Path.Combine(this.RootPath, language.ToString())); if (dir.Exists) { var dict = new Dictionary <string, JToken>(); this.Cache.Add(language, dict); foreach (var file in dir.EnumerateFiles("*.json")) { using (var stream = file.OpenRead()) using (var sreader = new StreamReader(stream)) using (var jreader = new JsonTextReader(sreader)) { try { dict.Add(file.Name, JToken.ReadFrom(jreader)); } catch { } } } } } }
private string InternalGet(string key, LanguageCode code) { string[] parts = key.Split('#'); if (parts.Length == 2) { if (this.Cache.TryGetValue(code, out var data) && data.TryGetValue(parts[0], out var token)) { token = token.SelectToken(parts[1]); if (token != null) { var type = token.Type; if (type == JTokenType.String) { return(token.ToObject <string>()); } if (type == JTokenType.Array) { try { string[] options = token.ToObject <string[]>(); return(options[this.Rand.Next(options.Length - 1)]); } catch { } } return("(invalid key: " + key + ')'); } } return(null); } return("(invalid key: " + key + ')'); }
public void loadTranslationStrings() { //Non-english logic for creating templates. foreach (var translation in HappyBirthday.Config.translationInfo.translationCodes) { StardewValley.LocalizedContentManager.LanguageCode code = translation.Value; string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", translation.Key); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } string stringsFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("TranslatedStrings", translation.Key)); if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, stringsFile))) { HappyBirthday.ModHelper.Data.WriteJsonFile <Dictionary <string, string> >(stringsFile, this.translatedStrings[code]); } else { this.translatedStrings[code] = HappyBirthday.ModHelper.Data.ReadJsonFile <Dictionary <string, string> >(stringsFile); } } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="oldLanguage">The previous language enum value.</param> /// <param name="oldLocale">The previous locale code.</param> /// <param name="newLanguage">The new language enum value.</param> /// <param name="newLocale">The new locale code.</param> internal LocaleChangedEventArgs(LanguageCode oldLanguage, string oldLocale, LanguageCode newLanguage, string newLocale) { this.OldLanguage = oldLanguage; this.OldLocale = oldLocale; this.NewLanguage = newLanguage; this.NewLocale = newLocale; }
public static string GetTranslatedString(string key) { StardewValley.LocalizedContentManager.LanguageCode code = HappyBirthday.Config.translationInfo.translationCodes[HappyBirthday.Config.translationInfo.currentTranslation]; string value = HappyBirthday.Instance.messages.translatedStrings[code][key]; if (string.IsNullOrEmpty(value)) { return(GetEnglishMessageString(key)); } else { return(value); } }
public static string GetEnglishMessageString(string key) { StardewValley.LocalizedContentManager.LanguageCode code = StardewValley.LocalizedContentManager.LanguageCode.en; return(HappyBirthday.Instance.messages.translatedStrings[code][key]); }