Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
	/// <summary>
	/// Returns a text value in the current language for the key. Returns null if nothing is found.
	/// </summary>
    public string GetTextValue(string key)
    {
		return languageDataHandler.GetTextValue(key);
    }