Skip to content

Commit

Permalink
[website] Enable Translation & Localization (apache#2251)
Browse files Browse the repository at this point in the history
* [website] Enable Translation & Localization

*Motivation*

Docusaurus allows for easy translation functionality using [Crowdin](https://crowdin.com/).
Documentation files written in English are uploaded to Crowdin for translation by users within a community.

*Changes*

- Enable the integration with Crowdin.
- Adjust hyperlinks to include `language`.

Crowdin project: https://crowdin.com/project/apache-pulsar

* Add a statement about translations
  • Loading branch information
sijie authored Jul 31, 2018
1 parent c7436fe commit 7d8ee04
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ docker.debug-info
# Yarn

**/yarn.lock

# docusaurus

**/website/i18n/*
**/website/translated_docs*
4 changes: 4 additions & 0 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install yarn

# Install crowdin
RUN wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb
RUN dpkg -i crowdin.deb

# Install PIP and PDoc
RUN wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py
RUN pip install pdoc
Expand Down
49 changes: 49 additions & 0 deletions site2/crowdin.yaml
Original file line number Diff line number Diff line change
@@ -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-CN'
'zh-TW': 'zh-TW'
-
source: '/website/i18n/en.json'
translation: '/website/i18n/%locale%.json'
languages_mapping: *anchor
6 changes: 5 additions & 1 deletion site2/tools/docker-build-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ echo "---- Build Pulsar website using image $IMAGE"
CI_USER=$(id -u)
CI_GROUP=$(id -g)

# crowdin keys
CROWDIN_DOCUSAURUS_PROJECT_ID=${CROWDIN_DOCUSAURUS_PROJECT_ID:-apache-pulsar}
CROWDIN_DOCUSAURUS_API_KEY=${CROWDIN_DOCUSAURUS_API_KEY:-UNSET}

DOCKER_CMD="docker run -i -e CI_USER=$CI_USER -e CI_GROUP=$CI_GROUP -v $ROOT_DIR:/pulsar $IMAGE"

$DOCKER_CMD bash -l -c 'cd /pulsar/site2/website && yarn && yarn build && node ./scripts/replace.js && cp -R ./build/pulsar /pulsar/generated-site/content/staging'
$DOCKER_CMD bash -l -c 'cd /pulsar/site2/website && yarn && yarn run crowdin-upload && yarn run crowdin-download && yarn build && node ./scripts/replace.js && cp -R ./build/pulsar /pulsar/generated-site/content/staging'
181 changes: 181 additions & 0 deletions site2/website/languages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const languages = [
{
enabled: true,
name: 'English',
tag: 'en',
},
{
enabled: true,
name: '日本語',
tag: 'ja',
},
{
enabled: false,
name: 'العربية',
tag: 'ar',
},
{
enabled: false,
name: 'Bosanski',
tag: 'bs-BA',
},
{
enabled: false,
name: 'Català',
tag: 'ca',
},
{
enabled: false,
name: 'Čeština',
tag: 'cs',
},
{
enabled: false,
name: 'Dansk',
tag: 'da',
},
{
enabled: false,
name: 'Deutsch',
tag: 'de',
},
{
enabled: false,
name: 'Ελληνικά',
tag: 'el',
},
{
enabled: false,
name: 'Español',
tag: 'es-ES',
},
{
enabled: false,
name: 'فارسی',
tag: 'fa-IR',
},
{
enabled: false,
name: 'Suomi',
tag: 'fi',
},
{
enabled: false,
name: 'Français',
tag: 'fr',
},
{
enabled: false,
name: 'עִברִית',
tag: 'he',
},
{
enabled: false,
name: 'Magyar',
tag: 'hu',
},
{
enabled: false,
name: 'Bahasa Indonesia',
tag: 'id-ID',
},
{
enabled: false,
name: 'Italiano',
tag: 'it',
},
{
enabled: false,
name: 'Afrikaans',
tag: 'af',
},
{
enabled: false,
name: '한국어',
tag: 'ko',
},
{
enabled: false,
name: 'मराठी',
tag: 'mr-IN',
},
{
enabled: false,
name: 'Nederlands',
tag: 'nl',
},
{
enabled: false,
name: 'Norsk',
tag: 'no-NO',
},
{
enabled: false,
name: 'Polskie',
tag: 'pl',
},
{
enabled: false,
name: 'Português',
tag: 'pt-PT',
},
{
enabled: false,
name: 'Português (Brasil)',
tag: 'pt-BR',
},
{
enabled: false,
name: 'Română',
tag: 'ro',
},
{
enabled: false,
name: 'Русский',
tag: 'ru',
},
{
enabled: false,
name: 'Slovenský',
tag: 'sk-SK',
},
{
enabled: false,
name: 'Српски језик (Ћирилица)',
tag: 'sr',
},
{
enabled: false,
name: 'Svenska',
tag: 'sv-SE',
},
{
enabled: false,
name: 'Türkçe',
tag: 'tr',
},
{
enabled: false,
name: 'Українська',
tag: 'uk',
},
{
enabled: false,
name: 'Tiếng Việt',
tag: 'vi',
},
{
enabled: true,
name: '中文',
tag: 'zh-CN',
},
{enabled: false, name: '繁體中文', tag: 'zh-TW'},
];
module.exports = languages;
4 changes: 3 additions & 1 deletion site2/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"write-translations": "docusaurus-write-translations",
"version": "docusaurus-version",
"rename-version": "docusaurus-rename-version",
"test": "jest --detectOpenHandles"
"test": "jest --detectOpenHandles",
"crowdin-upload": "crowdin --config ../crowdin.yaml upload sources --auto-update -b master",
"crowdin-download": "crowdin --config ../crowdin.yaml download -b master"
},
"devDependencies": {
"axios": "^0.18.0",
Expand Down
22 changes: 0 additions & 22 deletions site2/website/pages/en/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const CWD = process.cwd();

const siteConfig = require(`${CWD}/siteConfig.js`);

function docUrl(doc, language) {
return siteConfig.baseUrl + 'docs/' + (language ? language + '/' : '') + doc;
}

class Contact extends React.Component {
render() {
let language = this.props.language || '';
Expand Down Expand Up @@ -41,24 +37,6 @@ class Contact extends React.Component {
}
]

const supportLinks = [
{
content: `Learn more using the [documentation on this site.](${docUrl(
'doc1.html',
language
)})`,
title: 'Browse Docs',
},
{
content: 'Ask questions about the documentation and project',
title: 'Join the community',
},
{
content: "Find out what's new with this project",
title: 'Stay up to date',
},
];

return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer documentContainer postContainer">
Expand Down
20 changes: 11 additions & 9 deletions site2/website/pages/en/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const GridBlock = CompLibrary.GridBlock;

const CWD = process.cwd();

const translate = require('../../server/translate.js').translate;

const siteConfig = require(`${CWD}/siteConfig.js`);
const releases = require(`${CWD}/releases.json`);

Expand Down Expand Up @@ -51,9 +53,9 @@ class Download extends React.Component {
<table className="versions" style={{width:'100%'}}>
<thead>
<tr>
<th>Release</th>
<th>Link</th>
<th>Crypto files</th>
<th><translate>Release</translate></th>
<th><translate>Link</translate></th>
<th><translate>Crypto files</translate></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -105,7 +107,7 @@ class Download extends React.Component {
<p>
Once you've downloaded a Pulsar release, instructions on getting up and running with a standalone cluster
that you can run on your laptop can be found in the{' '}
<a href={`${siteConfig.baseUrl}docs/standalone`}>Run Pulsar locally</a> tutorial.
<a href={`${siteConfig.baseUrl}docs/${this.props.language}/standalone`}>Run Pulsar locally</a> tutorial.
</p>
</div>
<p>
Expand All @@ -121,19 +123,19 @@ class Download extends React.Component {
</thead>
<tbody>
<tr key={'java'}>
<td><a href={'docs/client-libraries-java'}>The Pulsar java client</a></td>
<td><a href={`${siteConfig.baseUrl}docs/${this.props.language}/client-libraries-java`}>The Pulsar java client</a></td>
<td>The Pulsar java client</td>
</tr>
<tr key={'go'}>
<td><a href={'docs/client-libraries-go'}>The Pulsar go client</a></td>
<td><a href={`${siteConfig.baseUrl}docs/${this.props.language}/client-libraries-go`}>The Pulsar go client</a></td>
<td>The Pulsar go client</td>
</tr>
<tr key={'python'}>
<td><a href={'docs/client-libraries-python'}>The Pulsar python client</a></td>
<td><a href={`${siteConfig.baseUrl}docs/${this.props.language}/client-libraries-python`}>The Pulsar python client</a></td>
<td>The Pulsar python client</td>
</tr>
<tr key={'cpp'}>
<td><a href={'docs/client-libraries-cpp'}>The Pulsar C++ client</a></td>
<td><a href={`${siteConfig.baseUrl}docs/${this.props.language}/client-libraries-cpp`}>The Pulsar C++ client</a></td>
<td>The Pulsar C++ client</td>
</tr>
</tbody>
Expand Down Expand Up @@ -170,7 +172,7 @@ class Download extends React.Component {
<a href={`${info.srcArchiveUrl}.sha512`}>sha512</a>)
</td>
<td>
<a href={`${siteConfig.baseUrl}release-notes#${info.version}`}>Release Notes</a>
<a href={`${siteConfig.baseUrl}${this.props.language}/release-notes#${info.version}`}>Release Notes</a>
</td>
</tr>
)
Expand Down
Loading

0 comments on commit 7d8ee04

Please sign in to comment.