Skip to main content
๋ฒ„์ „: 3.3.2

i18n - ์†Œ๊ฐœ

It is easy to translate a Docusaurus website with its internationalization (i18n) support.

๋ชฉํ‘œโ€‹

It is important to understand the design decisions behind the Docusaurus i18n support.

For more context, you can read the initial RFC and PR.

i18n์˜ ๋ชฉํ‘œโ€‹

๋„ํ์‚ฌ์šฐ๋ฃจ์Šค i18n ์‹œ์Šคํ…œ์˜ ๋ชฉํ‘œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Simple: just put the translated files in the correct filesystem location
  • Flexible translation workflows: use Git (monorepo, forks, or submodules), SaaS software, FTP
  • Flexible deployment options: single, multiple domains, or hybrid
  • Modular: allow plugin authors to provide i18n support
  • Low-overhead runtime: documentation is mostly static and does not require heavy JS libraries or polyfills
  • Scalable build-times: allow building and deploying localized sites independently
  • Localize assets: an image of your site might contain text that should be translated
  • No coupling: not forced to use any SaaS, yet integrations are possible
  • Easy to use with Crowdin: a lot of Docusaurus v1 sites use Crowdin and should be able to migrate to v2
  • Good SEO defaults: we set useful SEO headers like hreflang for you
  • RTL support: locales reading right-to-left (Arabic, Hebrew, etc.) are supported and easy to implement
  • Default translations: classic theme labels are translated for you in many languages

i18n ์„ค๊ณ„ ์‹œ ๊ณ ๋ คํ•˜์ง€ ์•Š์€ ๋ถ€๋ถ„โ€‹

์•„๋ž˜ ํ•ญ๋ชฉ์€ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • Automatic locale detection: opinionated, and best done on the server (your hosting provider)
  • Translation SaaS software: you are responsible to understand the external tools of your choice
  • Translation of slugs: technically complicated, little SEO value

๋ฒˆ์—ญ ์ ˆ์ฐจโ€‹

๊ฐœ์š”โ€‹

๋ฒˆ์—ญํ•œ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ์›น ์‚ฌ์ดํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ์ ˆ์ฐจ๋ฅผ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

  1. Configure: declare the default locale and alternative locales in docusaurus.config.js
  2. Translate: put the translation files at the correct filesystem location
  3. Deploy: build and deploy your site using a single or multi-domain strategy

๋ฒˆ์—ญ ํŒŒ์ผโ€‹

์—ฌ๋Ÿฌ๋ถ„์€ 3๊ฐ€์ง€ ์ข…๋ฅ˜์˜ ๋ฒˆ์—ญ ํŒŒ์ผ ์ž‘์—…์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋งˆํฌ๋‹ค์šด ํŒŒ์ผโ€‹

์—ฌ๋Ÿฌ๋ถ„์˜ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ์›น ์‚ฌ์ดํŠธ์˜ ์ค‘์‹ฌ์ด ๋˜๋Š” ์ฝ˜ํ…์ธ ์ž…๋‹ˆ๋‹ค.

๋งˆํฌ๋‹ค์šด๊ณผ MDX ๋ฌธ์„œ๋Š” ๊ฐ ๋‹จ๋ฝ์„ ๊ฐœ๋ณ„์ ์ธ ๋ฌธ์ž์—ด๋กœ ์ž˜๋ผ์ฃผ๊ธด ํ•˜์ง€๋งŒ ์ „์ฒด ์ฝ˜ํ…์ธ ๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ชจ๋‘ ๋ฒˆ์—ญํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

JSON ํŒŒ์ผโ€‹

๋ฒˆ์—ญ ์‹œ ์‚ฌ์šฉํ•˜๋Š” JSON ํŒŒ์ผ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Your React code: standalone React pages in src/pages, or other components
  • Layout labels provided through themeConfig: navbar, footer
  • ํ”Œ๋Ÿฌ๊ทธ์ธ ์˜ต์…˜์„ ํ†ตํ•ด ์ œ๊ณต๋˜๋Š” ๋ ˆ์ด์•„์›ƒ ๋ผ๋ฒจ: ๋ฌธ์„œ ์‚ฌ์ด๋“œ๋ฐ” ์นดํ…Œ๊ณ ๋ฆฌ ๋ผ๋ฒจ, ๋ธ”๋กœ๊ทธ ์‚ฌ์ด๋“œ๋ฐ” ํƒ€์ดํ‹€ ๋“ฑ

