diff --git a/.gitignore b/.gitignore index c73e5ff7ed..aeedda9bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,10 @@ node_modules .DS_Store lib/core/metadata.js lib/core/MetadataBlog.js -yarn.lock +website/translated_docs +website/build/ +website/yarn.lock +website/node_modules + +website/i18n/* +!website/i18n/en.json diff --git a/README.md b/README.md index 2838a94466..9508f83203 100644 --- a/README.md +++ b/README.md @@ -196,5 +196,5 @@ DEPLOY_USER=deltice GIT_USER=test-site-bot CIRCLE_PROJECT_USERNAME=deltice CIRCL ## More Information -For details on how to set up translation support, read [here](/docs/en/translation.md). -For details on how to set up documentation search, read [here](/docs/en/search.md). +For details on how to set up translation support, read [here](/docs/en/guides-translation.md). +For details on how to set up documentation search, read [here](/docs/en/guides-search.md). diff --git a/crowdin.yaml b/crowdin.yaml new file mode 100644 index 0000000000..82017cd0f3 --- /dev/null +++ b/crowdin.yaml @@ -0,0 +1,49 @@ +project_identifier_env: CROWDIN_DOCUSAURUS_PROJECT_ID +api_key_env: CROWDIN_DOCUSAURUS_API_KEY +base_path: "./" +preserve_hierarchy: true + +files: + - + source: '/docs/*.md' + translation: '/website/translated_docs/%locale%/%original_file_name%' + languages_mapping: &anchor + locale: + 'af': 'af' + 'ar': 'ar' + 'bs-BA': 'bs-BA' + 'ca': 'ca' + 'cs': 'cs' + 'da': 'da' + 'de': 'de' + 'el': 'el' + 'es-ES': 'es-ES' + 'fa': 'fa-IR' + 'fi': 'fi' + 'fr': 'fr' + 'he': 'he' + 'hu': 'hu' + 'id': 'id-ID' + 'it': 'it' + 'ja': 'ja' + 'ko': 'ko' + 'mr': 'mr-IN' + 'nl': 'nl' + 'no': 'no-NO' + 'pl': 'pl' + 'pt-BR': 'pt-BR' + 'pt-PT': 'pt-PT' + 'ro': 'ro' + 'ru': 'ru' + 'sk': 'sk-SK' + 'sr': 'sr' + 'sv-SE': 'sv-SE' + 'tr': 'tr' + 'uk': 'uk' + 'vi': 'vi' + 'zh-CN': 'zh-Hans' + 'zh-TW': 'zh-Hant' + - + source: '/website/i18n/en.json' + translation: '/website/i18n/%locale%.json' + languages_mapping: *anchor diff --git a/docs/guides-translation.md b/docs/guides-translation.md index 9191c63e2a..b14830abd6 100644 --- a/docs/guides-translation.md +++ b/docs/guides-translation.md @@ -1,9 +1,9 @@ --- id: translation -title: Translations +title: Translations & Localization --- -Docusaurus allows for easy translation functionality using Crowdin. Documentation files written in English are uploaded to Crowdin for translation by users. Top-level pages written with English strings can be translated by wrapping any strings you want to translate in a `` tag. Other titles and labels will also be found and properly translated. +Docusaurus allows for easy translation functionality using Crowdin. Documentation files written in English are uploaded to Crowdin for translation by users within a community. Top-level pages written with English strings can be translated by wrapping any strings you want to translate in a `` tag. Other titles and labels will also be found and properly translated. ## Docusaurus Translation Configurations @@ -13,6 +13,12 @@ To generate example files for translations with Docusuaurus, run the `examples` npm run examples translations ``` +or + +``` +yarn examples translations +``` + This will create the following files: ``` @@ -21,19 +27,30 @@ languages.js crowdin.yaml ``` -The `pages/en/help-with-translations.js` file is the same example help page generated by the `examples` script but now using translations tags that are described below. +The `pages/en/help-with-translations.js` file includes the same starter help page generated by the `examples` script, but now includes translation tags. + The `languages.js` file tells Docusaurus what languages you want to enable for your site. -The `crowdin.yaml` file is used to configure crowdin integration, and is copied out one level into your project repo. -## Writing Pages to be Translated +The `crowdin.yaml` file is used to configure crowdin integration, and is copied up one level into your docusaurus project repo. If your docusaurus project resides in `/project/website`, then `crowdin.yaml` will be copied to `/project/crowdin.yaml`. -Any pages with text you want to be translated should go into the `website/pages/en` folder. Simply wrap any strings you want translated in a `` tag, and add the following `require` statement to the top of the file: +## Translating Your Existing Docs + +Your documentation files do not need to be changed or moved to support translations. They will be uploaded to Crowdin to be translated directly. + + +## Enabling Translations on Pages + +Pages allow you to customize layout and specific content of pages like a custom index page or help page. + +Pages with text that you want translated should be placed in `website/pages/en` folder. + +Wrap strings you want translated in a `` tag, and add the following `require` statement to the top of the file: ```jsx ... const translate = require("../../server/translate.js").translate; ...

- This is a Header I want translated + This header will be translated

... ``` @@ -45,10 +62,10 @@ You can also include an optional description attribute to give more context to a

``` -Documentation files do not need to be changed to support translations. They will be uploaded to Crowdin to be translated directly. - ## Gathering Strings to Translate +The strings within localized Pages must be extracted and provided to Crowdin. + Add the following script to your package.json file: ```json ... @@ -70,22 +87,47 @@ The script will include text from the following places: ## How Strings Get Translated -Docusaurus itself does not do any translation from one language to another. Instead, it uses [Crowdin](https://crowdin.com/) to manage translations and then downloads appropriately translated files from Crowdin. More information on how to set up Crowdin translations later. +Docusaurus itself does not do any translation from one language to another. Instead, it integrates [Crowdin](https://crowdin.com/) to upload translations and then downloads the appropriately translated files from Crowdin. ## How Docusaurus Uses String Translations -This section provides some more context for how translation works, but is not necessary information for the user to know. +This section provides context about how translations in Docusaurus works. -For things like the strings found in the headers and sidebars of pages, Docusaurus references a translated version of `i18n/en.json` (for example, a `i18n/fr.json` file downloaded from Crowdin). +### Strings -For documentation text itself, fully translated markdown files will be compiled in the same way English documentation markdown files would be. +A Docusaurus site has many strings used throughout it that require localization. However, maintaining a list of strings used through out a site can be laborious. Docusaurus simplies this by centralizing strings. -For other pages, Docusaurus will automatically transform all `` tags into function calls that will return appropriately translated strings. For each language that is enabled with `languages.js`, Docusaurus will build translated pages using the files in `pages/en` and the language's respective `.json` file in `i18n`. +The header navigation, for example can have links to 'Home' or your 'Blog'. This and other strings found in the headers and sidebars of pages are extracted and placed into `i18n/en.json`. When your files are translated, say into Spanish, a `i18n/fr.json` file will be downloaded from Crowdin. Then, when the Spanish pages are generated, Docusaurus will replace the English version of corresponding strings with translated strings from the corresponding localized strings file (e.g. In a Spanish enabled site 'Help' will become 'Ayuda'). -## Crowdin Set-Up +### Markdown Files + +For documentation files themselves, translated versions of these files are downloaded and then rendered through the proper layout template. + +### Other Pages + +For other pages, Docusaurus will automatically transform all `` tags it finds into function calls that return the translated strings from corresponding localized _`locale`_`.json`. + +## Crowdin Create your translation project on [Crowdin](https://www.crowdin.com/). You can use [Crowdin's guides](https://support.crowdin.com/translation-process-overview/) to learn more about the translations work flow. +### Manual File Sync + +You can add the following to your `package.json` to manually trigger crowdin. + +```json +"scripts": { + "crowdin-upload": "export CROWDIN_DOCUSAURUS_PROJECT_ID=$YOUR_CROWDIN_ID; export CROWDIN_DOCUSAURUS_API_KEY=$YOUR_CROWDIN_API_KEY; crowdin-cli --config ../crowdin.yaml upload sources --auto-update -b master", + "crowdin-download": "export CROWDIN_DOCUSAURUS_PROJECT_ID=$YOUR_CROWDIN_ID; export CROWDIN_DOCUSAURUS_API_KEY=$YOUR_CROWDIN_API_KEY; crowdin-cli --config ../crowdin.yaml download -b master" +}, +``` + +These commands require having an environment variable set with your crowdin project id and api key (`CROWDIN_PROJECT_ID`, `CROWDIN_API_KEY`). You can add them inline like above or add them permanently to your `.bashrc` or `.bash_profile`. + +If you run more than one localized Docusaurus project on your computer, you should change the name of the enviroment variables to something unique (`CROWDIN_DOCUSAURUS_PROJECT_ID`, `CROWDIN_DOCUSAURUS_API_KEY`). + +### Automated File Sync + To automatically get the translations for your files, update the `circle.yml` file in your project directory to include steps to upload English files to be translated and download translated files using the Crowdin CLI. Here is an example `circle.yml` file: ```yaml @@ -128,7 +170,11 @@ Now, Circle will help you automatically get translations prior to building your If you wish to use Crowdin on your machine locally, you can install the [Crowdin CLI tool](https://support.crowdin.com/cli-tool/) and run the same commands found in the `circle.yaml` file. The only difference is that you must set `project_identifier` and `api_key` values in the `crowdin.yaml` file since you will not have Circle environment variables set up. -## Translations and Versioning +## Versioned Translations + +TODO - This section needs to be fleshed out. + +OLD - If you wish to have translation and versioning for your documentation, add the following section to the end of your `crowdin.yaml` file: diff --git a/examples/basics/gitignore b/examples/basics/gitignore index 6ec0ff0cdd..aeedda9bfc 100644 --- a/examples/basics/gitignore +++ b/examples/basics/gitignore @@ -1,5 +1,11 @@ -.DS_Store node_modules -translated_docs -i18n -yarn.lock +.DS_Store +lib/core/metadata.js +lib/core/MetadataBlog.js +website/translated_docs +website/build/ +website/yarn.lock +website/node_modules + +website/i18n/* +!website/i18n/en.json diff --git a/examples/basics/siteConfig.js b/examples/basics/siteConfig.js index accc9e4abf..2f93a1713f 100644 --- a/examples/basics/siteConfig.js +++ b/examples/basics/siteConfig.js @@ -34,6 +34,8 @@ const siteConfig = { headerIcon: "img/docusaurus.svg", footerIcon: "img/docusaurus.svg", favicon: "img/favicon.png", + /* the name of your custom css file that resides in static/css/ */ + // customCssFileName: "custom.css", /* colors for website */ colors: { primaryColor: "#2E8555", diff --git a/examples/basics/static/css/custom.css b/examples/basics/static/css/custom.css new file mode 100644 index 0000000000..220c1dde7d --- /dev/null +++ b/examples/basics/static/css/custom.css @@ -0,0 +1,16 @@ +/* your custom css */ + +@media only screen and (min-device-width: 360px) and (max-device-width: 736px) { +} + +@media only screen and (min-width: 1024px) { +} + +@media only screen and (max-width: 1023px) { +} + +@media only screen and (min-width: 1400px) { +} + +@media only screen and (min-width: 1500px) { +} \ No newline at end of file diff --git a/examples/translations/crowdin.yaml b/examples/translations/crowdin.yaml index 13fe725384..82017cd0f3 100644 --- a/examples/translations/crowdin.yaml +++ b/examples/translations/crowdin.yaml @@ -1,11 +1,11 @@ -project_identifier_env: CROWDIN_PROJECT_ID -api_key_env: CROWDIN_API_KEY +project_identifier_env: CROWDIN_DOCUSAURUS_PROJECT_ID +api_key_env: CROWDIN_DOCUSAURUS_API_KEY base_path: "./" preserve_hierarchy: true files: - - source: '/docs/en/*.md' + source: '/docs/*.md' translation: '/website/translated_docs/%locale%/%original_file_name%' languages_mapping: &anchor locale: diff --git a/examples/translations/languages.js b/examples/translations/languages.js index 38f0752869..e3fae61a7a 100644 --- a/examples/translations/languages.js +++ b/examples/translations/languages.js @@ -1,14 +1,14 @@ const languages = [ - { - enabled: false, - name: "日本語", - tag: "ja" - }, { enabled: true, name: "English", tag: "en" }, + { + enabled: false, + name: "日本語", + tag: "ja" + }, { enabled: false, name: "العربية", diff --git a/lib/core/Head.js b/lib/core/Head.js index 983591e6b2..9135b29bd7 100644 --- a/lib/core/Head.js +++ b/lib/core/Head.js @@ -43,6 +43,11 @@ class Head extends React.Component { rel="stylesheet" href={this.props.config.baseUrl + "css/main.css"} /> + {this.props.config.customCssFileName && + }