-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
i18n no defaultLocale fallback handling for single-domain-deployment strategy #4723
Comments
Hi @TomPeirs This is something I actually plan to add, just wanted to see if someone come from a need for this and could help design the feature :) In my opinion, it make sense for most users to have the default/en locale to not have a baseurl prefix by default, as most users already have an English Docusaurus sites with existing URLs (not using So my idea was to allow configuring the baseUrl for each locale independently, but use convenient default for most users. For your use-case, as you don't want module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
localeConfigs: {
en: {
baseUrl: '/en/'
},
},
},
}; Now, Note Docusaurus can only build static assets, and so, only do client-side redirects using JavaScript.
Somehow, you could already solve your problem by running something like
Docusaurus can only build a folder of static files. It's not clear to me what exactly is a "fallback" for you and how we should built this technically (ie what should the Note: some popular server-side solutions like Github Pages are quite limited: it's not possible to perform a server-side redirect here for example. And if we build something, we definitively want this to work in all Jamstack hosting solutions, including Github Pages, or this would be confusing for many users. If you have a clear idea of what you want and think it is technically possible, I'd suggest creating a POC by hand-writing some html files and deploying those to Github Pages so that I understand better your suggestion In my opinion, the role of Docusaurus is only to build a folder of static assets. It is your responsibility to handle the rest, including configuring your host correctly for fallbacks/redirects, adding performant caching headers, rewrite URLs etc... We can only help by documenting this, but it's hard to be exhaustive |
Hey @slorber , Concerning
For my particular use-case not having anything at the root would be fine This results in the following
This is also a good idea. (I'll try it out this afternoon and update this ticket)
I agree, you are right. |
No it is not added yet, but will do that, as I planned to add it anyway
Temporarily you can pass a baseurl by using nodejs env variables in your config file:
And run this: BASE_URL='/en/' docusaurus build --locale en --out-dir build/en
BASE_URL='/it/' docusaurus build --locale it --out-dir build/it
BASE_URL='/de/' docusaurus build --locale de --out-dir build/de When using the |
Thank you, I had to slightly modify this to work with nodejs env variables. First I installed cross-env.
Then I modified the scripts: Without cross-env I couldn't get it to work. I realized setting nodejs environment variables is windows is different. Just leaving this here HOWEVER, the proposed solution actually does not work @slorber |
Yes, this is somehow expected, as the drop-down need to be able to know all
the localized urls 😅 you would also need to create your own drop-down of
hard-coded links for this to work (no navbar type + list of link items)
This is a temporary workaround, as my api proposal would solve this.
Le mar. 4 mai 2021 à 13:21, Tom Peirs ***@***.***> a écrit :
… Thank you, I had to slightly modify this to work with nodejs env variables.
First I installed cross-env.
"devDependencies": {
"cross-env": "^7.0.3"
}
Then I modified the scripts:
"build_german": "cross-env BASE_URL='/de/' docusaurus build --locale de
--out-dir build/de "
Without cross-env I couldn't get it to work. I realized setting nodejs
environment variables is windows is different.
Just leaving this here
HOWEVER, the proposed solution actually does not work @slorber
<https://github.com/slorber>
yes I do have /en part of the URL now, but switching languages is broken
The reason I think is because somehow the language switcher appends the
locale rather then switching it.
I show it in a video:
[image: 2021-05-04_13h20_25]
<https://user-images.githubusercontent.com/68061801/116996356-93a7e000-acdb-11eb-8dfd-b79325ebae74.gif>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4723 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFW6PV3RVBCXDXR5DGAVRDTL7KERANCNFSM44CEXYOQ>
.
|
oke thank you @slorber , In that case I will move away for this for a little bit. |
@slorber , Hence, for my use-case where I deploy to
Like this the localeDropdown is working as expected for me. |
Thanks I'll tell you when I have a version to test with these features Is your site open-source so that I can test on your site directly? |
It's not public, |
Not exactly the same, this issue is about i18n locale configuration, not docs version configuration (both should allow to configure the path) Still in my todo list, which unfortunately is quite long 😅 |
Hi, @slorber, i have create a pr #6731 for support this feature, I'm glad you could point it out for me if there's anything I've missed.
|
I think it is more intuitive to simply make
would output
would output |
I also have the issue to support external links to docusaurus v1 site: they all include '/en/', and no longer work in v2 :-(. Moreover, translators need to know that they have to add their languages in the urls because they don't see /en/ in them. |
This is so needed imo. Will be waiting for the feature release |
Is there an update regarding this issue? I would love to have this feature within docusaurus, or the option to configure a custom baseUrl would also be nice. |
I am also interested in this feature. |
🐛 Bug Report
There seems to be no fallback handling to the defaultLocale.
When I change with the localeDropdown to French (fr), my baseURL is appended with the locale. And will look like below
https://docusaurus.io/fr/docs/i18n/tutorial
However when I replace the french locale with my default locale (in my case: en) it will return a page not found.
http://localhost:3000/en/docs/intro
How can I make the defaultLocale accessible from the URL as the current 'strategy' is to strip the defaultlocale from the URL.
I think this is an important Bug because when starting to use Docusaurus V2 early we shipped some 'stable' URLs to production, and these URLs need to remain stable, meaning we have the locale always appended after the BaseURL. (also for default english).
What would be the suggestion?
(to me it seems odd I would need to use the multi domain strategy and start configuring CDNs just to get this working)
To Reproduce
i18n: { defaultLocale: 'en', locales: ['en', 'de'], },
npm run build
using the https://docusaurus.io/docs/i18n/tutorial#single-domain-deployment single domain deployment strategyExpected behavior
I would expect that the application is accessible with the default locale prefix in the URL.
Even better would be if you do not define the locale it all, that the application falls back to the defaultLocale if the document is available.
e.g.
https://docusaurus.io/it/docs/i18n/tutorial
should fall back tohttps://docusaurus.io/docs/i18n/tutorial
in case IT (Italian) is not defined as a locale.Actual Behavior
Currently you see a Page Not Found forward.
Your Environment
The text was updated successfully, but these errors were encountered: