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

1

10

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?

Nijinsky answered 13/3, 2022 at 12:1 Comment(0)
E
6

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

Erenow answered 19/8, 2022 at 16:54 Comment(1)
Thank you for your response. It's a nice trick. I didn't find any way to use the .ard file so I'm using JSON files. I think with the easy_localization package and arb file editor, it's better to use the JSON files.Nijinsky

© 2022 - 2024 — McMap. All rights reserved.