Example #1
0
        static void LoadStringTables(string path, string ext, ref LELangDictCollection langCollection)
        {
            if (langCollection == null)
            {
                langCollection = new LELangDictCollection();
            }
            else
            {
                langCollection.Clear();
            }

            // Check if the localization directory exists, if so then load
            // If not, do nothing
            if (Directory.Exists(path))
            {
                string[] stringTables = Directory.GetFiles(path, "*" + ext);
                foreach (string table in stringTables)
                {
                    string langCode = Path.GetFileName(table).Replace(ext, string.Empty);

                    Dictionary <string, object> tempDict = (Dictionary <string, object>)Json.Deserialize(File.ReadAllText(table));
                    LELangDict langDict = tempDict.ToDictionary(k => k.Key, v => v.Value.ToString());

                    langCollection.Add(langCode, langDict);
                }
            }
        }
Example #2
0
        static void SaveTables(string path, string ext, LELangDictCollection langCollection)
        {
            try
            {
                string loc_directory = path;
                if (!Directory.Exists(loc_directory))
                {
                    Directory.CreateDirectory(loc_directory);
                }

                // Write out one file per lang in JSON format
                foreach (var string_table in langCollection)
                {
                    string lang_data_file_path = Path.Combine(loc_directory, string_table.Key + ext);
                    string rawJson             = Json.Serialize(string_table.Value);

                    File.WriteAllText(lang_data_file_path, rawJson);
                }

                AssetDatabase.Refresh();
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }