Пример #1
0
        private static LanguageDictionary ResolveDictionary()
        {
            LanguageDictionary dictionary = LanguageDictionary.GetDictionary(
                LanguageContext.Instance.Culture);

            if (dictionary == null)
            {
                throw new InvalidOperationException(string.Format("Dictionary for language {0} was not found",
                                                                  LanguageContext.Instance.Culture));
            }
            return(dictionary);
        }
Пример #2
0
 public static LanguageDictionary GetDictionary(CultureInfo cultureInfo)
 {
     if (cultureInfo == null)
     {
         throw new ArgumentNullException("cultureInfo");
     }
     if (_registeredDictionaries.ContainsKey(cultureInfo))
     {
         LanguageDictionary dictionary = _registeredDictionaries[cultureInfo];
         return(dictionary);
     }
     return(LanguageDictionary.Null);
 }
Пример #3
0
 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         int parametersCount = _isStaticUid ? values.Length - 1 : values.Length - 2;
         if (string.IsNullOrEmpty(_uid))
         {
             if (values[1] == null)
             {
                 throw new ArgumentNullException("Uid must be provided as the first Binding element, and must not be null");
             }
             _isStaticUid = false;
             _uid         = values[1].ToString();
             --parametersCount;
         }
         LanguageDictionary dictionary       = ResolveDictionary();
         object             translatedObject = dictionary.Translate(_uid, _vid, targetType);
         if (translatedObject != null && parametersCount != 0)
         {
             object[] parameters = new object[parametersCount];
             Array.Copy(values, values.Length - parametersCount, parameters, 0, parameters.Length);
             try
             {
                 translatedObject = string.Format(translatedObject.ToString(), parameters);
             }
             catch (Exception ex)
             {
                 #region Trace
                 Debug.WriteLine(string.Format("LanguageConverter failed to format text {0}", translatedObject.ToString()));
                 #endregion
             }
         }
         return(translatedObject);
     }
     catch (Exception ex)
     {
         #region Trace
         Debug.WriteLine(string.Format("LanguageConverter failed to convert text: {0}", ex.Message));
         #endregion
     }
     return(null);
 }