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.

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.10.0.tar.gz (33.3 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.10.0-py3-none-win_amd64.whl (1.9 MB view details)

Uploaded Python 3Windows x86-64

ftl_extract-0.10.0-py3-none-musllinux_1_2_x86_64.whl (1.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ftl_extract-0.10.0-py3-none-musllinux_1_2_aarch64.whl (1.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

ftl_extract-0.10.0-py3-none-manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

ftl_extract-0.10.0-py3-none-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: ftl_extract-0.10.0.tar.gz
  • Upload date:
  • Size: 33.3 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.10.0.tar.gz
Algorithm Hash digest
SHA256 b52494a527804da918253731ced88bee25cd0d8cede98d1ccc183c7988c638ae
MD5 c5a235958d7a67b0d13335d23400d761
BLAKE2b-256 d6d819051d51216202de8adbb9a001ecf59a9627953257bc424827168f055f33

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for ftl_extract-0.10.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a53b27ca75140ed043f5b6405e3960b6c769db228bcb63822fa67635ca26aec8
MD5 4ffc3c8c0ff4c6625ee749fd6d666d01
BLAKE2b-256 d2cbfcbc4c56948448bfa16ccee357c0783d85748b9dce9cf58a98176ccb375e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.10.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d1a283ecf4efe786f7180f60a46d5ec79d3570401a2b26a6e3ea92caf26ed47b
MD5 eadaa17460cdf97e2fbdf32601fe7a26
BLAKE2b-256 64c4abfae41f142f577499f0230d510d32cfb19ef05a217a48d3cc24704dac57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.10.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7ac31d84fef0a3b1b7f2738b22325bbae70f6f3c9c1ea419e30f4c07a257b32e
MD5 f12c646f55cc5b0952fb733a5aa535f6
BLAKE2b-256 5706865817511a196bac2cdd1856e63225ae8f535536255b72eb7473e2c0b48c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.10.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d48fdb337039abd66bf76ff6f0df132ac4bf4f31ca65357de22263f79193e55a
MD5 6f8841c7497eaf300f8459324f9b55ef
BLAKE2b-256 050f884968d1a0c3a0bcba20c764a60956a0a7e1af9406f82945cc9515c48564

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.10.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1a4098b32bd4d4ee88deaa4d666807b8514a4e6735c6b24aa2711d8c0ef6741a
MD5 c0d354852f6888f4908c734dd4dc4124
BLAKE2b-256 f8559212d3e21150caca009df6c0f6fddd2c53af6f52995c383d41b82ccb9f1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.10.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2719fd6e01ec3c9500fb0281d9145d4413c3ad0f104755e7a4582eec52d767d
MD5 a5d3ca5e54ff9badd9a96b1f7c8a70f2
BLAKE2b-256 71991587897f22c76ec10113c1901b6215d49d4158c2a12892fd500e246767b8

See more details on using hashes here.

Provenance

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