-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fall back if translation is missing #3312
base: main
Are you sure you want to change the base?
Conversation
This is brilliant. The only thing that occurs to me is whether search needs to consider the fact that any "not found" topics should be taken from the fallback trees. |
I support this PR |
I'm also very interested in this being merged. I was just in the process of starting to localise a docs website and realised there's no good way to work around the language picker 404ing if the page doesn't exist in the other language. It could also help reuse sidebars/navbars. |
It seems that index pages in sub-folders are not working. When going to |
Thank you for letting me know. I fixed it in the recent commits. Feel free to check it out, it's ready for review. |
I support this PR |
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.