public void SetLanguage(LanguageType languageType) { LanguageType = languageType; //1.get resource uri string path = string.Format("pack://application:,,,/FiiiCoin.Wallet.Win;component/lang/{0}.xaml", languageType); var resourceLoactor = new Uri(path); //2.find the resource file in Application, if it exists, it must be deleted var resources = Application.Current.Resources; var languageResource = resources.MergedDictionaries.FirstOrDefault(x => x.Source == resourceLoactor); if (languageResource != null) { resources.MergedDictionaries.Remove(languageResource); } //3.Readd the language file to the top ResourceDictionary resource = new ResourceDictionary(); resource.Source = resourceLoactor; Application.Current.Resources.MergedDictionaries.Add(resource); _languageResource = resource; ReLoadLanguageEntry(); LoadErrorCodes(languageType); OnLanguageChanged?.Invoke(languageType); }
public void LoadLocalizedText(string langName) { string path = Application.streamingAssetsPath + "/Languages/" + langName + ".json"; string dataAsJson; if (Application.platform == RuntimePlatform.Android) { WWW reader = new WWW(path); while (!reader.isDone) { } dataAsJson = reader.text; } else { dataAsJson = File.ReadAllText(path); } LocalizationData loadedData = JsonUtility.FromJson <LocalizationData>(dataAsJson); localizedText = new Dictionary <string, string>(); for (int i = 0; i < loadedData.items.Length; i++) { localizedText.Add(loadedData.items[i].key, loadedData.items[i].value); } PlayerPrefs.SetString("Language", langName); currentLanguage = PlayerPrefs.GetString("Language"); isReady = true; OnLanguageChanged?.Invoke(); GameObject.FindGameObjectWithTag("Canvas").GetComponent <Missions>().StartText(); }
public static void SetLanguage(string Language) { Current = Language; if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(Language); } }
public static void SetLanguage(LanguageType type) { languageType = type; if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } }
public void SetLanguage(string name) { _storageProvider.Save(LanguageNameKey, name); var cultureInfo = new CultureInfo(name); LanguageContainerService.SetLanguage(cultureInfo); OnLanguageChanged?.Invoke(); }
public void SetLanguagePref(string language) { PlayerPrefs.SetString(SettingValues.language, language); if (onLanguageChangedCallback != null) { onLanguageChangedCallback.Invoke(); } }
public void ChangeLanguage(LuaTable language) { if (languageTable != null && languageTable != language) { languageTable.Dispose(); languageTable = null; } languageTable = language; cachedTextDic.Clear(); OnLanguageChanged?.Invoke(); }
private IEnumerator ChangeLanguage(string language) { SetLanguage(language); // Load the translations from the language file yield return(LoadTranslations()); UpdateAllTexts(); OnLanguageChanged?.Invoke(); }
public static void SetLanguageId(int lang) { if (lang < LoadedLanguages && lang >= 0) { LanguageId = lang; OnLanguageChanged?.Invoke(); } else { Debug.LogWarning($"Language ID of {lang} is not a valid ID."); } }
private void LanguageChanged(Object sender, EventArgs e) { CultureInfo currentLanguage = App.Language; foreach (MenuItem item in Menu.Items) { CultureInfo cultureInfo = item.Tag as CultureInfo; item.IsChecked = cultureInfo != null && cultureInfo.Equals(currentLanguage); } OnLanguageChanged?.Invoke(); }
/// <summary> /// Change current player language (for editor test only). /// </summary> /// <param name="indexLanguage"></param> public static void ChangeLanguage(int indexLanguage) { if (localizedLanguages.Count == 0) { Debug.LogWarning("<color=yellow>SIMPLE-LOCALIZATOR ERROR</color>: localizator didn't find any language in translations file."); return; } ChangeLanguage(localizedLanguages[indexLanguage].Language); OnLanguageChanged?.Invoke(); }
public static void SetCurrentUserLanguage(string cultureCode) { int newLangIdx = CodeLanguageIdx; if (cultureCode == "de" || cultureCode.StartsWith("de-")) { newLangIdx = Array.IndexOf(Languages, "de"); } else if (cultureCode == "fr" || cultureCode.StartsWith("fr-")) { newLangIdx = Array.IndexOf(Languages, "fr"); } else if (cultureCode == "ja" || cultureCode.StartsWith("ja-")) { newLangIdx = Array.IndexOf(Languages, "ja"); } else if (cultureCode == "ko" || cultureCode.StartsWith("ko-")) { newLangIdx = Array.IndexOf(Languages, "ko"); } else if (cultureCode == "zh" || cultureCode.StartsWith("zh-")) { newLangIdx = Array.IndexOf(Languages, "cn"); } else { newLangIdx = CodeLanguageIdx; } bool changed = false; if (newLangIdx != UserLanguageIdx) { UserLanguageIdx = newLangIdx; changed = true; } var locManager = LocResourceManager.Get(); if (locManager.UserCultureCode != cultureCode) { CultureInfo.CurrentUICulture = new CultureInfo(cultureCode); locManager.SetCurrentUserLanguage(CultureInfo.CurrentUICulture, typeof(loc.strings)); changed = true; } if (changed) { OnLanguageChanged?.Invoke(); Logger.WriteLine("Init localization: culture:{0} -> gameData:{1}, UI:{2}", cultureCode, Languages[UserLanguageIdx], locManager.UserCultureCode); } }
public static void SetUpLanguage() { if (Application.systemLanguage == SystemLanguage.Russian) { currentLanguage = GameEnums.Language.RU; } else { currentLanguage = GameEnums.Language.ENG; } OnLanguageChanged?.Invoke(); }
public void NextLanguage() { Index++; if (Index >= AllLanguages.Length) { Index = 0; } CurrentLanguage = AllLanguages[Index]; if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } }
public void LoadLocalizedText(string langName) { string lang; Debug.Log(CurrentLanguage + "Langguage System"); if (langName == "en_US") { lang = "en_US"; } else { lang = "ru_RU"; } string path = Application.streamingAssetsPath + "/Languages/" + lang + ".json"; string dataAsJson; #if UNITY_ANDROID && !UNITY_EDITOR WWW reader = new WWW(path); UnityWebRequest unityWebRequest = new UnityWebRequest(path); while (!reader.isDone) { } if (langName == "en_US") { dataAsJson = reader.text; } else { dataAsJson = System.Text.Encoding.UTF8.GetString(reader.bytes, 3, reader.bytes.Length - 3); } #else dataAsJson = File.ReadAllText(path); #endif LocalizationData loadedData = JsonUtility.FromJson <LocalizationData>(dataAsJson); localizedText = new Dictionary <string, string>(); for (int i = 0; i < loadedData.items.Length; i++) { localizedText.Add(loadedData.items[i].key, loadedData.items[i].value); } CurrentLanguage = langName; isReady = true; LoadLocalizedSentence(langName); OnLanguageChanged?.Invoke(); }
/// <summary> /// Change current player language (for test only - any mobile test button). /// </summary> public static void ChangeLanguage() { if (localizedLanguages.Count == 0) { Debug.LogWarning("<color=yellow>SIMPLE-LOCALIZATOR ERROR</color>: localizator didn't find any language in translations file."); return; } int indexCurrentLanguage = localizedLanguages.IndexOf(cashLocalizedCurrentLanguage); int indexNextLanguage = (indexCurrentLanguage + 1) % localizedLanguages.Count; ChangeLanguage(localizedLanguages[indexNextLanguage].Language); OnLanguageChanged?.Invoke(); }
/// <summary> /// Load language from resource files /// </summary> /// <param name="path">the language file path</param> void ResourceLoadLanguage(string path) { TextAsset texts = Resources.Load(path) as TextAsset; if (texts == null) { Debug.LogError("UCL_LocalizeManager ResourceLoadLanguage path:" + path + ",not exist!!"); return; } string data = texts.ToString(); m_LocalizeData = new LocalizeData(data); Debug.LogWarning("ResourceLoadLanguage:" + path); OnLanguageChanged.Invoke(); }
public async Task SetLanguageAsync(string tag) { if (tag == CurrentLanguage) { return; } ApplicationLanguages.PrimaryLanguageOverride = tag; ResourceContext.GetForCurrentView().Reset(); ResourceContext.GetForViewIndependentUse().Reset(); // Workaround, otherwise the first language change does not update the resources. await Task.Delay(TimeSpan.FromMilliseconds(200)); OnLanguageChanged?.Invoke(this, tag); }
/// <summary> /// Sets an active language, all localization requests will from now on be querying the provided language /// </summary> /// <param name="languageCode">the language code to set as active</param> /// <param name="setAsDefault">a flag to set the default language, should be used only once</param> public void SetActiveLanguage(string languageCode, bool setAsDefault = false) { languageCode = languageCode.Trim().ToLower(); if (languageDictionary.ContainsKey(languageCode)) { currentLanguage = languageDictionary[languageCode]; OnLanguageChanged?.Invoke(this, EventArgs.Empty); if (setAsDefault) { defaultLanguage = currentLanguage; } } else { throw new InvalidOperationException($"Language with code {languageCode} is not implemented!"); } }
private void OnApplicationPause(bool pause) { if (!pause) { //MainCommon.LauncherApp.GetLanguage(); //Debug.Log(Application.systemLanguage+",Test"); Debug.Log("language:" + SystemCurrentLanguage.CurrentLanguage + "," + m_previousLanguage); if (SystemCurrentLanguage.CurrentLanguage != m_previousLanguage) { setLanguage(mXMLParaser, SystemCurrentLanguage.CurrentLanguage); if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } m_previousLanguage = SystemCurrentLanguage.CurrentLanguage; } } }
public void ChangeCurrentLanguage(string lang) { var selected = Array.IndexOf(m_supportedLang, lang); if (selected == -1) { throw new Exception($"Not supported language : {lang}"); } if (m_currentLang == selected) { return; } m_currentLang = selected; m_languageText.Clear(); RefreshLanguageText(); OnLanguageChanged?.Invoke(); }
private void Update() { #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.UpArrow)) { SystemCurrentLanguage.m_systemLanguage = SystemLanguage.English; setLanguage(mXMLParaser, SystemLanguage.English); if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } } if (Input.GetKeyDown(KeyCode.DownArrow)) { SystemCurrentLanguage.m_systemLanguage = SystemLanguage.Chinese; setLanguage(mXMLParaser, SystemLanguage.Chinese); if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } } if (Input.GetKeyDown(KeyCode.LeftArrow)) { SystemCurrentLanguage.m_systemLanguage = SystemLanguage.Japanese; setLanguage(mXMLParaser, SystemLanguage.Japanese); if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } } if (Input.GetKeyDown(KeyCode.RightArrow)) { SystemCurrentLanguage.m_systemLanguage = SystemLanguage.Korean; setLanguage(mXMLParaser, SystemLanguage.Korean); if (OnLanguageChanged != null) { OnLanguageChanged.Invoke(); } } #endif }
public static void ChangeCurrentLanguage(string newLanguage) { switch (newLanguage) { case "English": currentLanguage = Languages.English; break; case "Russian": currentLanguage = Languages.Russian; break; case "Belarusian": currentLanguage = Languages.Belarusian; break; default: throw new NotImplementedException($"{newLanguage} not implemented yet"); } OnLanguageChanged?.Invoke(); }
/// <summary> /// Raises language change event. /// </summary> private void RaiseLanguageChanged() { OnLanguageChanged?.Invoke(); }
public void SetLocalization(LuaTable languageTable) { localization.ChangeLanguage(languageTable); OnLanguageChanged?.Invoke(); }
internal static void InvokeLanguageChanged(Language lang) { OnLanguageChanged?.Invoke(lang); }
public static void SetLocalizationType(LocalizationType type) { string cfgPath = $"{FinalPatchConst.LOCALIZATION_DIR}/{type.ToString().ToLower()}{FinalPatchConst.LOCALIZATION_EXT}"; bool found = false; try { using (FileStream fs = File.Open(cfgPath, FileMode.Open, FileAccess.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(LocalizationData)); LocalizationData data = serializer.Deserialize(fs) as LocalizationData; if (s_localizationMap == null) { s_localizationMap = new Dictionary <string, string>(); } s_localizationMap.Clear(); foreach (var item in data.items) { s_localizationMap.Add(item.Key, item.Value); } found = true; CurrentType = type; EditorPrefs.SetInt(FinalPatchConst.KEY_FINAL_PATCH_LOCALIZATION, (int)type); OnLanguageChanged?.Invoke(); } } catch { } if (!found) { // create localization file LocalizationData data = new LocalizationData() { items = new List <LocalizationItem>() { new LocalizationItem() { Key = "localization_key", Value = "localization_value", } } }; string dir = Path.GetDirectoryName(cfgPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (FileStream fs = new FileStream(cfgPath, FileMode.Create, FileAccess.Write)) { XmlSerializer serializer = new XmlSerializer(typeof(LocalizationData)); serializer.Serialize(fs, data); } Debug.LogFormat("Create Localization File:{0}", cfgPath); AssetDatabase.Refresh(); SetLocalizationType(type); } }
protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e) { OnLanguageChanged?.Invoke(sender, e); }
public static void ChangeLanguage(UserLanguage newLanguage) { OnLanguageChanged?.Invoke(language, new SettingChangedEventArgs <UserLanguage>(language.Value, newLanguage)); language.Value = newLanguage; }
public static void SetUpLanguage(GameEnums.Language language) { currentLanguage = language; OnLanguageChanged?.Invoke(); }