i18nice
The i18nice preset supports i18nice and python-i18n, the library that i18nice forked.
Detection
The preset applies when pyproject.toml or requirements.txt has i18nice or python-i18n.
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: ['i18nice'],
})Locale files
The library has no default directory. If your config has no resources, the preset uses translations/{namespaces}.{locale}.{ext} and locales/{namespaces}.{locale}.{ext}. This is the default filename_format, {namespace}.{locale}.{format}. The file name and the folders under the directory are the namespace, so the key hi in translations/admin/foo.en.yml is admin.foo.hi. For another load_path or filename_format, set resources.
Resource transform
With the default skip_locale_root_data, a file starts with the locale code as its top-level key. The preset reads the messages under that key, in YAML and JSON files whose name ends with .{locale}.yml, .{locale}.yaml or .{locale}.json:
en:
hi: Hello %{name} !
mail:
one: You have a new mail.
many: '%{count} new mails.'This file has the keys foo.hi, foo.mail.one and foo.mail.many. When x18n writes a key, it writes it under the locale key of the file. A file without the locale key of its locale has no keys, so the preset does not support skip_locale_root_data.
Supported syntax
In .py files, the preset reads i18n.t('key') and t('key'):
import i18n
i18n.t('foo.hi', name='Bob')
i18n.t('foo.mail', count=2)A plural message is a key with the sub-keys zero, one, few and many. When a usage names the key, these sub-keys count as used.
Placeholders
Percent braces: %{name}.
Extraction templates
| Kinds | Template |
|---|---|
| any | i18n.t('{key}') |