Skip to main content

Extracts FTL files from a directory and outputs them to a directory

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.0a3-py3-none-win_amd64.whl (1.7 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ftl_extract-0.9.0a3-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.0a3-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.0a3-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

ftl_extract-0.9.0a3-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.0a3-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 48e7dd131d30ba097022f30a620c6cc98a5d4298d6f9ccfc38971fc958b128bf
MD5 74022309208b90372cf9c126deb8b630
BLAKE2b-256 c688c42917e9c9b089653d8b1ea35d6fe2fc8d841e9d05c67124da006e977254

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 db5ca72f02bd75378fd986704dff104232494b3e27b51c957a1a291a9bf1029e
MD5 3c57ca9f9568c29e31251e511201c0da
BLAKE2b-256 d62ac8fd93d813e3314615a4c9c704c870b6e67f877c9fc756d5b6cc2d7389d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4fa831ea1d63b82832ebde41d7af79c8ff0d6c443806066ef86bf4c83fa2aab7
MD5 973da43a68a27a52c9ebb7eb306db6e6
BLAKE2b-256 cb36d30824a6e0072112a8c5049271090a3fcb62d8b04e415d51d8b78a272043

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f388410e6c00decac82c927e7095c42c719158a1f313a1bc38c15754848ced80
MD5 9427352c80b07c802bf3ac023ab163ac
BLAKE2b-256 b48337079575e2bcd60a74a74368e450cb20ed38b0a9694680b28f9d6361f1ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d6a8809a61680e5646201f3d50d8c88dd53cd9d1f8c353af0bbd1acb4d847beb
MD5 3efc088c37c92a4325b198efbde45b44
BLAKE2b-256 06ef85345169e9e51e69e515f1d8b0c0e81c2218bd0c35cf3ec5ac567dbf259e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23ecfa7dc43df0c9086069383e78b1fe1d97b5c95023d6846ed620a5da124932
MD5 e66a6b0e6f361294c1df560bf9805f1a
BLAKE2b-256 00a2ec296fa6a908e0f35ff7014917a0c781e715bf62cbee27c4ac74c90e7206

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a3-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 28ee72b9fa06e028c33139f7f40375ace95c30a2cd3a97c66e0ab8d088ac19fe
MD5 3ce6bac6c1260811158d80f3245b24ad
BLAKE2b-256 7bbc66cb4e70861dab468d333e98400279d952bf3ec8632504589afaeb9da7a9

See more details on using hashes here.

Provenance

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