Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CultureInfo.GetCultureInfo() whenever it's possible #15948

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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