public void Process(GetTranslationArgs args)
    {
      if (!Settings.GetBoolSetting("FakeDb.AutoTranslate", false))
      {
        return;
      }

      var language = args.Language.Name;

      var prefix = Settings.GetSetting("FakeDb.AutoTranslatePrefix");
      prefix = prefix.Replace(@"{lang}", language);

      var suffix = Settings.GetSetting("FakeDb.AutoTranslateSuffix");

      if (string.IsNullOrEmpty(prefix) && string.IsNullOrEmpty(suffix))
      {
        suffix = "*";
      }
      else if (suffix.Contains(@"{lang}"))
      {
        suffix = suffix.Replace(@"{lang}", language);
      }

      if (!string.IsNullOrEmpty(suffix) && args.Key.EndsWith(suffix))
      {
        return;
      }

      args.Result = prefix + args.Key + suffix;
    }
Exemple #2
0
        /// <summary>
        /// Runs the processor.
        ///
        /// </summary>
        /// <param name="args">The arguments.
        ///             </param>
        public void Process(GetTranslationArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            List <string> processedDomains = new List <string>();

            if (args.HasResult || Context.Site == null || string.IsNullOrEmpty(Context.Site.DictionaryDomain))
            {
                return;
            }
            this.Args     = args;
            this.Database = args.Options.Database ?? args.ContentDatabase;
            DictionaryDomain domain;

            if (!DictionaryDomain.TryParse(Context.Site.DictionaryDomain, this.Database, out domain) || domain == null)
            {
                return;
            }

            string result;

            if (this.TryGetTranslation(domain, processedDomains, out result) && result != null)
            {
                args.Result = result;
            }
            else if (EnableFallback)
            {
                if (this.TryTranslateTextByFallbackLanguage(args, domain, out result) && result != null)
                {
                    args.Result = result;
                }
            }
        }
Exemple #3
0
        public void Process(GetTranslationArgs args)
        {
            if (!Settings.GetBoolSetting("FakeDb.AutoTranslate", false))
            {
                return;
            }

            var language = args.Language.Name;

            var prefix = Settings.GetSetting("FakeDb.AutoTranslatePrefix");

            prefix = prefix.Replace(@"{lang}", language);

            var suffix = Settings.GetSetting("FakeDb.AutoTranslateSuffix");

            if (string.IsNullOrEmpty(prefix) && string.IsNullOrEmpty(suffix))
            {
                suffix = "*";
            }
            else if (suffix.Contains(@"{lang}"))
            {
                suffix = suffix.Replace(@"{lang}", language);
            }

            if (!string.IsNullOrEmpty(suffix) && args.Key.EndsWith(suffix))
            {
                return;
            }

            args.Result = prefix + args.Key + suffix;
        }
Exemple #4
0
        protected virtual bool TryTranslateTextByFallbackLanguage(GetTranslationArgs args, DictionaryDomain domain, out string result)
        {
            result = null;
            List <string> processedDomains = new List <string>();

            // check if the the language passed in with the args has fallback assigned
            // if so, then get that fallback language
            // must try to get the translation based on that language
            var languageFallsBack = args.Language.HasFallbackAssigned(args.ContentDatabase);

            if (languageFallsBack)
            {
                Language fallbackLanguage = args.Language.GetFallbackLanguage(args.ContentDatabase);

                // the following cannot be called from here, because it is an internal method to the Sitecore.Kernel library
                //Translate.TryTranslateTextByLanguage(args.Key, domain, fallbackLanguage, out result, args.Parameters);

                // therefore, we set Args.Language to the fallbacklanguage
                // this.Args is the Args object in TryGetFromFallbackDomains processor
                // then we call this.TryGetTranslation, which is a method in the TryGetFromFallbackDomains processor,
                // which IS in the Sitecore.Kernel library and therefore can make the call to TryTranslateTextByLanguage

                this.Args.Language = fallbackLanguage;

                if (this.TryGetTranslation(domain, processedDomains, out result) && result != null)
                {
                    return(true);
                }
                else
                {
                    // if no results if found, try to see if this fallback language falls back itself to another language
                    // and then if so, try the translation with that
                    // pass into the recursive call this.Args (instead of args), since the language has been updated in this.Args
                    if (result == null)
                    {
                        var isSuccess = TryTranslateTextByFallbackLanguage(this.Args, domain, out result);
                        return(isSuccess);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }