private void ChangeLanguageInternal(Language language)
        {
            if (language == _currentLanguage)
            {
                Debug.Log("New Language " + language + " is same as current Language " + _currentLanguage);
                return;
            }

            if (LanguageHelper.IsNoDataLanguage(language))
            {
                _currentLanguage     = language;
                _currentLanguageData = null;
                languageChanged.Invoke();
                return;
            }

            if (_loadedLanguages.TryGetValue(language, out _currentLanguageData))
            {
                _currentLanguage = language;
                languageChanged.Invoke();
                return;
            }

            if (!TryLoadLanguage(language))
            {
                Debug.Log("Failed to load language file for " + language + " keeping old language loaded.");
                return;
            }

            if (_loadedLanguages.TryGetValue(language, out _currentLanguageData))
            {
                _currentLanguage = language;
                languageChanged.Invoke();
                return;
            }

            Debug.Log("Failed to retrieve language data for " + language);
        }
Beispiel #2
0
 /// <summary>
 /// Loads the laguage of the given language code if availible.
 /// Language codes adhere to the ISO 639-1 standard for language codes.
 /// </summary>
 /// <param name="languageCode">The code of the language in compliance with ISO 639-1</param>
 public void LoadLanguage(string languageCode)
 {
     if (_AvailibleLanguages.Contains(languageCode))
     {
         _CurrentLanguage = XML_to_Class.LoadClassFromXML <LanguageContainer>("\\StreamingAssets\\Languages\\" + languageCode + ".xml");
         LanguageLoaded   = languageCode;
         if (LanguageChangedEvent != null) //could be nothing is registered
         {
             LanguageChangedEvent.Invoke();
         }
     }
     else
     {
         Debug.LogWarning("LanguageController | LoadLanguage | Attempted to load a language that is not available.");
     }
 }
Beispiel #3
0
        /// <summary>
        /// Dynamically load a Localization ResourceDictionary from a file
        /// </summary>
        public void SwitchLanguage(string inFiveCharLang)
        {
            CultureInfo ci;

            if (CultureInfo.CurrentCulture.Name.Equals(inFiveCharLang) && CultureInfo.CurrentUICulture.Name.Equals(inFiveCharLang))
            {
                return;
            }
            if (inFiveCharLang == "Auto" || inFiveCharLang == null)
            {
                ci = CultureInfo.InstalledUICulture;
            }
            else
            {
                ci = new CultureInfo(inFiveCharLang);
            }
            Thread.CurrentThread.CurrentCulture   = ci;
            Thread.CurrentThread.CurrentUICulture = ci;

            SetLanguageResourceDictionary(GetLocXAMLFilePath(inFiveCharLang));
            LanguageChangedEvent?.Invoke(this, new EventArgs());
        }
 protected virtual void OnLanguageChangedEvent(string newCulture)
 {
     LanguageChangedEvent?.Invoke(this, new LocalizationEventArgs(newCulture));
     Config.Instance.LocaleToUse = newCulture;
     Config.Instance.SaveConfig();
 }
Beispiel #5
0
 public void FireLanguageChangedEvent()
 {
     LanguageChangedEvent?.Invoke(this, new EventArgs());
 }