-
Notifications
You must be signed in to change notification settings - Fork 320
Path Matcher
Available from 1.14.0
The path matcher provides a way to describe your directory structures, file naming and namespace mapping. It tells the extension how to handle your custom cases.
Some i18n frameworks require you to use some kind of name conversions. For example, in the VSCode extension, the message files have to be named like package.nls.ja-jp.json
. In this case, you need to tell the extension how to find the file's locale code.
"i18n-ally.pathMatcher": "package.nls.{locale}.json"
Note: if you are using i18n-ally for VSCode i18n, you don't need to do this. It's already setup out of the box.
Custom Namespaces Match
You can use path matcher to customize how namespaces are captured. You need to enable the namespace config first, for it to work.
"i18n-ally.namespace": true,
"i18n-ally.pathMatcher": "{locale}/{namespaces}.json"
Please check out the examples below.
The path matcher matches the relative path from your locale folder. File paths with no match will not be loaded.
Some common examples:
{locale}/{namespace}.{ext} # matches "zh-CN/attributes.yaml"
{namespaces}/{locale}.{ext} # matches "common/users/en-US.json"
{locale}.json # matches "fr-FR.json"
The following table lists some matchers you may want to use. {locale}
is required, while the others are optional.
Matcher | Description |
---|---|
{locale} |
Match the locale code, en-US zh-CN fr etc. |
{namespace} |
Match anything excludes folder separator / . It only matches one level of directories |
{namespaces} |
Match anything. It can match multiple levels of directories. The folder separator will be converted to . in keypath |
{ext} |
File extensions, based on current enabled parsers |
{locale?} |
Optional version of {locale} , if not locale captured, the current source language will be applied |
{namespace?} |
Optional version of {namespace}
|
{namespaces?} |
Optional version of {namespaces}
|
Directory structure:
i18n
βββ nl-NL
| βββ general
| | βββ ...
| βββ attributes
| | βββ foo.yaml
| βββ ...
βββ en
| βββ general
| | βββ ...
| βββ attributes
| | βββ foo.yaml
| βββ ...
// Path Matcher
'{locale}/{namespaces}.yaml'
// Example Path
'nl-NL/attributes/foo.yaml'
// Matched result
{ locale: 'nl-NL', namespace: 'attributes.foo' }
// Example usage
$t('attributes.foo.your-key')
Directory structure:
i18n
βββ general
| βββ nl.yaml
| βββ de.yaml
| βββ en.yaml
| βββ ...
βββ attributes
| βββ foo
| | βββ nl.yaml
| | βββ de.yaml
| | βββ en.yaml
| | βββ ...
| βββ bar
| | βββ ...
| βββ ...
βββ resources
| βββ ...
βββ ...
// Path Matcher
'{namespaces}/{locale}.yaml'
// Example Path
'attributes/bar/en.yaml'
// Matched result
{ locale: 'en', namespace: 'attributes.bar' }
// Example usage
$t('attributes.bar.your-key')
Lokalise is the fastest growing language cloud technology made by developers, for developers.
As a collaborative productivity platform, it helps structure and automate the translation and localization process for any company in the world.
Learn more
πβπ¨ Review & Collaborate
πͺ¨ Hard-coded Strings Extraction
βοΈ Configurations
π Migration