|
2 | 2 |
|
3 | 3 | using System; |
4 | 4 | using System.Globalization; |
| 5 | +using System.Linq; |
5 | 6 | using System.Resources; |
6 | 7 | using osu.Framework.Localisation; |
7 | 8 |
|
8 | 9 | namespace osu.Game.Rulesets.Space.Localisation |
9 | 10 | { |
10 | 11 | public static class SpaceStrings |
11 | 12 | { |
12 | | - private static readonly ResourceManager vietnamese = new ResourceManager("osu.Game.Rulesets.Space.Localisation.SpaceStrings.vi", typeof(SpaceStrings).Assembly); |
13 | | - private static readonly ResourceManager japanese = new ResourceManager("osu.Game.Rulesets.Space.Localisation.SpaceStrings.ja", typeof(SpaceStrings).Assembly); |
| 13 | + private static readonly System.Collections.Generic.Dictionary<string, ResourceManager> resources = |
| 14 | + typeof(SpaceStrings).Assembly.GetManifestResourceNames() |
| 15 | + .Where(name => name.StartsWith(typeof(SpaceStrings).FullName + ".", StringComparison.Ordinal) |
| 16 | + && name.EndsWith(".resources", StringComparison.Ordinal) |
| 17 | + && name.Length > typeof(SpaceStrings).FullName!.Length + ".resources".Length + 1) |
| 18 | + .ToDictionary( |
| 19 | + name => name.Substring(typeof(SpaceStrings).FullName!.Length + 1, name.Length - typeof(SpaceStrings).FullName!.Length - ".resources".Length - 1), |
| 20 | + name => new ResourceManager(name.Substring(0, name.Length - ".resources".Length), typeof(SpaceStrings).Assembly), |
| 21 | + StringComparer.OrdinalIgnoreCase |
| 22 | + ); |
14 | 23 |
|
15 | 24 | public static LocalisableString Get(string english) => |
16 | 25 | new LocalisableString(new SpaceString(english)); |
@@ -46,12 +55,10 @@ private sealed class SpaceString : ILocalisableStringData |
46 | 55 | public SpaceString(string english) => this.english = english; |
47 | 56 |
|
48 | 57 | public string GetLocalised(LocalisationParameters parameters) => |
49 | | - (parameters.Store?.EffectiveCulture.TwoLetterISOLanguageName switch |
50 | | - { |
51 | | - "vi" => vietnamese.GetString(english, CultureInfo.InvariantCulture), |
52 | | - "ja" => japanese.GetString(english, CultureInfo.InvariantCulture), |
53 | | - _ => null, |
54 | | - }) ?? english; |
| 58 | + parameters.Store != null |
| 59 | + && resources.TryGetValue(parameters.Store.EffectiveCulture.TwoLetterISOLanguageName, out var resource) |
| 60 | + ? resource.GetString(english, CultureInfo.InvariantCulture) ?? english |
| 61 | + : english; |
55 | 62 |
|
56 | 63 | public bool Equals(ILocalisableStringData? other) => |
57 | 64 | other is SpaceString value && english == value.english; |
|
0 commit comments