Skip to content

A code generator that generates all the keys in a language file to be used with the localization package.

License

Notifications You must be signed in to change notification settings

Stacked-Org/localization_generator

Repository files navigation

Stacked Localisation Generator

A code generator that generates all the keys in a language file to be used with the stacked_localisation package.

Setup

This package (and build_runner if you don't already have it) should be added as a dev dependency in the project you're using.

dev_dependencies:
  ...
  build_runner:
  stacked_localisation_generator:

Then create a new folder in root called assets with another folder inside it called lang. This folder will contain the language json or yaml files. Here's an example of a file called en.json

{
  "HomeView": {
    "title": "This is my Home",
    "subtitle": "I live in this Home"
  }
}

or for en.yaml

HomeView:
  title: This is my Home
  subtitle: I live in this Home

When you run flutter pub run build_runner build --delete-conflicting-outputs the package will generate a new file called localisation_string_keys.dart that can be found at the root of the lib folder that contains type save keys for the language string definition above. The above will produce the following keys.

/// This code is generated. DO NOT edit by hand

class HomeViewStrings {
  static String title = 'HomeView.title';
  static String subtitle = 'HomeView.subtitle';
}

This can be accessed statically throughout the application where the keys are required. To see a full example of using stacked_localisaion you can check out the walkthrough here.

Contributing

To run all generator tests:

flutter pub run build_runner test

About

A code generator that generates all the keys in a language file to be used with the localization package.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages