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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1a498cc3173efc4435415428925ea925f8045d6ca6ae8fab4cee9b1fb1313ad5
MD5 4329070396aa2e86792627b0960d7c99
BLAKE2b-256 60ec10f6ca1f7677923f6a2359516d8285504ee5f3eec3f0caeb9dc32975066e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3eadd4648e4a73153f7bbb29f2a90cc3476ed7dc50eea6835f390185405d63b9
MD5 1ec75e0e5cbce1671419cb6c6076c503
BLAKE2b-256 de726fd0d42947ca8cd7eb98c54601eb55c5bd8d7ebb8ccc6b82184b88956913

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ead545130d426d03f2c2e3c8f19b76dc20d4656e952658b20d19fe10af42e2c6
MD5 e872a27b78d1eef3fa405138d35df630
BLAKE2b-256 befa1c15eac61e565eaa6494f84b743d98d9dd0d64b6bd1f20daf5c29bea9a37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1f39a25d60332177c14a32241a2f2d2008a5b78212afb254b2b85d0f590e06ef
MD5 e6128397a32ec60b6a0f5d15bffcfcb6
BLAKE2b-256 61a1419b8684105a8aa1cb1c283db637dc15f3ca87b6b5fe29a0345a05e40c7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 27c1e496e2e983033f673deca9ec8181af2acac6a83ae6dd334c2c8875554ebf
MD5 aef3227724c422a1dad65307a8c280b1
BLAKE2b-256 5a6dd7581b5c477006ada0104d1ec5a4aa85926dc39aa6013ccac1c65cd97ac8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 310a8198689f7f9315b3235831ae1af0191d3f856187341d9761380e4069ae53
MD5 f5d42247b770f72b507160d7e1f281a1
BLAKE2b-256 b469673df0285760d6aaf81c7088e50de9d71ea6e19ead55a8e26a3bffb3f751

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a2-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6d5438e51eb9554948636f7afadb59dcfa94f527f40d0dc3c899a2c90e29f304
MD5 336ce2531fed8c582cfeaeb50b253e11
BLAKE2b-256 2605b93071ac9b2310f9e0bc67f3fdbe3e2423806fd49c86447a5ccd235d5149

See more details on using hashes here.

Provenance

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