The JSON format used is called Chrome i18n:

{
"myTranslationKey1": {
"message": "Translated message 1",
"description": "myTranslationKey1 is used on the homepage"
},
"myTranslationKey2": {
"message": "Translated message 2",
"description": "myTranslationKey2 is used on the FAQ page"
}
}

์•„๋ž˜ 2๊ฐ€์ง€ ์ด์œ ๋กœ ํ•ด๋‹น JSON ํ˜•์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ ํŒŒ์ผโ€‹

์ผ๋ถ€ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ์ „์ฒด์ ์œผ๋กœ ํ˜„์ง€ํ™”๋œ ์™ธ๋ถ€ ๋ฐ์ดํ„ฐ ํŒŒ์ผ์—์„œ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. For example, the blog plugin uses an authors.yml file that can be translated by creating a copy under i18n/[locale]/docusaurus-plugin-content-blog/authors.yml.

๋ฒˆ์—ญ ํŒŒ์ผ ์œ„์น˜โ€‹

๋ฒˆ์—ญ ํŒŒ์ผ์€ ์ ์ ˆํ•œ ํŒŒ์ผ์‹œ์Šคํ…œ ๊ฒฝ๋กœ์— ๋งŒ๋“ค์–ด์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Each locale and plugin has its own i18n subfolder:

website/i18n/[locale]/[pluginName]/...
์ฐธ๊ณ 

For multi-instance plugins, the path is website/i18n/[locale]/[pluginName]-[pluginId]/....

ํ”„๋ž‘์Šค์–ด๋กœ ๋ฒˆ์—ญ๋œ ๊ฐ„๋‹จํ•œ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ์‚ฌ์ดํŠธ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

website/i18n
โ””โ”€โ”€ fr
โ”œโ”€โ”€ code.json # ๋ฆฌ์•กํŠธ ์ฝ”๋“œ์— ์žˆ๋Š” ๋ชจ๋“  ํ…์ŠคํŠธ ๋ผ๋ฒจ
โ”‚ # ํ…Œ๋งˆ ์ฝ”๋“œ์˜ ํ…์ŠคํŠธ ๋ผ๋ฒจ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.
โ”œโ”€โ”€ docusaurus-plugin-content-blog # ๋ธ”๋กœ๊ทธ ํ”Œ๋Ÿฌ๊ทธ์ธ์— ํ•„์š”ํ•œ ๋ฒˆ์—ญ ๋ฐ์ดํ„ฐ
โ”‚ โ””โ”€โ”€ 2020-01-01-hello.md
โ”‚
โ”œโ”€โ”€ docusaurus-plugin-content-docs # ๋ฌธ์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ์— ํ•„์š”ํ•œ ๋ฒˆ์—ญ ๋ฐ์ดํ„ฐ
โ”‚ โ”œโ”€โ”€ current
โ”‚ โ”‚ โ”œโ”€โ”€ doc1.md
โ”‚ โ”‚ โ””โ”€โ”€ doc2.mdx
โ”‚ โ””โ”€โ”€ current.json
โ”‚
โ””โ”€โ”€ docusaurus-theme-classic # classic ํ…Œ๋งˆ์— ํ•„์š”ํ•œ ๋ฒˆ์—ญ ๋ฐ์ดํ„ฐ
โ”œโ”€โ”€ footer.json # ๋ฐ”๋‹ฅ๊ธ€ ํ…Œ๋งˆ ๊ตฌ์„ฑ์˜ ํ…์ŠคํŠธ ๋ผ๋ฒจ
โ””โ”€โ”€ navbar.json # ๋ฉ”๋‰ด๋ฐ” ํ…Œ๋งˆ ๊ตฌ์„ฑ์˜ ํ…์ŠคํŠธ ๋ผ๋ฒจ

The JSON files are initialized with the docusaurus write-translations CLI command. ๊ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ํ•ด๋‹น ํด๋”์—์„œ ์ž์ฒด ๋ฒˆ์—ญ ์ฝ˜ํ…์ธ ๋ฅผ ๊ฐ€์ ธ์˜ค๋ฉฐ, code.json ํŒŒ์ผ์€ ๋ฆฌ์•กํŠธ ์ฝ”๋“œ์— ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“  ํ…์ŠคํŠธ ๋ ˆ์ด๋ธ”์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

Each content plugin or theme is different, and defines its own translation files location: