-
Notifications
You must be signed in to change notification settings - Fork 241
i18n for guides #211
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 for guides #211
Conversation
Now there are two separate modules: one include general functions, another node-specific
…lugs and breadcrumbs
@simskij do you know how can we fix |
There is no really good way of doing this as vale uses unix globs and not regex, but I managed to come up with a hack that solves it for now at least: https://github.com/k6io/docs/blob/8901578e8ce155afc873d2660a3ede83e5d4d7fb/package.json#L20 Switch this command to instead run |
Deployed version: https://mdr-ci.staging.k6.io/docs/refs/pull/211/merge/es
Describe changes
This pull request adds setup for translating the
guides
section.For now language toggle is hidden and Spanish pages are hidden from algolia search, sitemap and sidebar.
How to add translations
For
.md
files:src/data/markdown/translated-guides/es
with the same relative path and file name as the english version (e.g. forgetting-started/installation
page we should have.../01 Getting Started/02 Installation.md
withing both.../translated-guides/en
and.../translated-guides/es
folders)title
to the Spanish title of the page. It would be used for generating localized slug, sidebar and SEO title.src/i18n/path-translations.js
contains Spanish translations for all folder names without leading numbers (e.g., to generate ES pages for files located in.../es/02 Using k6/
folder we need to translateUsing k6
key)For top-level
Guides
page:src/i18n/guides-translations.js
(Please note that now only Quickstart, Features and Use Cases sections support keys, will add the rest when the content is ready).How to enable all i18n logic
Open config file at
src/i18n/i18n-config.js
. There are 4 flags:disableRedirectToSelectedLanguage: false
to enable redirecting to translated version in selected languagehideEsFromAlgoliaSearch: false
to start sending ES content to Algolia for indexing and enable searching ithideLanguageToggle: false
to show language toggle on guides pages and remember language selected by userhideEsFromRobots: false
to removenoindex
from ES pagesHow it works
Translating md files
md
files for Guides section are moved tomarkdown/translated-guides
folder. They are now processed separately from other docs files. Insidemarkdown/translated-guides
there are separate folders for each language with the same file structure and naming inside. We need the same file and folder names to find corresponding translations for each page. For localizing URLs we usetitle
from frontmatter for file names andutils/path-translations.js
files for folder names. Accents and special characters are replaced with latin characters.Translating top-level guides page
Content for this page is translated using global context, that stores translations for each key (e.g. see
src/components/pages/doc-welcome/quickstart/quickstart.component.js
)Language toggle
Language toggle is located in the sidebar and is only visible on Guides pages. The selected language is saved to the localStorage. After user chooses a language, when they open a link that has a translation in selected language, they will be redirected to the translated version (e.g. user selected ES => user clicks of EN slug of a page that has ES translation => user will be redirected to ES version of the page).
Steps to test
npm i
npm start
http://localhost:8000/es
, then any other page from sidebar or breadcrumbs orguides
page.TODO
/en
prefix for english guides links