mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Minor improvements
This commit is contained in:
parent
6b61b50b53
commit
b5880c2680
@ -22,6 +22,9 @@ namespace Emby.Server.Implementations.Localization
|
||||
public class LocalizationManager : ILocalizationManager
|
||||
{
|
||||
private const string DefaultCulture = "en-US";
|
||||
private const string RatingsPath = "Emby.Server.Implementations.Localization.Ratings.";
|
||||
private const string CulturesPath = "Emby.Server.Implementations.Localization.iso6392.txt";
|
||||
private const string CountriesPath = "Emby.Server.Implementations.Localization.countries.json";
|
||||
private static readonly Assembly _assembly = typeof(LocalizationManager).Assembly;
|
||||
private static readonly string[] _unratedValues = { "n/a", "unrated", "not rated" };
|
||||
|
||||
@ -57,22 +60,19 @@ namespace Emby.Server.Implementations.Localization
|
||||
/// <returns><see cref="Task" />.</returns>
|
||||
public async Task LoadAll()
|
||||
{
|
||||
const string RatingsResource = "Emby.Server.Implementations.Localization.Ratings.";
|
||||
|
||||
// Extract from the assembly
|
||||
foreach (var resource in _assembly.GetManifestResourceNames())
|
||||
{
|
||||
if (!resource.StartsWith(RatingsResource, StringComparison.Ordinal))
|
||||
if (!resource.StartsWith(RatingsPath, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string countryCode = resource.Substring(RatingsResource.Length, 2);
|
||||
string countryCode = resource.Substring(RatingsPath.Length, 2);
|
||||
var dict = new Dictionary<string, ParentalRating>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
using (var str = _assembly.GetManifestResourceStream(resource))
|
||||
using (var reader = new StreamReader(str))
|
||||
{
|
||||
await using var str = _assembly.GetManifestResourceStream(resource);
|
||||
using var reader = new StreamReader(str);
|
||||
await foreach (var line in reader.ReadAllLinesAsync().ConfigureAwait(false))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
@ -94,7 +94,6 @@ namespace Emby.Server.Implementations.Localization
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
_allParentalRatings[countryCode] = dict;
|
||||
}
|
||||
@ -113,11 +112,8 @@ namespace Emby.Server.Implementations.Localization
|
||||
{
|
||||
List<CultureDto> list = new List<CultureDto>();
|
||||
|
||||
const string ResourcePath = "Emby.Server.Implementations.Localization.iso6392.txt";
|
||||
|
||||
using (var stream = _assembly.GetManifestResourceStream(ResourcePath))
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
await using var stream = _assembly.GetManifestResourceStream(CulturesPath);
|
||||
using var reader = new StreamReader(stream);
|
||||
await foreach (var line in reader.ReadAllLinesAsync().ConfigureAwait(false))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
@ -160,7 +156,6 @@ namespace Emby.Server.Implementations.Localization
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cultures = list;
|
||||
}
|
||||
@ -177,7 +172,7 @@ namespace Emby.Server.Implementations.Localization
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<CountryInfo> GetCountries()
|
||||
{
|
||||
using StreamReader reader = new StreamReader(_assembly.GetManifestResourceStream("Emby.Server.Implementations.Localization.countries.json"));
|
||||
using StreamReader reader = new StreamReader(_assembly.GetManifestResourceStream(CountriesPath));
|
||||
|
||||
return JsonSerializer.Deserialize<IEnumerable<CountryInfo>>(reader.ReadToEnd(), _jsonOptions);
|
||||
}
|
||||
@ -338,8 +333,7 @@ namespace Emby.Server.Implementations.Localization
|
||||
|
||||
private async Task CopyInto(IDictionary<string, string> dictionary, string resourcePath)
|
||||
{
|
||||
using (var stream = _assembly.GetManifestResourceStream(resourcePath))
|
||||
{
|
||||
await using var stream = _assembly.GetManifestResourceStream(resourcePath);
|
||||
// If a Culture doesn't have a translation the stream will be null and it defaults to en-us further up the chain
|
||||
if (stream != null)
|
||||
{
|
||||
@ -355,7 +349,6 @@ namespace Emby.Server.Implementations.Localization
|
||||
_logger.LogError("Missing translation/culture resource: {ResourcePath}", resourcePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetResourceFilename(string culture)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user