/// <summary> /// Allows to get localized text by specified key in editor mode. /// </summary> public static string GetTextValueInEditor(string key, string languageCode) { // load language data TextAsset languageData = Resources.Load(LanguageRuntimeData.LanguageFilePath(languageCode)) as TextAsset; if (languageData == null) { Debug.LogError("Failed to load language: " + languageCode); return(null); } if (string.IsNullOrEmpty(languageData.text)) { Debug.LogError("Failed to load language with ISO-639 code. Data was null or empty"); return(null); } // load culture data SmartCultureInfoCollection availableLanguageCultures = GetAvailableLanguageCultures(); SmartCultureInfo cultureToLoad = availableLanguageCultures.cultureInfos.Find(info => info.languageCode == languageCode); if (cultureToLoad == null) { Debug.LogError("Failed to load language with ISO-639 code: " + languageCode + ". Unable to find a corresponding SmartCultureInfo"); return(null); } // create language handler LanguageDataHandler languageDataHandler = new LanguageDataHandler(); if (!languageDataHandler.Load(languageData.text)) { Debug.LogError("Failed to load data to language handler with ISO-639 code: " + languageCode); return(null); } languageDataHandler.LoadedCulture = cultureToLoad; return(languageDataHandler.GetTextValue(key)); }
bool LoadLanguage(string languageData, string languageCode) { if(string.IsNullOrEmpty(languageData)) { Debug.LogError("Failed to load language with ISO-639 code. Data was null or empty"); return false; } var cultureToLoad = GetCultureInfo(languageCode); if(cultureToLoad == null) { Debug.LogError("Failed to load language with ISO-639 code: " + languageCode + ". Unable to find a corresponding SmartCultureInfo"); return false; } if(languageDataHandler.Load(languageData)) { languageDataHandler.LoadedCulture = cultureToLoad; return true; } return false; }