Remove GetLocalizedString overload used for testing

This commit is contained in:
Mark McDowall 2023-10-01 10:18:33 -07:00
parent 076aaba908
commit 08abf648b0
2 changed files with 21 additions and 34 deletions

View File

@ -32,7 +32,9 @@ namespace NzbDrone.Core.Test.Localization
[Test] [Test]
public void should_get_string_in_default_language_dictionary_if_no_lang_country_code_exists_and_string_exists() public void should_get_string_in_default_language_dictionary_if_no_lang_country_code_exists_and_string_exists()
{ {
var localizedString = Subject.GetLocalizedString("UiLanguage", "fr_fr"); Mocker.GetMock<IConfigService>().Setup(m => m.UILanguage).Returns((int)Language.French);
var localizedString = Subject.GetLocalizedString("UiLanguage");
localizedString.Should().Be("UI Langue"); localizedString.Should().Be("UI Langue");
@ -40,19 +42,10 @@ namespace NzbDrone.Core.Test.Localization
} }
[Test] [Test]
public void should_get_string_in_default_dictionary_if_no_lang_exists_and_string_exists() public void should_get_string_in_default_dictionary_if_unknown_language_and_string_exists()
{ {
var localizedString = Subject.GetLocalizedString("UiLanguage", "an"); Mocker.GetMock<IConfigService>().Setup(m => m.UILanguage).Returns(0);
var localizedString = Subject.GetLocalizedString("UiLanguage");
localizedString.Should().Be("UI Language");
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void should_get_string_in_default_dictionary_if_lang_empty_and_string_exists()
{
var localizedString = Subject.GetLocalizedString("UiLanguage", "");
localizedString.Should().Be("UI Language"); localizedString.Should().Be("UI Language");
} }
@ -60,7 +53,7 @@ namespace NzbDrone.Core.Test.Localization
[Test] [Test]
public void should_return_argument_if_string_doesnt_exists() public void should_return_argument_if_string_doesnt_exists()
{ {
var localizedString = Subject.GetLocalizedString("badString", "en"); var localizedString = Subject.GetLocalizedString("badString");
localizedString.Should().Be("badString"); localizedString.Should().Be("badString");
} }

View File

@ -19,7 +19,6 @@ namespace NzbDrone.Core.Localization
{ {
Dictionary<string, string> GetLocalizationDictionary(); Dictionary<string, string> GetLocalizationDictionary();
string GetLocalizedString(string phrase); string GetLocalizedString(string phrase);
string GetLocalizedString(string phrase, string language);
string GetLanguageIdentifier(); string GetLanguageIdentifier();
} }
@ -58,18 +57,26 @@ namespace NzbDrone.Core.Localization
return GetLocalizedString(phrase, language); return GetLocalizedString(phrase, language);
} }
public string GetLocalizedString(string phrase, string language) public string GetLanguageIdentifier()
{
var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage) ?? IsoLanguages.Get(Language.English);
var language = isoLanguage.TwoLetterCode;
if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace())
{
language = $"{language}-{isoLanguage.CountryCode.ToUpperInvariant()}";
}
return language;
}
private string GetLocalizedString(string phrase, string language)
{ {
if (string.IsNullOrEmpty(phrase)) if (string.IsNullOrEmpty(phrase))
{ {
throw new ArgumentNullException(nameof(phrase)); throw new ArgumentNullException(nameof(phrase));
} }
if (language.IsNullOrWhiteSpace())
{
language = GetLanguageFileName();
}
if (language == null) if (language == null)
{ {
language = DefaultCulture; language = DefaultCulture;
@ -85,19 +92,6 @@ namespace NzbDrone.Core.Localization
return phrase; return phrase;
} }
public string GetLanguageIdentifier()
{
var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage) ?? IsoLanguages.Get(Language.English);
var language = isoLanguage.TwoLetterCode;
if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace())
{
language = $"{language}-{isoLanguage.CountryCode.ToUpperInvariant()}";
}
return language;
}
private string GetLanguageFileName() private string GetLanguageFileName()
{ {
return GetLanguageIdentifier().Replace("-", "_").ToLowerInvariant(); return GetLanguageIdentifier().Replace("-", "_").ToLowerInvariant();