Esempio n. 1
0
        protected override bool ReplaceOrUpdateAsset(string calculatedModificationPath, ref T asset,
                                                     IAssetOrResourceLoadedContext context)
        {
            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
            var streams = redirectedResources.Select(x => x.OpenStream());
            var cache   = new SimpleTextTranslationCache(
                defaultTranslationFile,
                streams,
                false,
                true);

            if (cache.IsEmpty && !DisableEmptyCacheCheck)
            {
                return(false);
            }

            var result = false;

            foreach (var entry in GetParams(asset))
            {
                if (UpdateParam(calculatedModificationPath, cache, entry))
                {
                    result = true;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public override TextAndEncoding TranslateTextAsset(string calculatedModificationPath, TextAsset asset,
                                                           IAssetOrResourceLoadedContext context)
        {
            if (TextAssetMessagePackHelper.CanHandleAsset(asset, context, out var handler))
            {
                //return new TextAndEncoding(asset.bytes, null);
                var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
                var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
                var streams = redirectedResources.Select(x => x.OpenStream());
                var cache   = new SimpleTextTranslationCache(
                    defaultTranslationFile,
                    streams,
                    false,
                    true);

                if (cache.IsEmpty)
                {
                    Logger.LogDebug($"{GetType()} unable to handle {calculatedModificationPath} (no cache)");
                    return(null);
                }

                var obj = handler.Load(asset);

                if (obj != null && handler.Translate(ref obj, cache, calculatedModificationPath))
                {
                    Logger.LogDebug($"{GetType()} handled {calculatedModificationPath}");
                    return(handler.Store(obj));
                }
            }

            return(null);
        }
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         TitleSkillName.Param param)
        {
            var result = false;
            var key    = param.name0;

            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }
            if (cache.TryGetTranslation(key, true, out var translated))
            {
                param.name0 = translated;
                TrackReplacement(calculatedModificationPath, key, translated);
                TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                result = true;
            }
            else if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                     LanguageHelper.IsTranslatable(key))
            {
                cache.AddTranslationToCache(key, !string.IsNullOrEmpty(param.name1) ? param.name1 : key);
            }

            return(result);
        }
        private bool UpdateClipData(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                    Param param, ClipData clipData)
        {
            var key    = clipData.name;
            var result = false;

            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }
            if (cache.TryGetTranslation(key, true, out var translated))
            {
                clipData.name = translated;
                TrackReplacement(calculatedModificationPath, key, translated);
                TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                result = true;
            }
            else if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                     LanguageHelper.IsTranslatable(key))
            {
                DefaultDumpParam(cache, param, clipData, clipData.name);
            }

            return(result);
        }
        public override bool DumpParam(SimpleTextTranslationCache cache, Param param)
        {
            var clipDataResult     = DumpClipDatas(cache, param);
            var playListDataResult = DumpPlayListDatas(cache, param);

            return(clipDataResult || playListDataResult);
        }
        protected bool DefaultDumpParamMembers(SimpleTextTranslationCache cache, TParam param,
                                               params string[] membersToDump)
        {
            var result = false;

            foreach (var memberName in membersToDump)
            {
                if (!TryGetMemberValue(param, memberName, out var key))
                {
                    WarnMissingMember(memberName);
                    continue;
                }

                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }
                if (DefaultDumpParam(cache, param, key))
                {
                    result = true;
                }
            }

            return(result);
        }
        protected override bool DumpAsset(string calculatedModificationPath, TextAsset asset, IAssetOrResourceLoadedContext context)
        {
            if (!textAssetHelper.IsTable(asset))
            {
                return(false);
            }

            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
            var streams = redirectedResources.Select(x => x.OpenStream());
            var cache   = new SimpleTextTranslationCache(
                outputFile: defaultTranslationFile,
                inputStreams: streams,
                allowTranslationOverride: false,
                closeStreams: true);

            bool DumpCell(string cellText)
            {
                if (!string.IsNullOrEmpty(cellText) && LanguageHelper.IsTranslatable(cellText))
                {
                    cache.AddTranslationToCache(cellText, cellText);
                    return(true);
                }
                return(false);
            }

            return(textAssetHelper.ActOnCells(asset, DumpCell, out TextAssetHelper.TableResult tableResult));
        }
