/// <summary> /// Gets the culture info by language. /// </summary> /// <returns> /// The culture info by language. /// </returns> /// <param name='language'> /// localization Language. /// </param> public static CultureInfo GetCultureInfoByLanguage(LocalizationLanguages language) { switch(language) { case LocalizationLanguages.English: return new CultureInfo("en-US"); case LocalizationLanguages.Russian: return new CultureInfo("ru-RU"); default: return new CultureInfo("en-US"); } }
/// <summary> /// Changes the currently used localization language by the new localization languages name and localizes everything according to the new localization language. /// </summary> /// <param name="localizationLanguage"> /// The name of the localization language to be changed to. /// </param> /// <param name="scheduler"> /// The <see cref="TaskScheduler"/> containing GUI-context. /// </param> /// <exception cref="ArgumentNullException"> /// One or all of the parameters was/ were passed as null. /// </exception> public static void ChangeLocalizationLanguage(string localizationLanguage, TaskScheduler scheduler) { if (localizationLanguage == null || scheduler == null) { throw new ArgumentNullException(); } foreach (var item in LocalizationLanguages.Where(item => item["language"] == localizationLanguage)) { CurrentLocalizationLanguage = item; } Task.Factory.StartNew(() => LocalizeControlsAsync(), CancellationToken.None, TaskCreationOptions.None, scheduler); }
/// <summary> /// Gets the string. /// </summary> /// <returns> /// The string. /// </returns> /// <param name='index'> /// Index of string . /// </param> /// <param name='language'> /// current localization Language. /// </param> public string GetString(int index, LocalizationLanguages language) { string answ; try{ answ = _strings[index][(int)language]; } catch{ GameCoreSingletone.Singletone.LogController.WriteLine("Don't find string by index="+index.ToString()+" for language=" +language.ToString()); answ = ":)"; } Debug.Log("Returned string = " + answ); return answ; }
/// <summary> /// Initializes a new instance of the <see cref="SettingController"/> class. /// </summary> /// <param name='settingFilePath'> /// Setting file path . /// </param> public SettingController(string settingFilePath) { try{ ///read prefs language string locLanguage = PlayerPrefs.GetString(PreferencesKeys.PREFS_LANGUAGE.ToString()); _language = (LocalizationLanguages)Enum.Parse(typeof(LocalizationLanguages),locLanguage); ///read culture info string culInfo = PlayerPrefs.GetString(PreferencesKeys.PREFS_CULTURE.ToString()); if(culInfo == "") _usingCultureInfo = GlobalConstants.GetCultureInfoByLanguage(Language); _usingCultureInfo = new CultureInfo(culInfo); ///read volume of music _musicVolume = (double)PlayerPrefs.GetFloat(PreferencesKeys.PREFS_MUSIC_VOLUME.ToString(),0.5f); ///read volume of sound _soundVolume = (double)PlayerPrefs.GetFloat(PreferencesKeys.PREFS_SOUND_VOLUME.ToString(),0.5f); } catch(Exception ex) { Debug.LogError("error with read preferences "+ex.Message); SetDefaultSettings(); } ///it's a dynamically calculating preferences and they are not saved to file, but may be futher ///some from them will be saved _settingFileName = GlobalConstants.SETTING_FILE_NAME; _idealResolution = new Resolution(); _idealResolution.width = GlobalConstants.IDEAL_X_RESOLUTION; _idealResolution.height = GlobalConstants.IDEAL_Y_RESOLUTION; _currentResolution = new Resolution(); _currentResolution.height = Screen.height; _currentResolution.width = Screen.width; try{ ProportionalHeightCoeficient = (double)CurrentResolution.height/(double)_idealResolution.height; } catch(Exception ex){ Debug.LogError("can not calculate hight Proportional Coeficient "+ex.Message); _proportionalHeightCoeficient=0; } try{ ProportionalWidthCoeficient = (double)CurrentResolution.width/(double)_idealResolution.width; } catch(Exception ex){ Debug.LogError("can not calculate width Proportional Coeficient "+ex.Message); _proportionalWidthCoeficient=0; } }