2021-08-10 07:37:33 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2021-05-10 11:58:21 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Emby.Server.Implementations.Localization;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Implementations.Tests.Localization
|
|
|
|
|
{
|
|
|
|
|
public class LocalizationManagerTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetCountries_All_Success()
|
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration
|
|
|
|
|
{
|
|
|
|
|
UICulture = "de-DE"
|
|
|
|
|
});
|
2021-08-10 14:28:57 -04:00
|
|
|
|
var countries = localizationManager.GetCountries().ToList();
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-08-10 14:28:57 -04:00
|
|
|
|
Assert.Equal(139, countries.Count);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-08-10 14:28:57 -04:00
|
|
|
|
var germany = countries.FirstOrDefault(x => x.Name.Equals("DE", StringComparison.Ordinal));
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(germany);
|
|
|
|
|
Assert.Equal("Germany", germany!.DisplayName);
|
2021-08-10 07:37:33 -04:00
|
|
|
|
Assert.Equal("DEU", germany.ThreeLetterISORegionName);
|
|
|
|
|
Assert.Equal("DE", germany.TwoLetterISORegionName);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetCultures_All_Success()
|
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration
|
|
|
|
|
{
|
|
|
|
|
UICulture = "de-DE"
|
|
|
|
|
});
|
|
|
|
|
await localizationManager.LoadAll();
|
|
|
|
|
var cultures = localizationManager.GetCultures().ToList();
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2023-01-09 14:47:12 -05:00
|
|
|
|
Assert.Equal(191, cultures.Count);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-08-10 14:28:57 -04:00
|
|
|
|
var germany = cultures.FirstOrDefault(x => x.TwoLetterISOLanguageName.Equals("de", StringComparison.Ordinal));
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(germany);
|
|
|
|
|
Assert.Equal("ger", germany!.ThreeLetterISOLanguageName);
|
2021-08-10 07:37:33 -04:00
|
|
|
|
Assert.Equal("German", germany.DisplayName);
|
|
|
|
|
Assert.Equal("German", germany.Name);
|
|
|
|
|
Assert.Contains("deu", germany.ThreeLetterISOLanguageNames);
|
|
|
|
|
Assert.Contains("ger", germany.ThreeLetterISOLanguageNames);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("de")]
|
|
|
|
|
[InlineData("ger")]
|
|
|
|
|
[InlineData("german")]
|
2021-08-11 06:57:31 -04:00
|
|
|
|
public async Task FindLanguageInfo_Valid_Success(string identifier)
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration
|
|
|
|
|
{
|
|
|
|
|
UICulture = "de-DE"
|
|
|
|
|
});
|
|
|
|
|
await localizationManager.LoadAll();
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var germany = localizationManager.FindLanguageInfo(identifier);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(germany);
|
|
|
|
|
|
2021-08-15 11:20:07 -04:00
|
|
|
|
Assert.Equal("ger", germany!.ThreeLetterISOLanguageName);
|
2021-08-10 07:37:33 -04:00
|
|
|
|
Assert.Equal("German", germany.DisplayName);
|
|
|
|
|
Assert.Equal("German", germany.Name);
|
|
|
|
|
Assert.Contains("deu", germany.ThreeLetterISOLanguageNames);
|
|
|
|
|
Assert.Contains("ger", germany.ThreeLetterISOLanguageNames);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2021-08-11 06:57:31 -04:00
|
|
|
|
public async Task GetParentalRatings_Default_Success()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration
|
|
|
|
|
{
|
|
|
|
|
UICulture = "de-DE"
|
|
|
|
|
});
|
|
|
|
|
await localizationManager.LoadAll();
|
|
|
|
|
var ratings = localizationManager.GetParentalRatings().ToList();
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2023-03-09 08:13:57 -05:00
|
|
|
|
Assert.Equal(54, ratings.Count);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-08-10 14:28:57 -04:00
|
|
|
|
var tvma = ratings.FirstOrDefault(x => x.Name.Equals("TV-MA", StringComparison.Ordinal));
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(tvma);
|
2022-10-09 16:56:23 -04:00
|
|
|
|
Assert.Equal(17, tvma!.Value);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2021-08-11 06:57:31 -04:00
|
|
|
|
public async Task GetParentalRatings_ConfiguredCountryCode_Success()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
|
|
|
|
MetadataCountryCode = "DE"
|
|
|
|
|
});
|
2021-05-25 06:33:55 -04:00
|
|
|
|
await localizationManager.LoadAll();
|
|
|
|
|
var ratings = localizationManager.GetParentalRatings().ToList();
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2023-07-20 06:10:02 -04:00
|
|
|
|
Assert.Equal(24, ratings.Count);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
|
2021-08-10 14:28:57 -04:00
|
|
|
|
var fsk = ratings.FirstOrDefault(x => x.Name.Equals("FSK-12", StringComparison.Ordinal));
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(fsk);
|
2022-10-09 16:56:23 -04:00
|
|
|
|
Assert.Equal(12, fsk!.Value);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
2022-10-09 16:56:23 -04:00
|
|
|
|
[InlineData("CA-R", "CA", 18)]
|
|
|
|
|
[InlineData("FSK-16", "DE", 16)]
|
|
|
|
|
[InlineData("FSK-18", "DE", 18)]
|
|
|
|
|
[InlineData("FSK-18", "US", 18)]
|
|
|
|
|
[InlineData("TV-MA", "US", 17)]
|
|
|
|
|
[InlineData("XXX", "asdf", 1000)]
|
|
|
|
|
[InlineData("Germany: FSK-18", "DE", 18)]
|
2021-08-11 06:57:31 -04:00
|
|
|
|
public async Task GetRatingLevel_GivenValidString_Success(string value, string countryCode, int expectedLevel)
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
|
|
|
|
MetadataCountryCode = countryCode
|
|
|
|
|
});
|
2021-05-25 06:33:55 -04:00
|
|
|
|
await localizationManager.LoadAll();
|
|
|
|
|
var level = localizationManager.GetRatingLevel(value);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(level);
|
|
|
|
|
Assert.Equal(expectedLevel, level!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2021-08-11 06:57:31 -04:00
|
|
|
|
public async Task GetRatingLevel_GivenUnratedString_Success()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration()
|
|
|
|
|
{
|
|
|
|
|
UICulture = "de-DE"
|
|
|
|
|
});
|
|
|
|
|
await localizationManager.LoadAll();
|
2022-10-09 16:56:23 -04:00
|
|
|
|
Assert.Null(localizationManager.GetRatingLevel("NR"));
|
|
|
|
|
Assert.Null(localizationManager.GetRatingLevel("unrated"));
|
|
|
|
|
Assert.Null(localizationManager.GetRatingLevel("Not Rated"));
|
2021-05-25 06:33:55 -04:00
|
|
|
|
Assert.Null(localizationManager.GetRatingLevel("n/a"));
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("Default", "Default")]
|
|
|
|
|
[InlineData("HeaderLiveTV", "Live TV")]
|
|
|
|
|
public void GetLocalizedString_Valid_Success(string key, string expected)
|
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
|
|
|
|
UICulture = "en-US"
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var translated = localizationManager.GetLocalizedString(key);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(translated);
|
|
|
|
|
Assert.Equal(expected, translated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetLocalizedString_Invalid_Success()
|
|
|
|
|
{
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var localizationManager = Setup(new ServerConfiguration()
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
|
|
|
|
UICulture = "en-US"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var key = "SuperInvalidTranslationKeyThatWillNeverBeAdded";
|
|
|
|
|
|
2021-05-25 06:33:55 -04:00
|
|
|
|
var translated = localizationManager.GetLocalizedString(key);
|
2021-05-10 11:58:21 -04:00
|
|
|
|
Assert.NotNull(translated);
|
|
|
|
|
Assert.Equal(key, translated);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 06:33:55 -04:00
|
|
|
|
private LocalizationManager Setup(ServerConfiguration config)
|
2021-05-10 11:58:21 -04:00
|
|
|
|
{
|
|
|
|
|
var mockConfiguration = new Mock<IServerConfigurationManager>();
|
|
|
|
|
mockConfiguration.SetupGet(x => x.Configuration).Returns(config);
|
|
|
|
|
|
2021-05-25 06:33:55 -04:00
|
|
|
|
return new LocalizationManager(mockConfiguration.Object, new NullLogger<LocalizationManager>());
|
2021-05-10 11:58:21 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|