load method

Future<bool> load()

Load localized values from the spreadsheet. Uses cache, so if the network connection is not available, the cached version is returned.

Implementation

Future<bool> load() async {
  var _file = await _loadSpreadsheetWithCache();
  var data = jsonDecode(await _file.readAsString());
  List<dynamic> entries = data['feed']['entry'];
  loadedLanguages = entries[0]
      .keys
      .toList()
      .where((element) => element.startsWith('gsx') && element != 'gsx\$key')
      .map((element) => element.replaceFirst('gsx\$', ''))
      .toList()
      .cast<String>();
  localizedValues =
      Map.fromIterable(loadedLanguages, key: (e) => e, value: (_e) => {});

  entries.forEach((translation) {
    final key = translation['gsx\$key']['\$t'];
    loadedLanguages.forEach((language) {
      localizedValues[language]![key] = translation['gsx\$$language']['\$t'];
    });
  });
  return true;
}