Skip to content

A dart tool which generates ARB files from CSV files.

License

Notifications You must be signed in to change notification settings

defuncart/arb_generator

Repository files navigation

arb_generator

A dart tool which generates ARB files from CSV files.

Getting Started

A CSV file of the form

keys description en de
myKey The conventional newborn programmer greeting Hello world! Hallo Welt!
welcome A welcome message Welcome {firstName}! Willkommen {firstName}!
numberMessages An info message about new messages count {count, plural, zero{You have no new messages} one{You have 1 new message} other{You have {count} new messages}} {count, plural, zero{Du hast keine neue Nachrichten} one{Du hast eine neue Nachricht} other{Du hast {count} neue Nachrichten}}
whoseBook A message determine whose book it is {sex, select, male{His book} female{Her book} other{Their book}} {sex, select, male{Sein Buch} female{Ihr Buch} other{Ihr Buch}}

is generated into the following ARB file

{
  "@@locale": "en",
  "myKey": "Hello world!",
  "@myKey": {
    "description": "The conventional newborn programmer greeting"
  },
  "welcome": "Welcome {firstName}!",
  "@welcome": {
    "description": "A welcome message"
  },
  "numberMessages": "{count, plural, zero{You have no new messages} one{You have 1 new message} other{You have {count} new messages}}",
  "@numberMessages": {
    "description": "An info message about new messages count"
  },
  "whoseBook": "{sex, select, male{His book} female{Her book} other{Their book}}",
  "@whoseBook": {
    "description": "A message determine whose book it is"
  }
}

This ARB file can then be converted into localization delegates using intl or intl_utils.

Add dependency

Firstly, add the package as a dev dependency:

dev_dependencies: 
  arb_generator:

Define Settings

Next define arb_generator package settings in pubspec.yaml. Note that input_filepath is the only required parameter.

arb_generator:
  input_filepath: "assets_dev/test.csv"
  output_directory: "lib/l10n"
  filename_prepend: "intl_"
  csv_settings:
    delimiter: ";"
    description_index: 1
    base_index: 2
Setting Description
input_filepath Required. A path to the input CSV file.
output_directory A directory to generate the output ARB file(s). Defaults to lib/l10n
filename_prepend Text to prepend to filename of generated files. Defaults to empty string.
csv_settings: delimiter A delimiter to separate columns in the input CSV file. Defaults to ,.
csv_settings: description_index The description column index. Defaults to null.
csv_settings: base_index The column index of the base language in the input CSV file. Defaults to 1.

Run package

Ensure that your current working directory is the project root and run the following command:

dart run arb_generator

ARB files are then generated in output_directory.

Collaboration

Spotted any issues? Please open an issue on GitHub! Would like to contribute a new feature? Fork the repo and submit a PR!