feat: fall back if translation is missing #3312
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR helps to fall back to a different locale if a page in the current locale is missing. This feature can be enabled by setting the
localesFallback
option totrue
. All locales will fall back to the default locale (root), which can be changed by using thelocalesDefaultFallback
option (and setting the value to the key of a locale). Thefallback
option is available for each locale to have its custom locale to fall back to.Example 1
/fa/a
was not found, fall back to/a
./a
was not found, show404
.root
is the default locale to fall back to.localesFallback
option was set tofalse
, things would continue to work like this PR never happened.Example 2
You can set a custom locale to fall back to for each locale.
/fa/a
was not found, fall back to/en/a
./en/a
was not found, show404
.root
can have itsfallback
option too.Example 3
Change the default locale that all locales can fall back to.
/fa/a
was not found, fall back to/en/a
./en/a
was not found, show404
.Example 4
/fa/a
was not found, fall back to/tr/a
./tr/a
was not found, fall back to/en/a
./en/a
was not found, show404
.Helpful errors
fallback
option was set to'root'
, you will get an error, because it's the default value and there is no reason to do it.fallback
option was set to its locale key, you will get an error, because this will create a loop.fallback
option was set to a locale key that didn't exist, you will get an error, because, I guess if you have a locale, it should be configured in VitePress Config too.I fixed the issue reported here.