Run code clean and fix messages (#45)
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m13s
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m13s
Reviewed-on: #45
This commit was merged in pull request #45.
This commit is contained in:
@@ -5,22 +5,22 @@ namespace GameIdeas.Resources;
|
||||
|
||||
public class TranslationService
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<string, string>?> _translations = new();
|
||||
private readonly Dictionary<string, Dictionary<string, string>?> _translations = [];
|
||||
|
||||
public void Initialize(Dictionary<string, string> translations)
|
||||
{
|
||||
foreach (var translation in translations)
|
||||
{
|
||||
var json = JsonSerializer.Deserialize<Dictionary<string, string>>(translation.Value);
|
||||
_translations[translation.Key] = json;
|
||||
}
|
||||
}
|
||||
public void Initialize(Dictionary<string, string> translations)
|
||||
{
|
||||
foreach (var translation in translations)
|
||||
{
|
||||
var json = JsonSerializer.Deserialize<Dictionary<string, string>>(translation.Value);
|
||||
_translations[translation.Key] = json;
|
||||
}
|
||||
}
|
||||
|
||||
public string Translate(string key, string? culture = "fr")
|
||||
{
|
||||
culture ??= CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
||||
if (_translations.TryGetValue(culture, out var value) && value?.TryGetValue(key, out var translate) == true)
|
||||
return translate;
|
||||
return key; // Fallback to key if translation is missing
|
||||
}
|
||||
public string Translate(string key, string? culture = "fr")
|
||||
{
|
||||
culture ??= CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
||||
if (_translations.TryGetValue(culture, out var value) && value?.TryGetValue(key, out var translate) == true)
|
||||
return translate;
|
||||
return key; // Fallback to key if translation is missing
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user