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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 94d426accc8093d3df5bd7976dd48b034d38a882f73a02fb115061fc4952e20f
MD5 71788e742c2db0768ffd68335709367b
BLAKE2b-256 10d0dc252b7e308addcd1d044291497e9fad88993d9222bbebc298b194bec697

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7f6cedff5e362d7154a3b025d5d426011980569cf677718049ccf4dff94fbb2b
MD5 d1035787dde774433eb73c0c66cd05bb
BLAKE2b-256 52d23b81e472efc5adaa1d968c959c89c5b1efb27f6697dd9f29b4e9f40fee7f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 17322a9eb8f637c57c6adb23548169fae533ebd39291740175bbccc9209eb13e
MD5 a49b816d4da3b1547a44c5e0fd04d0cf
BLAKE2b-256 4b3e36ba6cd85c7c64d3a32b15a048bdf70bf17f76f750f78b4a7c8d3d7c4bf6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5e035aebc7a681b24c48c5654940528fc29a273a1281c491a1515e2dc8a4cc82
MD5 71cfa14d6f2b342560ea2c1ed860267b
BLAKE2b-256 48e247ccca359da6c4653d4c52f88ea0a57d66d708b7d452b072fbbd4467078b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f6c1e7e839544f04e53f73e0e5a7bbbfe79a1a9d79858b7f27e0a83f81773482
MD5 870dddd330a02c4ea78d167feb5232bc
BLAKE2b-256 e2a6a329e9db56346fe6be9229decb53330d5850816941ad3e8703d9a54d8e28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aff3e812974df0fb2eedf70c8271e3d04cd82cb034e6ca3e287e002f9d61df52
MD5 c944564f123a1c5ebb34a5a2a9275a4d
BLAKE2b-256 9fb5084168609651a95511c8915278db689e0181951068d8ab54414611770ae4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ftl_extract-0.9.0a9-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 77ba159f582030fcd031945401d2f4e821fa5054add8d405ac6b66399e3970a9
MD5 a2ae39132f2db1be2914ac95c1e37b1c
BLAKE2b-256 0d5e0ed7c2fd9af134fb2efbefd5e4e073d4a1964c02b78cd7eb97f1316f9eee

See more details on using hashes here.

Provenance

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