public void SpecificCulture_ShouldReturn_LocalizedResource(
            double value,
            RelativeTimeUnitValues unit,
            IntlStyleValues style,
            RelativeTimeNumericValues numericFormat,
            string expected)
        {
            string localized = this.Fixture.Formatter.Format(
                value,
                new CultureInfo("fr"),
                unit,
                style,
                numericFormat);

            Assert.Equal(expected, localized);
        }
        public void CurrentCulture_ShouldReturn_LocalizedResource(
            double value,
            RelativeTimeUnitValues unit,
            IntlStyleValues style,
            RelativeTimeNumericValues numericFormat,
            string expected)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
            string localized = this.Fixture.Formatter.Format(
                value,
                unit,
                style,
                numericFormat);

            Assert.Equal(expected, localized);
        }
Esempio n. 3
0
 /// <summary>
 /// Format the current value to a localized relative time using the specified <see cref="CultureInfo"/>
 /// </summary>
 /// <param name="value">The value to format</param>
 /// <param name="culture">The <see cref="CultureInfo"/> to use</param>
 /// <param name="unit">The <see cref="RelativeTimeUnitValues"/> used for formatting, default: RelativeTimeUnitValues.Second</param>
 /// <param name="style">The <see cref="IntlStyleValues"/> used for formatting, default: IntlStyleValues.Long</param>
 /// <param name="numericFormat">The <see cref="RelativeTimeNumericValues"/> used for formatting, default: RelativeTimeNumericValues.Always</param>
 /// <returns>The relative time localized resource of the specified value</returns>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="CultureNotFoundException"></exception>
 /// <exception cref="NotImplementedException"></exception>
 public string Format(
     double value,
     CultureInfo culture,
     RelativeTimeUnitValues unit             = RelativeTimeUnitValues.Second,
     IntlStyleValues style                   = IntlStyleValues.Long,
     RelativeTimeNumericValues numericFormat = RelativeTimeNumericValues.Always)
 {
     return(unit switch
     {
         RelativeTimeUnitValues.Unknown => throw new ArgumentException("RelativeTimeUnitValues.Unknown is not supported", nameof(unit)),
         _ => style switch
         {
             IntlStyleValues.Unknown => throw new ArgumentException("IntlStyleValues.Unknown is not supported", nameof(style)),
             _ => numericFormat switch
             {
                 RelativeTimeNumericValues.Unknown => throw new ArgumentException("RelativeTimeNumericValues.Unknown is not supported", nameof(unit)),
                 _ => this.FormatInternal(value, culture, unit, style, numericFormat)
             }
         }
     });
Esempio n. 4
0
 /// <summary>
 /// Combines an array of strings into a localized List string using the specified <see cref="CultureInfo"/>
 /// </summary>
 /// <param name="culture">A <see cref="CultureInfo"/></param>
 /// <param name="type">A <see cref="ListTypeValues"/></param>
 /// <param name="style">A <see cref="IntlStyleValues"/></param>
 /// <param name="values">An array of strings</param>
 /// <returns>A localized List string</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public string Format(
     CultureInfo culture,
     ListTypeValues type   = ListTypeValues.Conjunction,
     IntlStyleValues style = IntlStyleValues.Long,
     params string[] values)
 {
     return(values switch
     {
         null => throw new ArgumentNullException(nameof(values), "values is null"),
         string[] v when v.Length == 0 => string.Empty,
         string[] v when v.Length == 1 => v[0],
         _ => type switch
         {
             ListTypeValues.Unknown => throw new ArgumentException("ListTypeValues.Unknown is not supported", nameof(type)),
             _ => style switch
             {
                 IntlStyleValues.Unknown => throw new ArgumentException("IntlStyleValues.Unknown is not supported", nameof(style)),
                 _ => this.FormatInternal(culture, type, style, values)
             }
         }
     });
Esempio n. 5
0
        public void FormatValues_WithCulture_WithTypeAndStyle_ShouldReturn_ExpectedValue(string expected, ListTypeValues listType, IntlStyleValues intStyle, params string[] values)
        {
            string formatted = this.Fixture.Formatter.Format(new CultureInfo("en"), listType, intStyle, values);

            Assert.Equal(expected, formatted);
        }
Esempio n. 6
0
        public void FormatValues_WithoutCulture_WithStyle_ShouldReturn_ExpectedValue(string expected, IntlStyleValues intlStyle, params string[] values)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
            string formatted = this.Fixture.Formatter.Format(intlStyle, values);

            Assert.Equal(expected, formatted);
        }
Esempio n. 7
0
 /// <summary>
 /// Format the current value to a localized relative time using <see cref="CultureInfo.CurrentCulture"/>
 /// </summary>
 /// <param name="value">The value to format</param>
 /// <param name="unit">The <see cref="RelativeTimeUnitValues"/> used for formatting, default: RelativeTimeUnitValues.Second</param>
 /// <param name="style">The <see cref="IntlStyleValues"/> used for formatting, default: IntlStyleValues.Long</param>
 /// <param name="numericFormat">The <see cref="RelativeTimeNumericValues"/> used for formatting, default: RelativeTimeNumericValues.Always</param>
 /// <returns>The relative time localized resource of the specified value</returns>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="CultureNotFoundException"></exception>
 /// <exception cref="NotImplementedException"></exception>
 public string Format(
     double value,
     RelativeTimeUnitValues unit             = RelativeTimeUnitValues.Second,
     IntlStyleValues style                   = IntlStyleValues.Long,
     RelativeTimeNumericValues numericFormat = RelativeTimeNumericValues.Always)
 => this.Format(value, CultureInfo.CurrentCulture, unit, style, numericFormat);
Esempio n. 8
0
 /// <summary>
 /// Combines an array of strings into a localized List string using the <see cref="CultureInfo.CurrentCulture"/>
 /// </summary>
 /// <param name="type">A <see cref="ListTypeValues"/></param>
 /// <param name="style">A <see cref="IntlStyleValues"/></param>
 /// <param name="values">An array of strings</param>
 /// <returns>A localized List string</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public string Format(
     ListTypeValues type   = ListTypeValues.Conjunction,
     IntlStyleValues style = IntlStyleValues.Long,
     params string[] values)
 => this.Format(CultureInfo.CurrentCulture, type, style, values);
Esempio n. 9
0
 /// <summary>
 /// Combines an array of strings into a localized List string using the specified <see cref="CultureInfo"/>
 /// </summary>
 /// <param name="culture">A <see cref="CultureInfo"/></param>
 /// <param name="style">A <see cref="IntlStyleValues"/></param>
 /// <param name="values">An array of strings</param>
 /// <returns>A localized List string</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public string Format(
     CultureInfo culture,
     IntlStyleValues style = IntlStyleValues.Long,
     params string[] values)
 => this.Format(culture, ListTypeValues.Conjunction, style, values);