Skip to main content

Extract fluent keys from python code and organize them in .ftl files

Project description

FTL-Extract

Description

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

The ftl CLI is implemented in Rust and ships as a native binary inside the Python wheel.


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.

You can also keep command defaults in pyproject.toml:

[tool.ftl-extract.extract]
code-path = "project_path/code_path"
output-path = "project_path/locales"
languages = ["en", "uk"]
i18n-keys-append = ["LF", "LazyProxy"]
ignore-attributes-append = ["core"]
exclude-dirs-append = ["./tests/*"]
ignore-kwargs = ["when"]
comment-junks = true
comment-keys-mode = "comment"
line-endings = "lf"
cache = true

[tool.ftl-extract.stub]
ftl-path = "project_path/locales/en"
output-path = "project_path/code_path/stub.pyi"
export-tree = false

[tool.ftl-extract.untranslated]
locales-path = "project_path/locales"
languages = ["uk"]
suggest-from = ["en"]
fail-on-untranslated = true
output = "reports/untranslated"
output-format = "json"

Then run commands without repeating the configured paths:

$ ftl extract
$ ftl stub
$ ftl untranslated

By default, ftl searches for pyproject.toml from the current directory upward. Use --config to select a specific file:

$ ftl --config ./pyproject.toml extract

CLI arguments override values from pyproject.toml; built-in defaults are used when neither is provided.

To print a ready-to-edit configuration sample, use:

$ ftl config sample
$ ftl config sample --command extract

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 extract 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.
  • -K or --i18n-keys-append - add additional i18n keys to the extractor and append them to the default list.
  • -p or --i18n-keys-prefix - add a prefix to the i18n keys. For example, self.i18n.<key>().
  • -e or --exclude-dirs - exclude specific directories from the extraction process.
  • -E or --exclude-dirs-append - add more directories to exclude from the extraction process.
  • -i or --ignore-attributes - ignore specific attributes of the i18n.* like i18n.set_locale.
  • -I or --append-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.
  • -v or --verbose - print additional information about the process.
  • --dry-run - run the command without making any changes to the files.
  • --cache - cache extracted Python keys between runs and reuse them when source file metadata and extractor options are unchanged. By default, the cache is stored in .ftl-extract-cache/extract-<package-version>-v<schema-version>.bin.
  • --cache-path - custom cache directory or file path. Directory paths store the cache as extract-<package-version>-v<schema-version>.bin. Passing this option enables the cache.
  • --clear-cache - delete the existing extraction cache before running.

💁‍♂️ Explanation of the ftl stub command

$ ftl stub 'project_path/locales/<locale>' 'project_path/code_path'
  • project_path/locales/<locale> - path to the locales directory where the <locale> directory (e.g. en) contains .ftl files located.
  • project_path/code_path - path to the directory where the stub.pyi will be located.

💁‍♂️ Explanation of the ftl untranslated command

$ ftl untranslated project_path/locales
  • project_path/locales - path to the locales root directory that contains locale folders like en, uk, etc.

📚 Additional arguments

  • -l or --language - check only selected locales. Can be passed multiple times.
  • --suggest-from - locale(s) used to suggest non-placeholder translations for missing items. Can be passed multiple times.
  • --fail-on-untranslated - return exit code 1 if untranslated keys are found.
  • --output - optional output file path for batch processing reports. If no extension is provided, .txt or .json is appended automatically based on --output-format.
  • --output-format - report file format: txt or json (default: txt).

🙈 Ignore marker for intentional placeholders

If a key is intentionally the same as its message id (for example, brand or domain terms like balance = balance), add a message comment marker above it:

# ftl-extract: ignore-untranslated
balance = balance

This key will be skipped by ftl untranslated.

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 `LF`, `LazyProxy` and `L`
$ ftl extract project_path/code_path project_path/locales -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 'LF' \
  -I 'core' \
  -E './tests/*' \
  --ignore-kwargs 'when' \
  --comment-junks \
  --comment-keys-mode 'comment' \
  --cache \
  --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.11.0.tar.gz (45.4 kB view details)

Uploaded Source

Built Distributions

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

ftl_extract-0.11.0-py3-none-win_amd64.whl (2.2 MB view details)

Uploaded Python 3Windows x86-64

ftl_extract-0.11.0-py3-none-musllinux_1_2_x86_64.whl (2.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ftl_extract-0.11.0-py3-none-musllinux_1_2_aarch64.whl (2.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ftl_extract-0.11.0-py3-none-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

ftl_extract-0.11.0-py3-none-manylinux_2_28_aarch64.whl (2.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

ftl_extract-0.11.0-py3-none-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: ftl_extract-0.11.0.tar.gz
  • Upload date:
  • Size: 45.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ftl_extract-0.11.0.tar.gz
Algorithm Hash digest
SHA256 4c61dc591d574a439d2d8a67230c4e3c713d42122220ee483535f8a651d797aa
MD5 ffbd09adf2bf597e293affeb590ffa08
BLAKE2b-256 7f67587bdfcc124fe05b52164e91bea94b1e10021089424343d6b2d17c94c3fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0.tar.gz:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: ftl_extract-0.11.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ftl_extract-0.11.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 3121d24c6ef0e20541852af5db5b3ba9169e885cc89e6f6db3e86d6facb1d867
MD5 e05992aa099028153b85c1c639be7727
BLAKE2b-256 04f9e40de94314a329369fff8d80ff46551a2f3bcc9915b5fe6ccb8a6a21494f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-win_amd64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 409bb41b807edc6d61c268488ed343b716a384dcf4a96b3f96f2f0b6f4d189b2
MD5 baf919636ebc60e1a381636c1c4767d6
BLAKE2b-256 274373208b31da6d71466dd608e4e14f61641b68346def763353b754428b249d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-musllinux_1_2_x86_64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bf3c5a4e388d320fb172bf4421e0609d131a7e761f8c07ce729de2ce336c9b80
MD5 4bb1fb4f6ab620a106b03935ca04ec39
BLAKE2b-256 ab3a14d0e08e8068b6cf0e46e79fab5433b6681bc511345be27f9540dfcc681a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-musllinux_1_2_aarch64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 98d5d04b94dae0ad7b5adddbc0165a11cff9eaf0e1b3089c5134f0e9234f89a9
MD5 97c38c189aa25a1ae18692a81ae4d70b
BLAKE2b-256 1365a088dc17e5ffa228f1b55082896c1990ef8e7b69e6fcd3220ad889312d4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ccc8889ac84a9df73b9f6d091b97f17468e1d510891fb6c4c753f6134b02b931
MD5 94fe940c281c1c8e402398d46bbaddcc
BLAKE2b-256 0b58d0ac7a21b211ec2fc74ae68e677925ecd3ada684759f0392fa5fc68305c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ftl_extract-0.11.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddc34687ffc0be34ba6c5c8ab86f9b54ea3d1b85d1fe82139cda9a549ab244d5
MD5 5df1c09cdb50bc068765dc4f37e10e66
BLAKE2b-256 aabc9756e2a680c2309bbaae8c142a0ec5e741e1cf8b6fb3587b275e5a6740a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0-py3-none-macosx_11_0_arm64.whl:

Publisher: pypi-release.yml on andrew000/FTL-Extract

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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