localize_generator_keys 0.0.1 copy "localize_generator_keys: ^0.0.1" to clipboard
localize_generator_keys: ^0.0.1 copied to clipboard

A CLI to extract hardcoded text and generate localization JSON fully automation localization migrate from your hardcoded strings.

localize_generator_keys #

A Dart CLI tool that automatically scans your Flutter project for hardcoded UI strings and replaces them with .tr keys for localization using GetX. EasyLocalization etc It also generates a corresponding JSON file containing the translations.

๐Ÿš€ Features #

  • Detects and replaces hardcoded strings in widgets like Text, TextSpan, RichText, Text.rich, and buttons.
  • Generates a translation key based on the original string.
  • Outputs a structured JSON file under assets/lang/.
  • Supports customization for language code.

๐Ÿ“ฆ Installation #

Add the package to dev_dependencies in pubspec.yaml:

dev_dependencies:
  localize_generator_keys: latest

or

dart pub global activate localize_generator_keys

๐Ÿ”ง Usage #

From the root of your Flutter project:

dart run localize_generator_keys 

also can use it like

dart run localize_generator_keys . en
  • The first argument is the root path to scan (e.g., .).
  • The second argument is the language code (en, ar, etc).

The tool will:

  • Scan all .dart files under lib/
  • Replace hardcoded strings with .tr keys
  • Output assets/lang/lang_en.json

๐Ÿง  How it works #

This tool uses regular expressions to match widgets like:

Text("Hello World")
TextSpan(text: "Welcome")
TextButton(child: Text("Click Me"))

And transforms them into:

Text("hello_world".tr)
TextSpan(text: "welcome".tr)
TextButton(child: Text("click_me".tr))

With a generated lang_en.json like:

{
  "hello_world": "Hello World",
  "welcome": "Welcome",
  "click_me": "Click Me"
}

๐Ÿ“ Output #

assets/
โ””โ”€โ”€ lang/
    โ””โ”€โ”€ lang_en.json

Great Mix #

๐ŸŒ Support for Multiple Languages (Offline) #

To translate your translation files (lang_en.json) to other languages without the need for an internet connection, you can use the argos_translator_offline package that I developed.

โœ… Features: #

  • Offline translation using the Argos Translate library.
  • Supports more than 50 languages.
  • No external API or internet connection required.

๐Ÿงช Example Usage: #

dart run argos_translator_offline path=assets/lang/lang_en.json from=en to=ar

This will translate the file from English to Arabic while maintaining the same structure.

For more details, check out the argos_translator_offline package page on pub.dev.

โš ๏ธ Limitations #

  • Only works with strings in quotes (single/double).
  • Does not detect variables inside text.
  • Regex-based matching may skip edge cases.

๐Ÿ“„ License #

MIT


Built with โค๏ธ by [abdelrhmantolba.online]

2
likes
0
points
0
downloads

Publisher

verified publisherabdelrhmantolba.online

Weekly Downloads

A CLI to extract hardcoded text and generate localization JSON fully automation localization migrate from your hardcoded strings.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

path

More

Packages that depend on localize_generator_keys