localizeFormat method
Tries to localize text by given key
.
Then format string with given params
.
Simply replaces strings with params. For more complex formatting can be better to use Intl
.
Set custom ParamDecoratorFormat to decorate param, for example: 'city' => '{city}' or 'city' => '$city'
Default decorator is set to ParamDecorator.curl
'Weather in {city} is {temp}°{symbol}'
Then params
are:
{
{'city': 'California'},
{'temp': '25.5'},
{'symbol': 'C'},
}
Returns formatted string.
Enable/Disable debug mode to show/hide missing localizations.
Implementation
String localizeFormat(String key, Map<String, String> params) {
if (_data.containsKey(key)) {
return Parse.format(_data[key], params, _paramDecorator);
}
return debug ? '${key}_$_locale' : '';
}