public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { LanguageDictionary dictionary = ResolveDictionary(); object translation = dictionary.Translate(_uid, _vid, targetType); return(translation); }
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); }