Example #1
0
        /// <summary>
        /// 创建翻译文件
        /// </summary>
        /// <param name="language">目标语言</param>
        public void CreateTranslationFile(string language)
        {
            if (!Application.isEditor)
            {
                throw new NotSupportedException($"Cannot create translation file for {id}: static file compiler can only run in editor mode");
            }
            var target = $"Assets/{CompileConfiguration.Content.TranslationFolder}/{language}";

            if (!Directory.Exists(target))
            {
                Directory.CreateDirectory(target);
            }
            target = CreateLanguageAssetPathFromId(id, language);
            if (File.Exists(target))
            {
                var translation = new ScriptTranslation(File.ReadAllText(target, Encoding.UTF8));
                if (translation.MergeWith(ScriptHeader.LoadSync(id).Header.LoadDefaultTranslation()))
                {
                    translation.SaveToAsset(target);
                }
            }
            else
            {
                ScriptHeader.LoadSync(id).Header.LoadDefaultTranslation().SaveToAsset(target);
            }
        }
Example #2
0
        private static void RemoveUnavailableTranslationItems()
        {
            if (!EditorUtility.DisplayDialog("Remove all unavailable translation items", "This will launch WADV resource system and precompile all script files, which cannot be reversed.\n\nPlease make sure all scripts can be load properly before continue.", "Continue", "Cancel"))
            {
                return;
            }
            PrecompileAll(false);
            var changedFiles = new List <string>();

            foreach (var(key, info) in CompileConfiguration.Content.Scripts)
            {
                var translation = ScriptHeader.LoadSync(key).Header.LoadDefaultTranslation();
                foreach (var(language, _) in info.Translations)
                {
                    var languageFilePath = info.LanguageAssetPath(language);
                    if (!File.Exists(languageFilePath))
                    {
                        continue;
                    }
                    var existedTranslation = new ScriptTranslation(File.ReadAllText(languageFilePath));
                    if (!existedTranslation.RemoveUnavailableTranslations(translation))
                    {
                        continue;
                    }
                    existedTranslation.SaveToAsset(languageFilePath);
                    changedFiles.Add(languageFilePath);
                }
            }
            EditorUtility.DisplayDialog(
                "Remove finished",
                changedFiles.Any()
                    ? $"File changed:\n{string.Join("\n", changedFiles)}"
                    : "All translation items are activated, skip removing",
                "Close");
            AssetDatabase.Refresh();
        }
 /// <inheritdoc />
 public string ConvertToString(string language)
 {
     return(ScriptHeader.LoadSync(ScriptId).Header.GetTranslation(language, TranslationId));
 }
Example #4
0
 public string ConvertToString(string language = TranslationManager.DefaultLanguage)
 {
     return(ScriptHeader.LoadSync(scriptId).Header.GetTranslation(language, translationId));
 }