public void Assert_That_Valid_Canadian_Postal_Code_SHOULD_Succeed_With_Canadian_Localization(string postalCode, string culture) { var postalCodeRegexPattern = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "ResxLocalizationTest", Key = "PostalCodeRegexPattern", CultureInfo = CultureInfo.GetCultureInfo(culture) }); var matches = Regex.Match(postalCode, postalCodeRegexPattern); Assert.That(matches.Success); }
private object LocalizeValue(object value, IPropertyMetadata propertyMetadata, CultureInfo cultureInfo) { if (value == null) { return(null); } var strValue = value.ToString(); // check if VM propery can be formatted. If not, pass through if (!string.IsNullOrWhiteSpace(strValue) && propertyMetadata != null && propertyMetadata.LocalizableEnumProperty) { // format value var localizedString = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = propertyMetadata.PropertyEnumLocalizationCategory, Key = strValue, CultureInfo = cultureInfo }); return(string.IsNullOrWhiteSpace(localizedString) && !propertyMetadata.PropertyEnumAllowEmptyValue ? value.ToString() : localizedString ?? string.Empty); } return(value); }
public void HelperFunction(TextWriter output, object context, params object[] arguments) { if (arguments.Length < 2) { throw new HandlebarsException(string.Format("{{{{{0}}}}} helper must have at least two arguments", HelperName)); } var parms = new GetLocalizedParam { CultureInfo = Thread.CurrentThread.CurrentCulture, Category = (arguments[0] ?? string.Empty).ToString(), Key = (arguments[1] ?? string.Empty).ToString(), }; string format = _localizationProvider.GetLocalizedString(parms); string resourceValue; if (format != null) // Do not use !IsNullOrWhiteSpace, user might want to display empty string. { var options = new object[arguments.Length - 2]; Array.Copy(arguments, 2, options, 0, options.Length); resourceValue = string.Format(format, options); } else { resourceValue = GetMissingValueHint(parms); } output.WriteSafeString(resourceValue); }
public void HelperFunction(TextWriter output, HelperOptions options, object context, params object[] arguments) { if (arguments.Length != 2) { throw new HandlebarsException(string.Format("{{{{{0}}}}} helper must have exactly two arguments", HelperName)); } string category = (arguments[0] ?? string.Empty).ToString(); string key = (arguments[1] ?? string.Empty).ToString(); string resourceValue = _localizationProvider.GetLocalizedString(new GetLocalizedParam { CultureInfo = Thread.CurrentThread.CurrentCulture, Category = category, Key = key }); if (!string.IsNullOrEmpty(resourceValue)) { options.Template(output, context); } else { options.Inverse(output, context); } }
public static string FormatPhoneNumber(this ILocalizationProvider localizationProvider, string phoneNumber, CultureInfo cultureInfo) { if (localizationProvider == null) { throw new ArgumentNullException(nameof(localizationProvider)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } var format = localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "Store", Key = "PhoneNumberFormat", CultureInfo = cultureInfo }); double phoneNumberDouble; return(!string.IsNullOrWhiteSpace(phoneNumber) && double.TryParse(phoneNumber, out phoneNumberDouble) ? string.Format(cultureInfo, format, phoneNumberDouble) : phoneNumber); }
public string Format(object value, IPropertyMetadata propertyMetadata, CultureInfo cultureInfo) { if (propertyMetadata == null) { throw new ArgumentNullException("propertyMetadata"); } if (cultureInfo == null) { throw new ArgumentNullException("cultureInfo"); } if (value == null) { return(null); } var localFormattingString = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = propertyMetadata.PropertyFormattingCategory, Key = propertyMetadata.PropertyFormattingKey, CultureInfo = cultureInfo }); return(localFormattingString == null ? value.ToString() : string.Format(cultureInfo, localFormattingString, value)); }
/// <summary> /// Get Configuration for the Queried Search /// </summary> /// <returns></returns> private SelectedSortBy GetSelectedSortBy(SearchCriteria criteria) { var selectedSortByConfig = _searchSortBy .FirstOrDefault(c => c.Field == criteria.SortBy && c.Direction == criteria.SortDirection); selectedSortByConfig = selectedSortByConfig ?? _searchSortBy.First(); var selectedSortBy = new SelectedSortBy { DisplayName = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = selectedSortByConfig.LocalizationCategory, Key = selectedSortByConfig.LocalizationKey, CultureInfo = criteria.CultureInfo }), Value = selectedSortByConfig.Field }; return(selectedSortBy); }
public void WHEN_Handlebar_View_Retrive_Not_Defined_Culture_Key_SHOULD_Return_Local_Resource_Neutral_Value() { var value = _localizationProvider.GetLocalizedString( new GetLocalizedParam { Category = "ResxLocalizationTest", Key = "PageTitle", CultureInfo = CultureInfo.CreateSpecificCulture("en-US") } ); Assert.AreEqual(value, "Neutral Page Title"); }
private string FormatValueByType(object value, string propertyName, string baseTypeFormatting, CultureInfo cultureInfo) { var formatting = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = PropertyFormattingResource, Key = propertyName, CultureInfo = cultureInfo }); if (formatting == null) { formatting = _localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = PropertyFormattingResource, Key = baseTypeFormatting, CultureInfo = cultureInfo }); } if (formatting == null) { formatting = "{0}"; } return(string.Format(formatting, value)); }
/// <summary> /// Formats the price of a product. /// </summary> /// <param name="localizationProvider">The localization provider.</param> /// <param name="price">The price.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns></returns> public static string FormatPrice(this ILocalizationProvider localizationProvider, decimal price, CultureInfo cultureInfo) { if (localizationProvider == null) { throw new ArgumentNullException(nameof(localizationProvider)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } var format = localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "General", Key = "PriceFormat", CultureInfo = cultureInfo }); return(string.Format(cultureInfo, format, price)); }
/// <summary> /// Gets a localized error message based on the code of that error which will be used has a key. /// </summary> /// <param name="localizationProvider">The localization provider.</param> /// <param name="errorCode">The code of the error message.</param> /// <param name="cultureInfo">The culture information.</param> /// <returns></returns> public static string GetLocalizedErrorMessage(this ILocalizationProvider localizationProvider, string errorCode, CultureInfo cultureInfo) { if (localizationProvider == null) { throw new ArgumentNullException(nameof(localizationProvider)); } if (errorCode == null) { throw new ArgumentNullException(nameof(errorCode)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } return(localizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "Errors", Key = "L_" + errorCode, CultureInfo = cultureInfo })); }
public void WHEN_retreive_french_canadian_SHOULD_return_localized_string() { string paymentMethodString = _localizationProvider.GetLocalizedString( new GetLocalizedParam { Category = "ResxLocalizationTest", Key = "PageTitle", CultureInfo = CultureInfo.GetCultureInfo("fr-CA") } ); paymentMethodString.Should().NotBeNull(); paymentMethodString.Should().Be("Québec Page Title"); }