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

i18n setup + example #230

Merged
merged 5 commits into from Oct 3, 2022
Merged

i18n setup + example #230

merged 5 commits into from Oct 3, 2022

Conversation

vonPB
Copy link
Member

@vonPB vonPB commented Oct 2, 2022

Starting point for the internationalisation.

How to add other languages

Add your locale in docusaurus.config.js

i18n: {
  defaultLocale: 'en',
  locales: ['en', 'de', '<LANG>'],
  
  localeConfigs: {
    en: {
	  label: 'English',
    },
    de: {
	  label: 'Deutsch',
    },
    <LANG>: {
	    label: '<LOCAL_NAME>'
    }
  },
},

Setup files

yarn run write-translations --locale <LANG>
this generates a folder ./i18n/<LANG>/ with the translation files.

code.json -> all texts that are wrapped in a <Translate> component can be edited here. Docusaurus also added a lot of standard translations for ui elements

docusaurus-theme-classic/navbar.json -> all texts visible in the navbar

docusaurus-theme-content-docs/current/ -> you can put .md files here
docusaurus-theme-content-docs/current.json-> titles of the auto generated sidebar entries

docusaurus-theme-content-blog/options.json -> blog translations

To translate, simply change the "message": <new_text> in the json files.

Add markdown files

all the files you want to translate have to be copied from ./docs/ to i18n/<LANG>/docusaurus-plugin-content-docs/current .
You could run cp -r docs/** i18n/<LANG>/docusaurus-plugin-content-docs/current to copy all files.

Run your dev server

Unfortunately you can only run one language at a time... Switching to another results in page not found

yarn run start --locale <LANG>
or
npm run start -- --locale <LANG>

Few notes

  • We can not use dynamic text with translations (see changes in src/pages/index.jsx)
  • static files (Images) will be served from http://localhost:3000/<LANG>/ instead of /
    • for images in the .jsx files we can do: require('@site/static/<FILE>').default instead
    • for images in markdown, just prepend ../ to the path for the "default" images or add your local image

@ChristianChiarulli
Copy link
Member

pls make against master

@vonPB vonPB changed the base branch from new-site to master October 3, 2022 00:47
@MAHcodes MAHcodes merged commit 6f4349f into LunarVim:master Oct 3, 2022
@vonPB vonPB deleted the i18n_setup branch October 3, 2022 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants