Example #1
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);
                }
            }
        }
        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);
            }
        }
Example #3
0
        /// <summary>
        /// Write a combined CSV to File
        /// </summary>
        /// <param name="path">The destination path</param>
        /// <param name="delimiter">The delimiter to separate values with</param>
        public static void Write(string path, char delimiter, List <string> keys, Dictionary <string, Dictionary <string, string> > languages)
        {
            var csvContent = WriteToString(delimiter, keys, languages);

            FileUtility.WriteToFile(path, csvContent);
        }
Example #4
0
        /// <summary>
        /// Write the csv to file
        /// </summary>
        /// <param name="path">The destination path</param>
        /// <param name="delimiter">The delimiter to separate values with</param>
        /// <param name="input">The Values</param>
        public static void Write(string path, char delimiter, List <List <string> > input)
        {
            var csvContent = WriteToString(delimiter, input);

            FileUtility.WriteToFile(path, csvContent);
        }