Beispiel #1
0
        /// <summary>
        /// Returns localized representation which corresponds to the local text key or the fallback if none
        /// found in the registry.
        /// </summary>
        /// <param name="key">Local text key (e.g. Enums.Month.June)</param>
        /// <param name="languageID">Language identifier</param>
        /// <returns></returns>
        public string TryGet(string languageID, string key)
        {
            string text = localTextRegistry.TryGet(languageID, key);

            if (!string.IsNullOrEmpty(text) || string.IsNullOrEmpty(key))
            {
                return(text);
            }

            // Get text without key's suffixes
            string[] suffixes = { ".EntitySingular", ".EntityPlural" };
            foreach (var suffix in suffixes)
            {
                if (key.EndsWith(suffix))
                {
                    key = key.Substring(0, key.Length - suffix.Length);

                    text = localTextRegistry.TryGet(languageID, key);
                    if (!string.IsNullOrEmpty(text))
                    {
                        return(text);
                    }

                    break;
                }
            }

            // Fallback to a sub-key (e.g. if Enums.Month.June not found, then try get June instead)
            key = TryGetKeyFallback(key);
            if (!string.IsNullOrEmpty(key))
            {
                text = localTextRegistry.TryGet(languageID, key);
                if (!string.IsNullOrEmpty(text))
                {
                    return(text);
                }

                return(BreakUpString(key));
            }

            return(null);
        }
 /// <summary>
 /// Gets translation for a key based on the context language
 /// </summary>
 /// <param name="key">Local text key</param>
 /// <returns>Translated text or null if no translation found in the context language</returns>
 public string TryGet(string key)
 {
     return(registry.TryGet(CultureInfo.CurrentUICulture.Name, key, false));
 }