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.


🔥 Try fast-ftl-extract command.

It's Rust version of ftl extract command, that is 10-20 times faster than Python version.


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

$ fast-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.9.0a12.tar.gz (28.8 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.9.0a12-py3-none-win_amd64.whl (1.7 MB view details)

Uploaded Python 3Windows x86-64

ftl_extract-0.9.0a12-py3-none-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ftl_extract-0.9.0a12-py3-none-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ftl_extract-0.9.0a12-py3-none-manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

ftl_extract-0.9.0a12-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file ftl_extract-0.9.0a12.tar.gz.

File metadata

  • Download URL: ftl_extract-0.9.0a12.tar.gz
  • Upload date:
  • Size: 28.8 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.9.0a12.tar.gz
Algorithm Hash digest
SHA256 2d5be4d789cc21510a8d63daec51552799991e03574f9603c0b027cbe5976490
MD5 ab2f074e9397a5a1f803f9abca48570d
BLAKE2b-256 e7759021b42bd2fb3451fd450148e1ac1456280c10bfc447d2338a5a73dc4abc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 644c3909a7c7d71ad3d8473760789407c20fee4ac59e6ffc981d12409f6a7c99
MD5 cc7a3779f76cc8ba87d016f676d772ca
BLAKE2b-256 e3ae35c89a7792ce2f65211fb0baaad8eda2a0618699393207bfa0ff9737b2f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c97416fee6113af8618f89fdf65c5b2b3f3888133bc2146a9b6077b6a6fe80d2
MD5 bebfed62ab0e7dbae67b940b8163148d
BLAKE2b-256 341b9d19191c92b8b9498517bb2d66e1b337b336a29da8fa69adceeafd656a00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 43b5288a8e1a99cd47e345ebfdad76bdc9adf72528c47a65fb935ec0f281cf55
MD5 7ebdc6a12ef78319bce847e2f6c8fc1d
BLAKE2b-256 195814ab4e7265aa1dfa398a1b1104299adeb8b9314094b351345d40aa3f22ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 31aaaec8c2d41460e51a86a21873404447298dfc87a300a262f981944e7b0e78
MD5 a724fecd3678c21b95966acca4355fa7
BLAKE2b-256 61112f4ab9ed5baabbc6a7c466b07a57a112907f017a59c85f6dd6b511ecd8a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d16c3a72a217437a8b8aa4108184743429141af4c04de4440107a9d0209fda54
MD5 0bbee8d3c8544aa959b6dca15bb4f393
BLAKE2b-256 767fc236fc80e4342bd680050ba338c7d4ab36d226fde0d7cfb485ea75550f02

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a12-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8e294c470560d5187f71a3763b55e390ebb09a09eb9b8afc7ebbd9d14126473
MD5 1f2ca0373feb49d94c933c1daac53e52
BLAKE2b-256 2ddce14e32eb98ea07f31f45754f14625a03abb9afa7ef5bf69149a706fcf036

See more details on using hashes here.

Provenance

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