fix(localization): improve translation fallback logic and clean up code
This commit is contained in:
@@ -20,6 +20,7 @@ public class LocalizationServiceImpl implements LocalizationService {
|
||||
public final static String NOT_FOUND_PREFIX = "{i18n.";
|
||||
|
||||
private static final List<String> LANGUAGE_STORAGE_PATH = List.of("gameEngine");
|
||||
|
||||
private static final String LANGUAGE_STORAGE_NAME = "currentLanguage";
|
||||
|
||||
private final StorageService storageService;
|
||||
@@ -122,14 +123,17 @@ public class LocalizationServiceImpl implements LocalizationService {
|
||||
if (this.currentLanguage == null) {
|
||||
return NOT_FOUND_PREFIX + id + "}";
|
||||
}
|
||||
return this.currentLanguage.computeIfAbsent(id, key -> NOT_FOUND_PREFIX + key + "}");
|
||||
return this.currentLanguage.computeIfAbsent(id, key -> key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate(final String id, final String defaultText) {
|
||||
String result = this.translate(id);
|
||||
if (result.startsWith(NOT_FOUND_PREFIX)) {
|
||||
result = defaultText;
|
||||
if (this.currentLanguage == null) {
|
||||
return defaultText;
|
||||
}
|
||||
var result = this.currentLanguage.get(id);
|
||||
if (result == null) {
|
||||
return defaultText;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user