init static method

dynamic init({
  1. required String url,
  2. Map<String, String>? headers,
  3. String sourceLocale = 'en',
  4. String? locale,
  5. List<String>? locales,
})

Implementation

static init({
  required String url,
  Map<String, String>? headers,
  String sourceLocale = 'en',
  String? locale,
  List<String>? locales,
}) {
  _reqUrl = url;
  _reqHeaders = headers ?? {};
  _sourceLocale = sourceLocale;
  _targetLocale = locale ?? 'en';
  _availableLocales = locales ?? ['en'];

  Uri fetchUri = Uri.parse(_reqUrl + '/' + _targetLocale + '.json');

  http.get(fetchUri, headers: _reqHeaders).then((res) {
    List body = jsonDecode(utf8.decode(res.bodyBytes));

    for (int i = 0; i < body.length; i++) {
      String hash = md5.convert(utf8.encode(body[i]['en'])).toString();

      globalTranslations[hash] = body[i][_targetLocale];
    }
  });
}