Skip to content

Commit

Permalink
Use CultureInfo.GetCultureInfo() whenever it's possible
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed May 2, 2024
1 parent c967b5d commit 39c5e7c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LocalizationPartViewModel : ShapeViewModel
public string Culture { get; set; }

[BindNever]
public CultureInfo CultureInfo { get { return new CultureInfo(Culture); } }
public CultureInfo CultureInfo => CultureInfo.GetCultureInfo(Culture);

[BindNever]
public LocalizationPart LocalizationPart { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public string FindNearestCulture(string culture)
return Cultures[selectedIndex];
}
// Try parent culture if any.
var cultureInfo = new CultureInfo(culture);
var cultureInfo = CultureInfo.GetCultureInfo(culture);
if (cultureInfo.Parent.Name != culture)
{
var selectedCulture = FindNearestCulture(cultureInfo.Parent.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void GetDictionaryReturnsDictionaryWithPluralRuleAndCultureIfNoTranslatio

var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache);

var dictionary = manager.GetDictionary(new CultureInfo("cs"));
var dictionary = manager.GetDictionary(CultureInfo.GetCultureInfo("cs"));

Assert.Equal("cs", dictionary.CultureName);
Assert.Equal(PluralizationRule.Czech, dictionary.PluralRule);
Expand All @@ -45,7 +45,7 @@ public void GetDictionaryReturnsDictionaryWithTranslationsFromProvider()

var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache);

var dictionary = manager.GetDictionary(new CultureInfo("cs"));
var dictionary = manager.GetDictionary(CultureInfo.GetCultureInfo("cs"));
var key = new CultureDictionaryRecordKey { MessageId = "ball" };

dictionary.Translations.TryGetValue(key, out var translations);
Expand All @@ -69,7 +69,7 @@ public void GetDictionarySelectsPluralRuleFromProviderWithHigherPriority()

var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object, highPriorityRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache);

var dictionary = manager.GetDictionary(new CultureInfo("cs"));
var dictionary = manager.GetDictionary(CultureInfo.GetCultureInfo("cs"));

Assert.Equal(dictionary.PluralRule, csPluralRuleOverride);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void LocalizerWithContextShouldCallGetDictionaryOncePerCulture(string cul
SetupDictionary(culture, Array.Empty<CultureDictionaryRecord>());

var localizer = new PortableObjectStringLocalizer("context", _localizationManager.Object, true, _logger.Object);
CultureInfo.CurrentUICulture = new CultureInfo(culture);
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(culture);

// Act
var translation = localizer["Hello"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class LocaleShortcodeTests
[InlineData("fr", "foo [locale en]bar[/locale][locale fr]far[/locale] baz", @"foo far baz")]
public async Task ShouldProcess(string currentCulture, string text, string expected)
{
CultureInfo.CurrentUICulture = new CultureInfo(currentCulture);
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(currentCulture);

var localeProvider = new LocaleShortcodeProvider();
var processor = new ShortcodeService(new IShortcodeProvider[] { localeProvider }, []);
Expand Down

0 comments on commit 39c5e7c

Please sign in to comment.