コード例 #1
0
ファイル: LanguageHandlerEditor.cs プロジェクト: moalexey/ade
	public static void UpdateLanguageFile(string languageCode, List<List<string>> values)
	{
		Dictionary<string,string> languageItems = null;
		if(FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(languageCode)))
		{
			languageItems = LanguageHandlerEditor.LoadLanguageFile(languageCode, false);
		}
		else
		{
			languageItems = new Dictionary<string, string>();
		}
		
		int updatedKeys = 0;
		foreach (List<string> row in values)
		{
			if (row.Count != 2)
			{
				continue;
			}
			string key = row[0].TrimStart('\r', '\n').TrimEnd('\r', '\n').Trim();
			string value = row[1];

			if (!languageItems.ContainsKey(key))
			{
				continue;
			}

			languageItems[key] = value;
			updatedKeys++;
		}

		LanguageHandlerEditor.SaveLanguageFile(languageItems, LocalizationWorkspace.LanguageFilePath(languageCode));
		Debug.Log("Updated language:" + languageCode + ", Keys updated:" + updatedKeys);
	}
コード例 #2
0
ファイル: LanguageHandlerEditor.cs プロジェクト: moalexey/ade
	/// <summary> Deletes the language. </summary>
	public static void DeleteLanguage(SmartCultureInfo cultureInfo)
	{
		string filePath = LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode);
		if(FileUtility.Exists(filePath))
		{
			FileUtility.Delete(filePath);
			FileUtility.Delete(filePath + LocalizationWorkspace.metaFileEnding);
		}
		//The text file
		filePath = LocalizationWorkspace.ResourcesFolderFilePath() + "/" + LocalizationWorkspace.rootLanguageName + "." + cultureInfo.languageCode + LocalizationWorkspace.txtFileEnding;
		if(FileUtility.Exists(filePath))
		{
			FileUtility.Delete(filePath);
			FileUtility.Delete(filePath + LocalizationWorkspace.metaFileEnding);
		}
		
		//The assets directory
		filePath = LocalizationWorkspace.LanguageRuntimeFolderPath(cultureInfo.languageCode);
		if(Directory.Exists(filePath))
		{
			Directory.Delete(filePath + "/", true);
			FileUtility.Delete(filePath + LocalizationWorkspace.metaFileEnding);
		}

		SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());
		LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures);
		AssetDatabase.Refresh();
	}
コード例 #3
0
        /// <summary>
        /// Read a csv file
        /// </summary>
        /// <param name="path">The path to the file</param>
        /// <param name="delimiter">The delimiter used in the file</param>
        /// <returns>The parsed csv values</returns>
        public static List <List <string> > Read(string path, char delimiter)
        {
            string csvContent = null;

            if (FileUtility.Exists(path))
            {
                FileUtility.ReadFromFile(path, out csvContent);
                return(ReadFromString(csvContent, delimiter));
            }

            throw new System.IO.FileNotFoundException("CSV file does not exist!", path);
        }
コード例 #4
0
ファイル: LanguageHandlerEditor.cs プロジェクト: moalexey/ade
	/// <summary>
	/// Gets a SmartCultureInfoCollection with all the cultures not available in this workspace
	/// </summary>
	/// <param name="allCultures">The list of all the available cultures</param>
	/// <returns>A SmartCultureInfoCollection with all the cultures not available in this workspace</returns>
	public static SmartCultureInfoCollection GetNonAvailableLanguages(SmartCultureInfoCollection allCultures)
	{
		SmartCultureInfoCollection nonCreatedLanguages = new SmartCultureInfoCollection();
		
		foreach(SmartCultureInfo cultureInfo in allCultures.cultureInfos)
		{
			if(!FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode)))
			{
				nonCreatedLanguages.AddCultureInfo(cultureInfo);
			}
		}
		
		return nonCreatedLanguages;
	}
コード例 #5
0
ファイル: LanguageHandlerEditor.cs プロジェクト: moalexey/ade
	/// <summary>
	/// Checks all the created languages and Saves the AvailableCultures xml.
	/// </summary>
	/// <param name="allCultures">A list of all the available cultures</param>
	/// <returns>A list of all the created languages</returns>
	public static SmartCultureInfoCollection CheckAndSaveAvailableLanguages(SmartCultureInfoCollection allCultures)
	{
		SmartCultureInfoCollection createdCultures = new SmartCultureInfoCollection();
		
		foreach(SmartCultureInfo cultureInfo in allCultures.cultureInfos)
		{
			if(FileUtility.Exists(LocalizationWorkspace.LanguageFilePath(cultureInfo.languageCode)))
			{
				createdCultures.AddCultureInfo(cultureInfo);
			}
		}

		createdCultures.Serialize(LocalizationWorkspace.AvailableCulturesFilePath());
		
		return createdCultures;
	}
