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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 fc9b9cef18cf32204d4cc4ad56cef8fbd3c566809915f5c376fa3c805458f604
MD5 cb52f2a6bb57e4cdf39be42dd35190bb
BLAKE2b-256 927f87827a88e1e7c66159d448e3b317d886b81a858d30827de005bd98913494

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80a62a09f9ae3337537037889f8c50d2c7ece9e81ced5e12e7a621fe3b3f7fcc
MD5 512d21aba2454cd6a7148a4392d74168
BLAKE2b-256 699f1050d07c564cb22ef927f7f50fe78f35c81d13a83a8e819f3087d248b71a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 781bfe7f644406542ef5b78954c0e8578a57bb6628fe2329c2567a5316a5eca7
MD5 8bba234a77729c43a383140abc5b6fa9
BLAKE2b-256 a43d8065f9cfaef30049aafaf89d9926e19005814232b0d528978654d9ab949a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 197cec9bbd4efd471583199b435a4393d0c8e5f2b830ec567f4b9dc5db642ba7
MD5 8968c0496ccdd60393b48e3d271d0688
BLAKE2b-256 1569514c17131856b4f62272752d1270732af3ba155a9bcaa6bb040c1b0e6380

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d2a06b24e6a3aea366a44b3b13c122205c4c1507f17359069d0f2daf0b96fcbb
MD5 31250f5d6ebbd36cabc8572520796def
BLAKE2b-256 7da4a072f4563f3bf3f5ec48b009d01bb26414d601ad0733c5b256215d476a30

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 69d8d6a804e1b51a19628e9c8a6eba6528e93c4332e95f4b1940ce6e90f338ab
MD5 9b23c43d63643928e7539c132d3a039b
BLAKE2b-256 efbf5b073f9ad714014fc7d2e3799cc5af2dffe6c5587f7c0dac5188df6c1a80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a7-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 65b17c32b85ea1ac8bb2488f8b5bb8545704c77cd408a4b065348156f5708c74
MD5 79fea39f09f7ebbfb96cadda7ceeabe0
BLAKE2b-256 7f00e9f7c05e07ae8d99b502e78659e58122738817eb19e2874d99f10082ca69

See more details on using hashes here.

Provenance

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