Esempio n. 8
0
        protected override bool ReplaceOrUpdateAsset(string calculatedModificationPath, ref ExcelData asset, IAssetOrResourceLoadedContext context)
        {
            var cache = new SimpleTextTranslationCache(calculatedModificationPath, true, true, false);

            foreach (var param in asset.list)
            {
                for (int i = 0; i < param.list.Count; i++)
                {
                    var key = param.list[i];
                    if (!string.IsNullOrEmpty(key))
                    {
                        if (cache.TryGetTranslation(key, true, out var translated))
                        {
                            param.list[i] = translated;
                        }
                        else if (IsDumpingEnabled && LanguageHelper.IsTranslatable(key))
                        {
                            cache.AddTranslationToCache(key, key);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 9
0
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         VoiceInfo.Param param)
        {
            var result = false;
            var key    = param.Personality;

            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }
            if (cache.TryGetTranslation(key, true, out var translated))
            {
                _personalityById[param.No] = translated;
                _personalityByName[key]    = translated;
                TrackReplacement(calculatedModificationPath, key, translated);
                TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                result = true;
            }
            else if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                     LanguageHelper.IsTranslatable(key))
            {
                cache.AddTranslationToCache(key, string.Empty);
            }

            return(result);
        }
        public override TextAndEncoding TranslateTextAsset(string calculatedModificationPath, TextAsset asset,
                                                           IAssetOrResourceLoadedContext context)
        {
            Logger.DebugLogDebug($"{GetType()} attempt to handle {calculatedModificationPath}");
            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
            var streams = redirectedResources.Select(x => x.OpenStream());
            var cache   = new SimpleTextTranslationCache(
                defaultTranslationFile,
                streams,
                false,
                true);

            if (cache.IsEmpty)
            {
                Logger.DebugLogDebug($"{GetType()} unable to handle {calculatedModificationPath} (no cache)");
                return(null);
            }

            var obj = LoadFromAsset(asset);

            if (obj != null && TranslateObject(ref obj, cache, calculatedModificationPath))
            {
                Logger.DebugLogDebug($"{GetType()} handled {calculatedModificationPath}");
                return(StoreAsset(obj));
            }

            Logger.DebugLogDebug($"{GetType()} unable to handle {calculatedModificationPath}");
            return(null);
        }
Esempio n. 11
0
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         EventInfo.Param param)
        {
            var result  = false;
            var origKey = param.Name;

            foreach (var key in TextResourceHelper.GetTranslationKeys(param, origKey))
            {
                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }

                if (cache.TryGetTranslation(key, true, out var translated))
                {
                    param.Name = translated;
                    TrackReplacement(calculatedModificationPath, origKey, translated);
                    TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                    result = true;
                    break;
                }

                if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                    LanguageHelper.IsTranslatable(origKey))
                {
                    cache.AddTranslationToCache(key, !string.IsNullOrEmpty(param.Name) ? param.Name : string.Empty);
                }
            }

            return(result);
        }
