Exemplo n.º 1
0
        string GetAssetFolderPath(System.Type assetType, string languageCode)
        {
            if (assetType == GameObjectType)
            {
                return(LanguageRuntimeData.PrefabsFolderPath(languageCode));
            }
            else if (assetType == AudioClipType)
            {
                return(LanguageRuntimeData.AudioFilesFolderPath(languageCode));
            }
            else if (assetType == TextureType)
            {
                return(LanguageRuntimeData.TexturesFolderPath(languageCode));
            }
            else if (assetType == TextAssetType)
            {
                return(LanguageRuntimeData.TextAssetsFolderPath(languageCode));
            }
            else if (assetType == FontType)
            {
                return(LanguageRuntimeData.FontsFolderPath(languageCode));
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        // menshikh:
        // Implemented specially for use in inspector editor scripts to avoid necessity of LanguageManager instance.

        public static SmartCultureInfoCollection GetAvailableLanguageCultures()
        {
            TextAsset availableCulturesXML = Resources.Load(LanguageRuntimeData.AvailableCulturesFilePath()) as TextAsset;

            if (availableCulturesXML == null)
            {
                Debug.LogError("Could not load available cultures! No such file!");
                return(null);
            }

            return(SmartCultureInfoCollection.Deserialize(availableCulturesXML));
        }
Exemplo n.º 3
0
	bool LoadAvailableCultures()
	{
		TextAsset availableCulturesXML = Resources.Load(LanguageRuntimeData.AvailableCulturesFilePath()) as TextAsset;

		if(availableCulturesXML == null)
		{
			Debug.LogError("Could not load available languages! No such file!");
			return false;
		}

		availableLanguages = SmartCultureInfoCollection.Deserialize(availableCulturesXML);

		return true;
	}
Exemplo n.º 4
0
    /// <summary>
    /// Change the language into a specified culture
    /// </summary>
    /// <param name="languageCode">The culture to change to</param>
    public void ChangeLanguage(string languageCode)
    {
        TextAsset languageData = Resources.Load(LanguageRuntimeData.LanguageFilePath(languageCode)) as TextAsset;

        if (languageData == null)
        {
            Debug.LogError("Failed to load language: " + languageCode);

            return;
        }

        LoadLanguage(languageData.text, languageCode);

        OnChangeLanguage?.Invoke(this);
    }
Exemplo n.º 5
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));
        }