FTL-Extract is a Python package that extracts Fluent keys from .py files and generates .ftl file with extracted
keys.
The ftl CLI is implemented in Rust and ships as a native binary inside the Python wheel.
Use the package manager pip to install FTL-Extract.
$ pip install FTL-ExtractOr use modern tool like UV to install FTL-Extract.
$ uv add --dev FTL-ExtractFirst of all, you should create locales directory in your project.
$ mkdir project_path/localesThen, you can use the following command to extract keys from your code.
$ ftl extract project_path/code_path project_path/localesBy default, FTL-Extract will create a directory named en and put all keys into _default.ftl file.
You can also keep command defaults in pyproject.toml:
[tool.ftl-extract.extract]
code-path = "project_path/code_path"
output-path = "project_path/locales"
languages = ["en", "uk"]
i18n-keys-append = ["LF", "LazyProxy"]
ignore-attributes-append = ["core"]
exclude-dirs-append = ["./tests/*"]
ignore-kwargs = ["when"]
comment-junks = true
comment-keys-mode = "comment"
line-endings = "lf"
cache = true
[tool.ftl-extract.stub]
ftl-path = "project_path/locales/en"
output-path = "project_path/code_path/stub.pyi"
export-tree = false
[tool.ftl-extract.untranslated]
locales-path = "project_path/locales"
languages = ["uk"]
suggest-from = ["en"]
fail-on-untranslated = true
output = "reports/untranslated"
output-format = "json"Then run commands without repeating the configured paths:
$ ftl extract
$ ftl stub
$ ftl untranslatedBy default, ftl searches for pyproject.toml from the current directory upward. Use --config to select a specific
file:
$ ftl --config ./pyproject.toml extractCLI arguments override values from pyproject.toml; built-in defaults are used when neither is provided.
To print a ready-to-edit configuration sample, use:
$ ftl config sample
$ ftl config sample --command extractIn 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")$ ftl extract project_path/code_path project_path/localesproject_path/code_path- path to the project directory where the code is located.project_path/locales- path to the project directory where the.ftlfiles will be located.
-lor--language- add a new language to the project.-kor--i18n-keys- add additional i18n keys to the extractor.-Kor--i18n-keys-append- add additional i18n keys to the extractor and append them to the default list.-por--i18n-keys-prefix- add a prefix to the i18n keys. For example,self.i18n.<key>().-eor--exclude-dirs- exclude specific directories from the extraction process.-Eor--exclude-dirs-append- add more directories to exclude from the extraction process.-ior--ignore-attributes- ignore specific attributes of thei18n.*likei18n.set_locale.-Ior--append-ignore-attributes- add more attributes to ignore to the default list.--ignore-kwargs- ignore specific kwargs of the i18n_keys likewhen=...inaiogram_dialog.I18nFormat(..., when=...).--comment-junks- comments errored translations in the.ftlfile.--default-ftl-file- specify the default.ftlfile 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.-vor--verbose- print additional information about the process.--dry-run- run the command without making any changes to the files.--cache- cache extracted Python keys between runs and reuse them when source file metadata and extractor options are unchanged. By default, the cache is stored in.ftl-extract-cache/extract-<package-version>-v<schema-version>.bin.--cache-path- custom cache directory or file path. Directory paths store the cache asextract-<package-version>-v<schema-version>.bin. Passing this option enables the cache.--clear-cache- delete the existing extraction cache before running.
$ 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.ftlfiles located.project_path/code_path- path to the directory where thestub.pyiwill be located.
$ ftl untranslated project_path/localesproject_path/locales- path to the locales root directory that contains locale folders likeen,uk, etc.
-lor--language- check only selected locales. Can be passed multiple times.--suggest-from- locale(s) used to suggest non-placeholder translations for missing items. Can be passed multiple times.--fail-on-untranslated- return exit code1if untranslated keys are found.--output- optional output file path for batch processing reports. If no extension is provided,.txtor.jsonis appended automatically based on--output-format.--output-format- report file format:txtorjson(default:txt).
If a key is intentionally the same as its message id (for example, brand or domain terms like balance = balance), add a message comment marker above it:
# ftl-extract: ignore-untranslated
balance = balanceThis key will be skipped by ftl untranslated.
# Here we add 3 languages: English, Ukrainian and Polish
$ ftl extract project_path/code_path project_path/locales -l en -l uk -l pl# 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$ 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' \
--cache \
--verbosePull 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.