Esempio n. 12
0
        protected override bool DumpAsset(string calculatedModificationPath, ScenarioData asset, IAssetOrResourceLoadedContext context)
        {
            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var cache = new SimpleTextTranslationCache(
                file: defaultTranslationFile,
                loadTranslationsInFile: false);

            foreach (var param in asset.list)
            {
                if (param.Command == Command.Text)
                {
                    for (int i = 0; i < param.Args.Length; i++)
                    {
                        var key = param.Args[i];

                        if (!string.IsNullOrEmpty(key) && LanguageHelper.IsTranslatable(key))
                        {
                            cache.AddTranslationToCache(key, key);
                            //AutoTranslator.Default.TranslateAsync( key, result =>
                            //{
                            //   if( result.Succeeded )
                            //   {
                            //      cache.AddTranslationToCache( key, result.TranslatedText );
                            //   }
                            //} );
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 13
0
        public override bool DumpParam(SimpleTextTranslationCache cache, ClubInfo.Param param)
        {
            var nameResult  = DefaultDumpParam(cache, param, param.Name);
            var placeResult = DefaultDumpParam(cache, param, param.Place);

            return(nameResult || placeResult);
        }
        protected override bool DumpAsset(string calculatedModificationPath, ExcelData asset,
                                          IAssetOrResourceLoadedContext context)
        {
            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var cache = new SimpleTextTranslationCache(
                defaultTranslationFile,
                false);

            var columnsToDump =
                new HashSet <int>(TextResourceHelper.GetSupportedExcelColumns(calculatedModificationPath, asset));

            for (var i = 1; i < asset.list.Count; i++)
            {
                var row        = asset.GetRow(i);
                var rowColumns = Enumerable.Range(0, row.Count);
                if (columnsToDump.Count > 0)
                {
                    rowColumns = rowColumns.Where(columnsToDump.Contains);
                }

                foreach (var key in rowColumns.Select(j => row[j])
                         .Where(k => !k.IsNullOrEmpty() && LanguageHelper.IsTranslatable(k)))
                {
                    cache.AddTranslationToCache(key, key);
                }
            }

            return(true);
        }
Esempio n. 15
0
        public override void DumpScenarioParam(ScenarioData.Param param, SimpleTextTranslationCache cache)
        {
            if (!IsSupportedCommand(param.Command))
            {
                Logger.DebugLogDebug("{0} skipping unsupported command: {1}", GetType().Name, param.Command);
                return;
            }

            if (SelectionCommands.Contains(param.Command))
            {
                foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                {
                    var key = param.Args[i];
                    if (!string.IsNullOrEmpty(key) && !TextKeysBlacklist.Contains(key) &&
                        LanguageHelper.IsTranslatable(key))
                    {
                        cache.AddTranslationToCache(key, key);
                    }
                }

                return;
            }

            base.DumpScenarioParam(param, cache);
        }
Esempio n. 16
0
        public override bool TranslateObject(ref ChaListData obj, SimpleTextTranslationCache cache,
                                             string calculatedModificationPath)
        {
            var idx = obj.lstKey.IndexOf("Name");

            if (idx == -1)
            {
                return(false);
            }
            var result      = false;
            var shouldTrack = IsTranslationRegistrationAllowed(calculatedModificationPath);

            foreach (var entry in obj.dictList.Values)
            {
                if (entry.Count <= idx || !cache.TryGetTranslation(entry[idx], true, out var translation))
                {
                    continue;
                }

                if (shouldTrack)
                {
                    TrackReplacement(calculatedModificationPath, entry[idx], translation);
                }
                TranslationHelper.RegisterRedirectedResourceTextToPath(translation, calculatedModificationPath);
                result     = true;
                entry[idx] = translation;
            }

            return(result);
        }
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         EventInfo.Param param)
        {
            var key = TextResourceHelper.GetSpecializedKey(param, param.Name);

            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }
            var result = false;

            if (cache.TryGetTranslation(key, true, out var translated))
            {
                param.Name = translated;
                TrackReplacement(calculatedModificationPath, key, translated);
                TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                result = true;
            }
            else if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                     LanguageHelper.IsTranslatable(key))
            {
                cache.AddTranslationToCache(key, !string.IsNullOrEmpty(param.Name) ? param.Name : string.Empty);
            }

            return(result);
        }
        private TextAndEncoding Translate(SimpleTextTranslationCache cache, ref TextAsset textAsset)
        {
            string TranslateCell(string cellText)
            {
                if (cache.TryGetTranslation(cellText, false, out string newText))
                {
                    return(newText);
                }
                else
                {
                    if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled)
                    {
                        if (!string.IsNullOrEmpty(cellText) && LanguageHelper.IsTranslatable(cellText))
                        {
                            cache.AddTranslationToCache(cellText, cellText);
                        }
                    }
                }
                return(null);
            }

            string result = textAssetHelper.ProcessTable(textAsset, TranslateCell, out TextAssetHelper.TableResult tableResult);

            //Logger.Log( BepinLogLevel.Debug, $"{this.GetType()}: {tableResult.RowsUpdated}/{tableResult.Rows} rows updated" );
            if (tableResult.RowsUpdated > 0)
            {
                return(new TextAndEncoding(result, Encoding.UTF8));
            }

            return(null);
        }
Esempio n. 19
0
        public override bool DumpParam(SimpleTextTranslationCache cache, PrayInfo.Param param)
        {
            var nameResult   = DefaultDumpParam(cache, param, param.Name);
            var explanResult = DefaultDumpParam(cache, param, param.Explan);

            return(nameResult || explanResult);
        }
Esempio n. 20
0
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache, PrayInfo.Param param)
        {
            var nameResult   = UpdateName(calculatedModificationPath, cache, param);
            var explanResult = UpdateExplan(calculatedModificationPath, cache, param);

            return(nameResult || explanResult);
        }
