getTranslation method
- String localeTag
Returns the translation map for the given localeTag (e.g. en-UK).
The key used in Remote Config is the locale tag with hyphens replaced by
underscores (e.g. en_UK) to satisfy Remote Config key naming rules.
Remote Config is pre-seeded with the local translation file as its default value, so if the remote fetch failed or the key is missing, the local file is returned automatically. Returns an empty map only if both the remote value and the default are missing or malformed.
Implementation
Map<String, dynamic> getTranslation(String localeTag) {
final String key = localeTag.replaceAll('-', '_');
final String raw = _remoteConfig.getString(key);
if (raw.isEmpty) {
_logger.warn('[RemoteConfig] Translation value is empty for key "$key" — EasyLocalization will show raw keys');
return <String, dynamic>{};
}
try {
return json.decode(raw) as Map<String, dynamic>;
} catch (e, st) {
_logger.error('[RemoteConfig] Failed to decode translation JSON for key "$key"', error: e, stackTrace: st);
return <String, dynamic>{};
}
}