LocalizedValue<T>.fromJson constructor

LocalizedValue<T>.fromJson(
  1. DynamicMap json
)

Class for storing translation data.

It consists of a pair of Locale and the corresponding T for the translation.

LocalizedValue.fromJson can be used to convert String and T pairs from Json. In that case, the key must be a string delimited by _, such as ja_JP.

Obtains the translation of Locale specified in value.

翻訳データを保存するためのクラス。

Localeとその翻訳に対応するTのペアで構成されます。

LocalizedValue.fromJsonを利用することでStringTのペアのJsonからの変換が可能です。 その場合、キーはja_JPのように_で区切られた文字列である必要があります。

valueで指定したLocaleの翻訳を取得します。

Implementation

factory LocalizedValue.fromJson(DynamicMap json) {
  return LocalizedValue(
    json.toList((key, value) {
      final keys = key.replaceAll("-", "_").split("_");
      return LocalizedLocaleValue(
        Locale(
          keys.first,
          keys.length > 1 ? keys.last : null,
        ),
        value as T,
      );
    }),
  );
}