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.
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.
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")$ 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.
$ 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.
# 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$ 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' \
--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.