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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

ftl_extract-0.9.0a8-py3-none-win_amd64.whl (1.7 MB view details)

Uploaded Python 3Windows x86-64

ftl_extract-0.9.0a8-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.0a8-py3-none-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ftl_extract-0.9.0a8-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ftl_extract-0.9.0a8-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

ftl_extract-0.9.0a8-py3-none-macosx_10_13_x86_64.whl (1.7 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

Details for the file ftl_extract-0.9.0a8-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 346be7a1d6106285d35a7873643545d412a2ab051608e762b87b6884a34beb62
MD5 d5b272d16452d6444e8b958bb9f1ea36
BLAKE2b-256 61fa1f78fce7523a357d385dc3a686013214911423d0a2da0dc5a27d15de47f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 871679c3930fefe3a12c2a3d0fba1205172546dd86a44ac9708d478f5d3beef6
MD5 82b6962e564c8e39ffbc3584eb05052e
BLAKE2b-256 6c4c6abe2a0f17dba8b477264ba9864a6e003a27756aeace67c0dc3df7047ff9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 91fbff23fb7b6cba04c0c1c6f45652cdd629e47068345430426a64c001999439
MD5 036ee969f8d38733e1fc7eeb6c9edcec
BLAKE2b-256 1e3f5944078322196a1e8c68514e4358148bb8f16d9e3028716a910d35b47e62

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.9.0a8-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.0a8-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f203a4d72f032a31663a48a72240082ab93be5f320338db15ee83a95c0b6e613
MD5 bf0c0c5c83f8aa72862f976c6c79ac7f
BLAKE2b-256 cb00d3853200211c7367cd623bf7ff988669a81313482bd664bb2ba50628df4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.9.0a8-py3-none-manylinux2014_x86_64.manylinux_2_17_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.0a8-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 6da6e5a711ccf1190e1e04a7512ee6118d607680f81d94a90b203baf09968e54
MD5 91aa20a547703023b6f9ba270d63d036
BLAKE2b-256 406b9a538e359b3466ebfea9e6ae71514f7baad366fc8c9cb5f371cdcbb16025

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.9.0a8-py3-none-manylinux2014_aarch64.manylinux_2_17_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.0a8-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0d2eb6448a423c76aeb49cd4f815b858152c5597d4bf330430c67609430f247
MD5 c8e542696d19066455a68948eb8c47ea
BLAKE2b-256 967baa544042b9bb5340141aedb22f6be0c7299d66cda27849ad96c5e918c0bc

See more details on using hashes here.

Provenance

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

File details

Details for the file ftl_extract-0.9.0a8-py3-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a8-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 be1b89ad5db84c844b2a910dad21d51788fd5f333487e5edd3733a8122a83a88
MD5 e7e966b5c2e813351a76d3c646263f75
BLAKE2b-256 4f6f91881ab61d3e7bb6014bbbcc7050c7c7756276908816ef72662241dce7e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ftl_extract-0.9.0a8-py3-none-macosx_10_13_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.

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