Example #1
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;
                }
            }
        }
Example #2
0
        public static DictionaryDomain GetDictionaryDomain(SiteContext site)
        {
            DictionaryDomain dictionary;

            DictionaryDomain.TryParse(site.DictionaryDomain, Context.Database, out dictionary);
            return(dictionary);
        }
 public DeleteDictionaryWindow(int id)
 {
     InitializeComponent();
     using (var db = new groceryContext())
     {
         Dictionary = db.Dictionary.FirstOrDefault(domain => domain.IdDictionary == id);
     }
     text.Text += Dictionary?.NameDictionary;
 }
 public void RemoveKeyFromCache(string key, Language language, DictionaryDomain domain)
 {
     Translate.RemoveKeyFromCache(key, language, domain);
 }
 public void ReloadDomainCache(DictionaryDomain domain)
 {
     Translate.ReloadDomainCache(domain);
 }
 public Language[] GetCachedLanguages(DictionaryDomain domain)
 {
     return Translate.GetCachedLanguages(domain);
 }
 public void CachePhrase(string key, string phrase, Language language, DictionaryDomain domain)
 {
     Translate.CachePhrase(key, phrase, language, domain);
 }
Example #8
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);
            }
        }
Example #9
0
 public void RemoveKeyFromCache(string key, Language language, DictionaryDomain domain)
 {
     Translate.RemoveKeyFromCache(key, language, domain);
 }
Example #10
0
 public void ReloadDomainCache(DictionaryDomain domain)
 {
     Translate.ReloadDomainCache(domain);
 }
Example #11
0
 public Language[] GetCachedLanguages(DictionaryDomain domain)
 {
     return(Translate.GetCachedLanguages(domain));
 }
Example #12
0
 public void CachePhrase(string key, string phrase, Language language, DictionaryDomain domain)
 {
     Translate.CachePhrase(key, phrase, language, domain);
 }
 private static string DictionaryPath(DictionaryDomain dictionary)
 {
     return(dictionary != null?dictionary.GetDefinitionItem().Paths.Path : Paths.DefaultDictionaryPath);
 }