-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d5d6e9
commit 4d7142c
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Extanding a locale | ||
|
||
The `inherits` config options under the `[package.metadata.leptos-i18n]` can allow you to describe inheritance hierarchy for your locales: | ||
|
||
```toml | ||
[package.metadata.leptos-i18n] | ||
default = "en" | ||
locales = ["en", "fr", "fr-CA"] | ||
inherits = { fr-CA = "fr" } | ||
``` | ||
|
||
This will default any missing keys in "fr-CA" to the value in "fr". | ||
|
||
The "general" default for missing keys will still be the default locale, so if a key is missing in both "fr" and "fr-CA", the key will use the value in "en". | ||
|
||
## Recursive inheritance | ||
|
||
You can have recursive inheritances, this is allowed and works as expected: | ||
|
||
```toml | ||
[package.metadata.leptos-i18n] | ||
default = "en" | ||
locales = ["en", "fr", "fr-CA", "fr-FR"] | ||
inherits = { fr-CA = "fr-FR", fr-FR = "fr" } | ||
``` | ||
|
||
> note: cyclic inheritance is also valid but I don't see the use, it's only supported because if we didn't detected cycles we could have an endless loop when resolving what default to use, if a cycle is encountered on a missing key the default locale is used. | ||
## Missing key warnings | ||
|
||
if locale A extend locale B, missing key warnings will not be emitted for locale A. | ||
|
||
Explicitly setting the inheritance to the default locale is also a way to suppress missing key warnings for a given locale: | ||
|
||
```toml | ||
[package.metadata.leptos-i18n] | ||
default = "en" | ||
locales = ["en", "fr", "it"] | ||
inherits = { it = "en" } | ||
``` | ||
|
||
While the above is technically already the default behavior, missing warnings will not be emitted for the "it" locale, but will be emitted for the "fr" locale. | ||
|
||
## Extends the default locale | ||
|
||
The default locale can not inherit. | ||
|
||
This is not allowed and will error: | ||
|
||
```toml | ||
[package.metadata.leptos-i18n] | ||
default = "en" | ||
locales = ["en", "fr"] | ||
inherits = { en = "fr" } | ||
``` |