Esempio n. 21
0
        protected override bool ReplaceOrUpdateAsset(string calculatedModificationPath, ref ScenarioData asset, IAssetOrResourceLoadedContext context)
        {
            var cache = new SimpleTextTranslationCache(calculatedModificationPath, true);

            foreach (var param in asset.list)
            {
                if (param.Command == Command.Text)
                {
                    for (int i = 0; i < param.Args.Length; i++)
                    {
                        var key = param.Args[i];
                        if (!key.IsNullOrWhiteSpace())
                        {
                            if (cache.TryGetTranslation(key, true, out var translated))
                            {
                                param.Args[i] = translated;
                            }
                            else if (IsDumpingEnabled && LanguageHelper.IsTranslatable(key))
                            {
                                cache.AddTranslationToCache(key, key);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 22
0
        private bool TryRegisterTranslation(SimpleTextTranslationCache cache, ScenarioData.Param param, int i,
                                            string calculatedModificationPath)
        {
            var key = TextResourceHelper.GetSpecializedKey(param, i, out var value);

            if (!string.IsNullOrEmpty(key))
            {
                if (cache.TryGetTranslation(key, true, out var translated))
                {
                    var result = TextResourceHelper.GetSpecializedTranslation(param, i, translated);
                    TranslationHelper.RegisterRedirectedResourceTextToPath(result, calculatedModificationPath);
                    param.Args[i] = result;
                    Logger.DebugLogDebug($"{GetType()} handled {calculatedModificationPath}");
                    return(true);
                }

                if (LanguageHelper.IsTranslatable(key))
                {
                    TranslationHelper.RegisterRedirectedResourceTextToPath(key, calculatedModificationPath);
                    if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled)
                    {
                        cache.AddTranslationToCache(key, value);
                    }
                }
            }

            return(false);
        }
Esempio n. 23
0
        protected override bool ReplaceOrUpdateAsset(string calculatedModificationPath, ref ScenarioData asset, IAssetOrResourceLoadedContext context)
        {
            var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
            var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
            var streams = redirectedResources.Select(x => x.OpenStream());
            var cache   = new SimpleTextTranslationCache(
                outputFile: defaultTranslationFile,
                inputStreams: streams,
                allowTranslationOverride: false,
                closeStreams: true);

            foreach (var param in asset.list)
            {
                if (param.Command == Command.Text)
                {
                    for (int i = 0; i < param.Args.Length; i++)
                    {
                        var key = param.Args[i];
                        if (!string.IsNullOrEmpty(key))
                        {
                            if (cache.TryGetTranslation(key, true, out var translated))
                            {
                                param.Args[i] = translated;
                            }
                            else if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled && LanguageHelper.IsTranslatable(key))
                            {
                                cache.AddTranslationToCache(key, key);
                            }
                        }
                    }
                }
            }

            return(true);
        }
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         Param param)
        {
            var clipDataResult     = UpdateClipDatas(calculatedModificationPath, cache, param);
            var playListDataResult = UpdatePlayListDatas(calculatedModificationPath, cache, param);

            return(clipDataResult || playListDataResult);
        }
Esempio n. 25
0
        public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                         ClubInfo.Param param)
        {
            var nameResult  = UpdateName(calculatedModificationPath, cache, param);
            var placeResult = UpdatePlace(calculatedModificationPath, cache, param);

            return(nameResult || placeResult);
        }
Esempio n. 26
0
        protected virtual bool UpdateParamField(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                                ref string[] field, string prefix = null)
        {
            var rawKey = field[0];

            if (string.IsNullOrEmpty(rawKey))
            {
                return(false);
            }

            var keys = new List <string>();

            if (!string.IsNullOrEmpty(prefix))
            {
                keys.Add($"{prefix}{field[0]}");
            }
            keys.Add(field[0]);

            var shouldTrack = IsTranslationRegistrationAllowed(calculatedModificationPath);

            foreach (var key in keys)
            {
                if (cache.TryGetTranslation(key, true, out var translated))
                {
                    field[0] = translated;
                    if (shouldTrack)
                    {
                        TrackReplacement(calculatedModificationPath, rawKey, translated);
                    }
                    TranslationHelper.RegisterRedirectedResourceTextToPath(translated, calculatedModificationPath);
                    return(true);
                }

                if (EnableInternalAssetTranslation.Value && TranslatedIndex > 0 && field.Length > TranslatedIndex)
                {
                    var possible = field[TranslatedIndex];
                    if (Plugin.TextResourceHelper.IsValidStringArrayParamAssetTranslation(key, possible))
                    {
                        field[0] = possible;
                        if (shouldTrack)
                        {
                            TrackReplacement(calculatedModificationPath, rawKey, possible);
                        }
                        TranslationHelper.RegisterRedirectedResourceTextToPath(possible,
                                                                               calculatedModificationPath + " (original asset)");
                        return(true);
                    }
                }

                if (AutoTranslatorSettings.IsDumpingRedirectedResourcesEnabled &&
                    LanguageHelper.IsTranslatable(key))
                {
                    DumpParamField(cache, field);
                }
            }

            return(false);
        }
Esempio n. 27
0
        private IEnumerator ExecuteDump(IEnumerator dumper)
        {
            _currentTranslationCache = GetCurrentTranslatorCache();
            yield return(dumper);

            _currentTranslationCache = null;
            yield return(WriteTranslations());

            DumpCompleted = true;
        }
Esempio n. 28
0
 public override bool UpdateParam(string calculatedModificationPath, SimpleTextTranslationCache cache,
                                  CommunicationInfo.Param param)
 {
     // the multi-quoted string entries need some work, skip them
     if (param.text.Contains("」「"))
     {
         return(false);
     }
     return(DefaultUpdateParam(calculatedModificationPath, cache, param, param.text, ApplyTranslation));
 }
        public override bool DumpParam(SimpleTextTranslationCache cache, AchievementInfoData.Param param)
        {
            var result = new List <bool>
            {
                DumpParamField(cache, param.content),
                DumpParamField(cache, param.title)
            };

            return(result.Any(x => x));
        }
        protected virtual bool DefaultDumpParam(SimpleTextTranslationCache cache, TParam param, string value)
        {
            var key = TextResourceHelper.GetSpecializedKey(param, value);

            if (string.IsNullOrEmpty(key) || !LanguageHelper.IsTranslatable(value))
            {
                return(false);
            }
            cache.AddTranslationToCache(key, string.Empty);
            return(true);
        }