Skip to main content

Extracts FTL files from a directory and outputs them to a directory

Project description

FTL-Extract

Description

FTL-Extract is a Python package that extracts Fluent keys from .py files and generates a .ftl file with extracted keys.


Installation

Use the package manager pip to install FTL-Extract.

$ pip install FTL-Extract

Or use modern tool like UV to install FTL-Extract.

$ uv add --dev FTL-Extract

Usage

First of all, you should create locales directory in your project.

$ mkdir project_path/locales

Then, you can use the following command to extract keys from your code.

$ ftl_extract project_path/code_path project_path/locales

By default, FTL-Extract will create a directory named en and put all keys into _default.ftl file.

In some cases, you may want to extract keys to specific .ftl files. So, there is new keyword argument _path in i18n.get and i18n.<key>.

# Before
i18n.get("key-1", arg1="value1", arg2="value2")

# After
i18n.get("key-1", arg1="value1", arg2="value2", _path="dir/ftl_file.ftl")

# Also
i18n.key_1(arg1="value1", arg2="value2", _path="dir/ftl_file.ftl")

# Or
i18n.some.key_1(arg1="value1", arg2="value2", _path="dir/ftl_file.ftl")

💁‍♂️ Explanation of the ftl-extractor command

$ ftl_extract project_path/code_path project_path/locales
  • project_path/code_path - path to the project directory where the code is located.
  • project_path/locales - path to the project directory where the .ftl files will be located.

📚 Additional arguments

  • -l or --language - add a new language to the project.
  • -k or --i18n_keys - add additional i18n keys to the extractor.
  • --ignore-attributes - ignore specific attributes of the i18n.* like i18n.set_locale.
  • -a or --expand-ignore-attributes - add more attributes to ignore to the default list.
  • --ignore-kwargs - ignore specific kwargs of the i18n_keys like when=... in aiogram_dialog.I18nFormat(..., when=...).
  • --comment-junks - comments errored translations in the .ftl file.
  • --default-ftl-file - specify the default .ftl file name.
  • --comment-keys-mode - specify the comment keys mode. It will comment keys that are not used in the code or print warnings about them. Available modes: comment, warn.
  • --dry-run - run the command without making any changes to the files.
  • -v or --verbose - print additional information about the process.

FAQ

❓ - How to add more languages to the project ?

# Here we add 3 languages: English, Ukrainian and Polish
$ ftl_extract project_path/code_path project_path/locales -l en -l uk -l pl

❓ - How to detect another i18n keys like LazyProxy or L ?

# Here we extract ftl keys from i18n-keys like `i18n`, `LF`, `LazyProxy` and `L`
$ ftl_extract project_path/code_path project_path/locales -k i18n -k LF -k LazyProxy -k L

How I use FTL-Extract in most of my projects

$ ftl_extract \
  './app/bot' \
  './app/bot/locales' \
  -l 'en' \
  -l 'uk' \
  -k 'i18n' \
  -k 'L' \
  -k 'LF' \
  -k 'LazyProxy' \
  -a 'core' \
  --comment-junks \
  --comment-keys-mode 'warn' \
  --verbose

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftl_extract-0.7.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ftl_extract-0.7.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file ftl_extract-0.7.1.tar.gz.

File metadata

  • Download URL: ftl_extract-0.7.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.16

File hashes

Hashes for ftl_extract-0.7.1.tar.gz
Algorithm Hash digest
SHA256 56f4325a967026d5f40daec7f34237c5a530e606e4ea3df4f5f4aa4e1002b6e5
MD5 2b44f62b860466f2ff64306f08ecfb9c
BLAKE2b-256 21a91a4a7e0f2916e183918750b08a666ec4555f77f2ec11a0c2c552c630ee02

See more details on using hashes here.

File details

Details for the file ftl_extract-0.7.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ftl_extract-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf877a13f480f46b90a117d9daa963e1a13f58261dc638725794f9b4f147ec9
MD5 b06f552bef0ea887ac9ebf35c1f9da17
BLAKE2b-256 dea35869f02ac787814ca53732a45022fb825355bd1b2359c596829eb4f6a6ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page