public CompositeTextTranslationCache(
     IReadOnlyTextTranslationCache first,
     IReadOnlyTextTranslationCache second)
 {
     _first  = first;
     _second = second;
 }
        public ParserResult Parse(string input, int scope, IReadOnlyTextTranslationCache cache)
        {
            var  reader = new StringReader(input);
            bool containsTranslatable = false;
            var  template             = new StringBuilder(input.Length);
            var  args = new List <ArgumentedUntranslatedTextInfo>();
            var  arg  = 'A';

            string line = null;

            while ((line = reader.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    if (cache.IsTranslatable(line, true, scope))
                    {
                        // template it!
                        containsTranslatable = true;

                        var key = "[[" + (arg++) + "]]";
                        template.Append(key).Append('\n');
                        args.Add(new ArgumentedUntranslatedTextInfo
                        {
                            Info = new UntranslatedTextInfo(line)
                        });
                    }
                    else
                    {
                        // add it
                        //containsTranslated = true;
                        template.Append(line).Append('\n');
                    }
                }
                else
                {
                    // add new line
                    template.Append('\n');
                }
            }

            if (!containsTranslatable)
            {
                return(null);
            }

            if (!input.EndsWith("\r\n") && !input.EndsWith("\n"))
            {
                template.Remove(template.Length - 1, 1);
            }

            if (args.Count > 1)
            {
                return(new ParserResult(ParserResultOrigin.GameLogTextParser, input, template.ToString(), false, false, false, true, args));
            }

            return(null);
        }
Esempio n. 3
0
        public ParserResult Parse(string input, int scope, IReadOnlyTextTranslationCache cache)
        {
            if (cache.TryGetTranslationSplitter(input, scope, out var match, out var splitter))
            {
                return(new ParserResult(ParserResultOrigin.RegexTextParser, input, splitter.Translation, true, true, Settings.CacheRegexPatternResults, true, splitter.CompiledRegex, match));
            }

            return(null);
        }
Esempio n. 4
0
 public static void SetTextCacheForAllObjectsInHierachy(GameObject go, IReadOnlyTextTranslationCache cache)
 {
     try
     {
         foreach (var comp in go.GetAllTextComponentsInChildren())
         {
             var info = comp.GetOrCreateTextTranslationInfo();
             info.TextCache = cache;
         }
     }
     catch (Exception e)
     {
         XuaLogger.AutoTranslator.Error(e, "An error occurred while scanning object hierarchy for text components.");
     }
 }
Esempio n. 5
0
        public static void SetTextCacheForAllObjectsInHierachy(this GameObject go, IReadOnlyTextTranslationCache cache)
        {
            try
            {
                foreach (var comp in go.GetAllTextComponentsInChildren())
                {
                    var derivedComp = comp.CreateDerivedProxyIfRequiredAndPossible();
                    var info        = derivedComp.GetOrCreateTextTranslationInfo();
                    info.TextCache = cache;
                }

                var ti = new TransformInfo {
                    TextCache = cache
                };
                foreach (var transform in go.GetComponentsInChildren <Transform>(true))
                {
                    transform.SetExtensionData(ti);
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while scanning object hierarchy for text components.");
            }
        }
Esempio n. 6
0
 public static void SetTextCache(IReadOnlyTextTranslationCache cache)
 {
     _cache = cache;
 }
        public ParserResult Parse(string input, int scope, IReadOnlyTextTranslationCache cache)
        {
            var  reader = new StringReader(input);
            bool containsTranslatable = false;
            //bool containsTranslated = false;
            var template    = new StringBuilder(input.Length);
            var args        = new Dictionary <string, string>();
            var reverseArgs = new Dictionary <string, string>();
            var arg         = 'A';

            string line = null;

            while ((line = reader.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    if (cache.IsTranslatable(line, true, scope))
                    {
                        // template it!
                        containsTranslatable = true;
                        if (reverseArgs.TryGetValue(line, out var existingKey))
                        {
                            template.Append(existingKey).Append('\n');
                        }
                        else
                        {
                            var key = "[[" + (arg++) + "]]";
                            template.Append(key).Append('\n');
                            args.Add(key, line);
                            reverseArgs[line] = key;
                        }
                    }
                    else
                    {
                        // add it
                        //containsTranslated = true;
                        template.Append(line).Append('\n');
                    }
                }
                else
                {
                    // add new line
                    template.Append('\n');
                }
            }

            if (!containsTranslatable)
            {
                return(null);
            }

            if (!input.EndsWith("\r\n") && !input.EndsWith("\n"))
            {
                template.Remove(template.Length - 1, 1);
            }

            if (args.Count > 1)
            {
                return(new ParserResult(ParserResultOrigin.GameLogTextParser, input, template.ToString(), false, false, false, true, args));
            }

            return(null);
        }