Skip to content

Translations.byHttp could try reading the available files from the manifest #154

@marcglasberg

Description

@marcglasberg

Check the possibility of reading the available translation files from the assets directory by reading the manifest (just like we do for files), similar to what GettextImporter().fromAssetDirectory did

Future<Map<String, Map<String, String>>> fromAssetDirectory(
    String dir) async {
  var manifestContent = await rootBundle.loadString("AssetManifest.json");
  Map<String, dynamic> manifestMap = json.decode(manifestContent);

  Map<String, Map<String, String>> translations = HashMap();

  for (String path in manifestMap.keys) {
    if (!path.startsWith(dir)) continue;
    var fileName = path.split("/").last;
    if (!fileName.endsWith(_extension)) {
      print("➜ Ignoring file $path with unexpected file type "
          "(expected: $_extension).");
      continue;
    }
    var languageCode = fileName.split(".")[0];
    translations.addAll(await fromAssetFile(languageCode, path));
  }

  return translations;
}

Or something like

// Get a list of all file paths in the asset directory.
ret = await rootBundle
    .loadString('AssetManifest.json')
    .then((jsonStr) => jsonDecode(jsonStr) as Map<String, dynamic>)
    .then((map) => map.keys
    .where((String key) => key.startsWith("assets/$dir"))
    .toList());
[…](https://github.com/marcglasberg/i18n_extension/issues/153#)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions