Skip to content
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

Internationalisation: Fall back to specified language if translation is missing #3275

Open
4 tasks done
hamishwillee opened this issue Nov 30, 2023 · 8 comments
Open
4 tasks done
Labels

Comments

@hamishwillee
Copy link

Is your feature request related to a problem? Please describe.

The more pages you have the longer it takes to build a site. Adding each translation can very significantly increase the number of pages. If there is a fallback for missing translations then you only have to build the pages that are actually translated.

This also is better for users, as they see what is translated and what is not more clearly.

Describe the solution you'd like

I'd like to be able to specify a default language. If a page in any other language is not found, I'd like the system to fall back to the version in the default language, and only if that is missing fall back to 404.

Note that I don't want to use root as the default language. This is a common approach, but it doesn't work well for shared assets unless they are in "public", because the root will have a different relative path to these compared to translations.

Describe alternatives you've considered

No response

Additional context

Docsify does this, and some other systems.

Validations

@babakfp
Copy link

babakfp commented Dec 7, 2023

Just asking a question, is it possible right now to fall back to the default language (root)?

@hamishwillee
Copy link
Author

Just asking a question, is it possible right now to fall back to the default language (root)?

Not for me. I mean, falling back to root has bigger problems because it means you can't have shared images unless they are in public and are reference by an absolute URL. Using root as recommended by many SSG means you are pretty much forced to have separate images for every translation.

@babakfp
Copy link

babakfp commented Dec 9, 2023

Can you check this out if it does what you are asking for?

#3312

but it doesn't work well for shared assets unless they are in "public", because the root will have a different relative path to these compared to translations.

I don't know about this. I don't know how to test it. Let me know if it works or not. Thanks.

@hamishwillee
Copy link
Author

What you're proposing there is better than I asked for. In particular allowing each language to choose its own fallback means that you could have fallback to language variants - e.g. dialects. So this is excellent.

Note that I have not actually tested this patch. I tried - but I'm having trouble working out how get my own docs to build in the context of this repo (and modifying the existing docs to test this seems hard).

@hamishwillee
Copy link
Author

but it doesn't work well for shared assets unless they are in "public", because the root will have a different relative path to these compared to translations.

I don't know about this. I don't know how to test it. Let me know if it works or not. Thanks

Sorry, I have not been clear. I am not saying that there is a bug of any kind here in vitepress.

What I am saying is that I don't like the concept of using "root" as a fallback. I'll explain below but feel free to ignore - your PR looks great.

The "root" approach works fine if your images are in the same directory as your docs, because you just access them relative to the current document ![my image](myimage.jpg).
However with a big project and you don't want to localise the images then you are more likely to have the images in a shared folder. IN this case you access them by relative URL - e.g. ![my image](../../assets/myimage.jpg). That path ends up at a different location in "root" than in any translation.
So you end up being forced to either have the images in "public" so you can use an absolute URL, or duplicating the images for every translation).

@babakfp
Copy link

babakfp commented Dec 12, 2023

What you're proposing there is better than I asked for. In particular allowing each language to choose its own fallback means that you could have fallback to language variants - e.g. dialects. So this is excellent.

Note that I have not actually tested this patch. I tried - but I'm having trouble working out how get my own docs to build in the context of this repo (and modifying the existing docs to test this seems hard).

Thanks.

You can close the repo, fetch the changes. Open the project in your workspace in vsCode. pnpm i. pnpm run docs. Open the URL logged in the terminal. That's it. Add your locales config, etc same as how you do it in your project.

@babakfp
Copy link

babakfp commented Dec 12, 2023

The "root" approach works fine if your images are in the same directory as your docs, because you just access them relative to the current document ![my image](myimage.jpg). However with a big project and you don't want to localise the images then you are more likely to have the images in a shared folder. IN this case you access them by relative URL - e.g. ![my image](../../assets/myimage.jpg). That path ends up at a different location in "root" than in any translation. So you end up being forced to either have the images in "public" so you can use an absolute URL, or duplicating the images for every translation).

If I understood you correctly, use this https://vitepress.dev/guide/asset-handling#base-url.
No matter from what path/URL you are accessing the assets inside public, if you use the base URL, you can load the assets by the same path. Like /my-image.png.
🤔

@hamishwillee
Copy link
Author

That works if you're keeping all your assets in public. But there must be a reason why the docs recommend that instead "you can, and should, reference any assets using relative URLs"

@github-actions github-actions bot added the stale label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants