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.

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.

💁‍♂️ 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' \
  --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.0a1.tar.gz (38.2 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.0a1-py3-none-win_amd64.whl (2.0 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for ftl_extract-0.11.0a1.tar.gz
Algorithm Hash digest
SHA256 24600f6fc27a8c3cc81561a1b545c99e14c5743fa827cf75706f75f807a45230
MD5 b6ab2af53dd39aecfa82136d06d2dce5
BLAKE2b-256 6b3c6990e3c8f39d1811fbeec1e60ce1c4e2953d2a292bfea954d9138ab6da98

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1.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.0a1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6016af04f37798f06403688e6f25b135e9d84ff709202293fa1cb8c7ce5f4963
MD5 4f31cda58c37bff689d3afe752b95488
BLAKE2b-256 36ab4df9183b00ff1891503515d9ec0b860458f8d894b27a56e2c37a29d72e0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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.0a1-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ee0d3722158ba30c62f74adc8d6b90f75163a071044c0b60855c2810b03b9a5f
MD5 857bcb26179e9af414bb914de2ecac12
BLAKE2b-256 f4264b273ac516a302df9debd05813b53494097a79afe77342f20e15d7c4385a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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.0a1-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a83fd85a7e4c0682ceb0ee1acaafa13f73b86eb65c1403bf5adc490248a860fa
MD5 e9d46fc1310e7ad109d64577eac585b8
BLAKE2b-256 bd8d3728f9e7700360e1bf236af47fa8729316ebd892a5e70b874a3a747bf65a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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.0a1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97db7ffe6da1af5b39c49c35568e5c4372f0c409a1ecd9ed7545efde87658815
MD5 9f5b913383752f1ae2e6e611c3aa0b17
BLAKE2b-256 c5e852d961f0ce0a130da84053554b7cc43c6ca0b627f15db3621c038a2a535e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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.0a1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d891a79e7891650d7abd64a4e9fd6184cdd532392d5cd6c3c71d44e33ddc15dd
MD5 392fdeecb09b2525685c6201a96e0c66
BLAKE2b-256 0f50cf23d168db1552436b4eb95eaad74055a2135846a704e3125b38f0014831

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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.0a1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.11.0a1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac04d2fad4a6d3bbcd6d231e0178edeba9dbf8f2bf4e20ae36ee98e5565ba1cb
MD5 42549745b4de6959b94aec1ca589c175
BLAKE2b-256 22443c52fe35f3499e2963b6066190ae45a017bd0816a10439642f6dd30a3a65

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.11.0a1-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