localizeValue method

String localizeValue(
  1. String key,
  2. String value
)

Tries to localize text by given key and value.

child: { "male": "boy", "female": "girl", "other": "child" }

Enable/Disable debug mode to show/hide missing localizations.

Implementation

String localizeValue(String key, String value) {
  if (_data.containsKey(key)) {
    if (_data[key] is Map) {
      final map = _data[key] as Map;

      if (map.containsKey(value)) {
        return map[value];
      }

      if (map.containsKey('other')) {
        return map['other'];
      }
    }

    return _data[key];
  }

  return debug ? '$key[$value]_$_locale' : '';
}