-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: support i18n #1339
Merged
Merged
feat: support i18n #1339
Conversation
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
fix: don't break when locales are not used fix: make navbar title link to current locale feat: allow customizing locale link in navbar feat: allow overriding theme config feat: support overriding head based on current locale feat: support customizing title and description feat: add lang attribute to html based on route feat: show current and available langs on navbar fix: refactor types to support locales fix: group label customization to theme.translations
brc-dd
force-pushed
the
feat/i18n-next
branch
from
September 14, 2022 13:25
ca1b2a2
to
ad8a368
Compare
kiaking
reviewed
Sep 15, 2022
kiaking
reviewed
Sep 15, 2022
This comment was marked as outdated.
This comment was marked as outdated.
brc-dd
force-pushed
the
feat/i18n-next
branch
from
September 16, 2022 06:10
c13b911
to
df14075
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Hiroki Okada <hirokio@tutanota.com>
any plan to merge this? |
@yyx990803 hope to see this as soon as possible |
We're working on it. Almost done. We're checking if this wouldn't break any ecosystem like Vue and Vite docs. Stay tuned! |
Finally! thank you! ❤️ |
@brc-dd Could you please add docs for |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Breaking Changes
Legacy i18n stuff is removed/replaced.
localePath
is removed fromuseData()
. One can have similar functionality usinglocaleIndex
orlang
property.For people using the default theme,
themeConfig.localeLinks
is removed in favor oflocales
.Change:
to:
There are internal changes in Algolia Search and Carbon Ads components.
Features
To use in-built i18n features, one need to create a file structure as following:
Then in
docs/.vitepress/config
:The following properties can be overridden for each locale (including root):
DefaultTheme.Config
type for details.Linked Issues
Todo
But track this separately as it needs modification in theme too.Test Algolia DocSearch'sfacetFilters
option (Help needed. I don't have an account to test that.)__ALGOLIA__
and__CARBON__
logic. (See notes below.)Allow overriding Algolia options based on locale.Support Algolia's i18n options.Likely there will be a mess in vue/theme because of types. Probably will have to keep theme configReverted.)any
by default, and typing it specifically in the default theme. Can also use module augmentation. Will take a look what's cleaner and require least change in other projects.I was going through VuePress' implementation, and I think some other things can be done or need testing:
Allow customizing text of containers at theme level?facetFilters
in-place to prevent re-initialization in case only the language has changed. But IG most of the projects will be changing other stuff likeplaceholder
/translations
too if they are using locales with Algolia. Not sure if this optimization will have any significant impact.)Notes
locales.root
is not required if there is no document at root level.This is a perfectly fine structure:
However, VitePress won't redirect
/
to/en/
by default. You'll need to configure your server for that. On Netlify, the configuration (docs/public/_redirects
) may look similar to this:Pro tip: If using the above approach, you can use
nf_lang
cookie to persist user's language choice. A very basic way to do this is register a watcher insidesetup
function of custom theme:For a complete example visit https://github.com/brc-dd/vite-docs (deployed at https://gleeful-rugelach-418cf0.netlify.app/). It's a test repo with combined Vite's docs.
For testing purposes you can use these changes by running
pnpm add -D vitepress@npm:@brc-dd/vitepress@next
Config file can now be stored at
docs/.vitepress/config/index.ts
too. It allows you to write separate config files for locales inside the same directory and export them from index. (example)Don't override
themeConfig.algolia
andthemeConfig.carbonAds
at locale-level. To use multilingual DocSearch, you can have some configuration like this:Click to expand
These options can be overridden. Refer Algolia's docs on what they do.
For RTL support, specify
dir: 'rtl'
in config and use some RTLCSS PostCSS plugin (https://github.com/MohammadYounes/rtlcss, https://github.com/vkalinichev/postcss-rtl, https://github.com/elchininet/postcss-rtlcss). You'll need to configure your PostCSS plugin to use:where([dir="ltr"])
and:where([dir="rtl"])
as prefixes to prevent CSS specificity issues.Changing locale to say
zh
will change the URL from/foo
(or/en/foo/
) to/zh/foo
. You can disable this behavior by settingthemeConfig.i18nRouting
tofalse
.