コード例 #6
0
        /// <summary>Renames the localized file from resources.</summary>
        public static void RenameFileFromResources(string key, string newKey, SmartCultureInfo cultureInfo)
        {
            string languageFolderPath   = null;
            LocalizedObjectType keyType = LocalizedObject.GetLocalizedObjectType(key);
            string cleanKey             = LocalizedObject.GetCleanKey(key);
            string cleanNewKey          = LocalizedObject.GetCleanKey(newKey);

            switch (keyType)
            {
            case LocalizedObjectType.GAME_OBJECT:
                languageFolderPath = LocalizationWorkspace.LanguagePrefabsFolderPathRelative(cultureInfo.languageCode) + "/" + cleanKey + LocalizationWorkspace.prefabFileEnding;
                break;

            case LocalizedObjectType.AUDIO:
                languageFolderPath = LocalizationWorkspace.LanguageAudioFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.TEXTURE:
                languageFolderPath = LocalizationWorkspace.LanguageTexturesFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.TEXT_ASSET:
                languageFolderPath = LocalizationWorkspace.LanguageTextAssetsFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.FONT:
                languageFolderPath = LocalizationWorkspace.LanguageFontsFolderPathRelative(cultureInfo.languageCode);
                break;
            }

            if (keyType != LocalizedObjectType.GAME_OBJECT)
            {
                string fileExtension = FileUtility.GetFileExtension(cleanKey, languageFolderPath);
                languageFolderPath += "/" + cleanKey + fileExtension;
            }

            if (FileUtility.Exists(Application.dataPath + languageFolderPath))
            {
                AssetDatabase.RenameAsset("Assets" + languageFolderPath, cleanNewKey);
            }

            AssetDatabase.Refresh();
        }
コード例 #7
0
        /// <summary>
        /// Checks .resx files and converts them into text assets that can be used at runtime
        /// </summary>
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            //Only use this if there's a localization system created
            if (!LocalizationWorkspace.Exists())
            {
                return;
            }

            foreach (string asset in importedAssets)
            {
                if (asset.EndsWith(LocalizationWorkspace.resXFileEnding))
                {
                    string newFileName = LocalizationWorkspace.ResourcesFolderFilePath() + "/" + Path.GetFileNameWithoutExtension(asset) + LocalizationWorkspace.txtFileEnding;

                    if (!DirectoryUtility.CheckAndCreate(LocalizationWorkspace.ResourcesFolderFilePath()))
                    {
                        return;
                    }

                    //Delete the file if it already exists
                    if (FileUtility.Exists(newFileName))
                    {
                        FileUtility.Delete(newFileName);
                    }

                    string fileData = "";
                    using (StreamReader reader = new StreamReader(asset))
                    {
                        fileData = reader.ReadToEnd();
                    }


                    FileUtility.WriteToFile(newFileName, fileData);

                    SmartCultureInfoCollection allCultures = SmartCultureInfoEx.Deserialize(LocalizationWorkspace.CultureInfoCollectionFilePath());
                    LanguageHandlerEditor.CheckAndSaveAvailableLanguages(allCultures);

                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                }
            }
        }
コード例 #8
0
        /// <summary> Deletes the localized file from resources.</summary>
        public static void DeleteFileFromResources(string key, SmartCultureInfo cultureInfo)
        {
            string languageFolderPath   = string.Empty;
            string cleanKey             = LocalizedObject.GetCleanKey(key);
            LocalizedObjectType keyType = LocalizedObject.GetLocalizedObjectType(key);

            switch (keyType)
            {
            case LocalizedObjectType.GameObject:
                languageFolderPath = LocalizationWorkspace.LanguagePrefabsFolderPathRelative(cultureInfo.languageCode) + "/" + cleanKey + LocalizationWorkspace.prefabFileEnding;
                break;

            case LocalizedObjectType.Audio:
                languageFolderPath = LocalizationWorkspace.LanguageAudioFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.Texture:
                languageFolderPath = LocalizationWorkspace.LanguageTexturesFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.TextAsset:
                languageFolderPath = LocalizationWorkspace.LanguageTextAssetsFolderPathRelative(cultureInfo.languageCode);
                break;

            case LocalizedObjectType.Font:
                languageFolderPath = LocalizationWorkspace.LanguageFontsFolderPathRelative(cultureInfo.languageCode);
                break;
            }

            if (keyType != LocalizedObjectType.GameObject)
            {
                string fileExtension = FileUtility.GetFileExtension(cleanKey, languageFolderPath);
                languageFolderPath += "/" + cleanKey + fileExtension;
            }

            if (FileUtility.Exists(Application.dataPath + languageFolderPath))
            {
                AssetDatabase.DeleteAsset("Assets" + languageFolderPath);
            }
            AssetDatabase.Refresh();
        }
コード例 #9
0
        static bool AppendOrCreateStringsFile(string fullPath)
        {
            if (!FileUtility.Exists(fullPath))
            {
                return(FileUtility.WriteToFile(fullPath, GetBasicStringXMLData()));
            }

            if (DoesFileHavePresence(fullPath))
            {
                return(true);
            }

            XDocument doc = XDocument.Load(fullPath);

            if (doc == null)
            {
                return(false);
            }

            try
            {
                XElement resourceElement = doc.Root;
                XElement presence        = new XElement("string");
                presence.Value = SmartLocalizationDeclaration;
                XAttribute nameAttrib = new XAttribute("name", SmartLocalizationDeclaration);
                presence.Add(nameAttrib);
                resourceElement.Add(presence);
                doc.Save(fullPath);
                return(true);
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.Message);
                return(false);
            }
        }