|
1 | 1 | using SecureFolderFS.Sdk.Services;
|
2 |
| -using System; |
| 2 | +using SecureFolderFS.UI.ServiceImplementation; |
3 | 3 | using System.Collections.Generic;
|
4 |
| -using System.Diagnostics; |
| 4 | +using System.Collections.Immutable; |
5 | 5 | using System.Globalization;
|
6 | 6 | using System.Linq;
|
7 | 7 | using System.Resources;
|
|
11 | 11 | namespace SecureFolderFS.WinUI.ServiceImplementation
|
12 | 12 | {
|
13 | 13 | /// <inheritdoc cref="ILocalizationService"/>
|
14 |
| - internal sealed class LocalizationService : ILocalizationService |
| 14 | + internal sealed class LocalizationService : BaseLocalizationService |
15 | 15 | {
|
16 |
| - private ResourceManager ResourceManager { get; set; } |
| 16 | + /// <inheritdoc/> |
| 17 | + protected override ResourceManager ResourceManager { get; } |
17 | 18 |
|
18 | 19 | /// <inheritdoc/>
|
19 |
| - public CultureInfo CurrentCulture { get; } |
| 20 | + public override CultureInfo CurrentCulture { get; } |
20 | 21 |
|
21 | 22 | /// <inheritdoc/>
|
22 |
| - public IReadOnlyList<CultureInfo> AppLanguages { get; } |
| 23 | + public override IReadOnlyList<CultureInfo> AppLanguages { get; } |
23 | 24 |
|
24 | 25 | public LocalizationService()
|
25 | 26 | {
|
26 |
| - CurrentCulture = new(ApplicationLanguages.PrimaryLanguageOverride); |
27 |
| - AppLanguages = ApplicationLanguages.ManifestLanguages |
28 |
| - .Select(x => new CultureInfo(x)) |
29 |
| - .ToList(); |
30 |
| - |
| 27 | + CurrentCulture = new(SupportedLanguages.First(x => x.Contains(ApplicationLanguages.PrimaryLanguageOverride))); |
| 28 | + AppLanguages = GetAppLanguages().ToImmutableList(); |
31 | 29 | ResourceManager = new($"SecureFolderFS.UI.Strings.{GetLanguageString(CurrentCulture)}.Resources", typeof(UI.Constants).Assembly);
|
32 | 30 | }
|
33 | 31 |
|
34 | 32 | /// <inheritdoc/>
|
35 |
| - public string? GetString(string resourceKey) |
36 |
| - { |
37 |
| - try |
38 |
| - { |
39 |
| - return ResourceManager.GetString(resourceKey); |
40 |
| - } |
41 |
| - catch (Exception ex) |
42 |
| - { |
43 |
| - _ = ex; |
44 |
| - Debugger.Break(); |
45 |
| - |
46 |
| - return null; |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - /// <inheritdoc/> |
51 |
| - public Task SetCultureAsync(CultureInfo cultureInfo) |
| 33 | + public override Task SetCultureAsync(CultureInfo cultureInfo) |
52 | 34 | {
|
53 | 35 | ApplicationLanguages.PrimaryLanguageOverride = cultureInfo.Name;
|
54 | 36 | return Task.CompletedTask;
|
55 | 37 | }
|
56 | 38 |
|
57 |
| - private static string GetLanguageString(CultureInfo cultureInfo) |
| 39 | + private IEnumerable<CultureInfo> GetAppLanguages() |
58 | 40 | {
|
59 |
| - if (cultureInfo.Name.Contains('-', StringComparison.OrdinalIgnoreCase)) |
60 |
| - return cultureInfo.Name.Replace('-', '_'); |
61 |
| - |
62 |
| - return $"{cultureInfo.Name}_{cultureInfo.TwoLetterISOLanguageName.ToUpperInvariant()}"; |
| 41 | + foreach (var item in ApplicationLanguages.ManifestLanguages) |
| 42 | + { |
| 43 | + yield return new(SupportedLanguages.First(x => x.Contains(item))); |
| 44 | + } |
63 | 45 | }
|
64 | 46 | }
|
65 | 47 | }
|
0 commit comments