Flutter Internationalization: How to generate AppLocalizations file with nested objects in .arb?

1.9k Views Asked by At

How can we use nested objects in arb files? Flutter gen doesn't work if there's a nested object.

l10n.yaml

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
output-class: AppLocalizations
synthetic-package: false

pubspec.yaml

flutter:
  generate: true

app_en.arb

  "clients": {
    "label": "Client",
    "title": {
      "add": "New Client",
      "details": "Client Details",
      "edit": "Edit Client",
      "manage": "Manage Clients"
    }
  },

app_bn.arb

   "clients": {
    "label": "ক্লায়েন্ট",
    "title": {
      "add": "নতুন ক্লায়েন্ট",
      "details": "ক্লায়েন্ট ডিটেলস",
      "edit": "এডিট ক্লায়েন্ট",
      "manage": "ক্লায়েন্ট পরিচালনা"
    }
  },

If I run the files to generate the translation flutter throws an exception.

Exception: The value of "clients" is not a string.

Can't find any solution with nested objects in arb files. I found some ways to do it with JSON files. But I want to use arb files.

Is there any way to do it with arb files?

1

There are 1 best solutions below

1
On

As of the time of writing this comment there is no way to do that

However one trick I particularly use to organize sections goes like this :

 {
        "@_CLIENT": {} 
        "client_label": "Client",
        "client_title_add":"New Client",
        "client_title_details":"Client Details",
        "client_title_edit": "Edit Client",
        "client_title_manage": "Manage Clients"
        }

the @ helps me find sections Hope This Helps