Ejemplo n.º 1
0
        private LocalizedTextCacheEntry GetTextEntryInternal(string ns, string key, LanguageInfo language, bool considerLanguageFallbacks)
        {
            if (_textCache != null)
            {
                Dictionary <string, Dictionary <string, LocalizedTextCacheEntry> > keys;
                if (_textCache.TryGetValue(ns, out keys))
                {
                    Dictionary <string, LocalizedTextCacheEntry> translations;
                    if (keys.TryGetValue(key, out translations))
                    {
                        LocalizedTextCacheEntry text;

                        if (translations.TryGetValue(language.Key, out text))
                        {
                            EnsureEvaluator(text);
                            return(text);
                        }
                    }
                }
            }


            if (PrepareTextSources(ns))
            {
                return(GetTextEntry(ns, key, language, considerLanguageFallbacks));
            }

            if (considerLanguageFallbacks)
            {
                var fallbacks = new List <LanguageInfo>();
                if (language.Fallbacks != null)
                {
                    fallbacks.AddRange(language.Fallbacks);
                }
                if (FallbackLanguages != null)
                {
                    fallbacks.AddRange(FallbackLanguages.Reverse());
                }

                LocalizedTextCacheEntry text = null;
                if (fallbacks.Any(x =>
                                  (text = GetTextEntry(ns, key, x, false, false)) != null))
                {
                    return(text);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        protected void EnsureEvaluator(LocalizedTextCacheEntry entry)
        {
            EnsureLoaded();
            if (entry.Evaluator == null)
            {
                PatternDialect dialect;
                if (Dialects.TryGetValue(entry.Text.PatternDialect, out dialect))
                {
                    try
                    {
                        entry.PatternDialect = dialect;
                        entry.Evaluator      = dialect.GetEvaluator(entry.Text.Pattern, this);
                    }
                    catch (PatternException pe)
                    {
                        var parameters = new
                        {
                            Message   = pe.Message,
                            Namespace = entry.Text.Namespace,
                            Key       = entry.Text.Key,
                            Language  = entry.Text.Language
                        };

                        var ex = new PatternException("TextManager.PatternException",
                                                      "{0} while parsing {2} in namespace \"{1}\" for {2}", parameters, innerException: pe);


                        throw ex;
                    }
                }
                else
                {
                    throw new UnkownDialectException(entry.Text.PatternDialect);
                }
            }
        }