Skip to content

Commit 130b6c9

Browse files
committed
Merge branch 'master' of https://github.com/processing/p5.js-website into add-kaleidoscope-example
2 parents 884a350 + b635034 commit 130b6c9

28 files changed

+4538
-6720
lines changed

Gruntfile.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,28 @@ module.exports = function(grunt) {
244244
dest: '<%= config.dist %>/assets/reference'
245245
},
246246
reference_assets: {
247-
expand: true,
248-
cwd: '<%= config.src %>/templates/pages/reference/',
249-
src: ['**/!(*.hbs)'],
250-
dest: '<%= config.dist %>/reference/'
251-
},
252-
reference_es: {
253-
expand: true,
254-
cwd: '<%= config.dist %>/reference',
255-
src: ['**'],
256-
dest: '<%= config.dist %>/es/reference'
257-
},
258-
reference_zh_Hans: {
259-
expand: true,
260-
cwd: '<%= config.dist %>/reference',
261-
src: ['**'],
262-
dest: '<%= config.dist %>/zh-Hans/reference'
247+
files: (function() {
248+
const cp = [];
249+
pkg.languages.forEach(language => {
250+
if (language === 'en') {
251+
cp.push({
252+
expand: true,
253+
cwd: '<%= config.src %>/templates/pages/reference/',
254+
src: ['**/!(*.hbs)'],
255+
dest: '<%= config.dist %>/reference/'
256+
});
257+
} else {
258+
cp.push({
259+
expand: true,
260+
cwd: '<%= config.src %>/templates/pages/reference/',
261+
src: ['**/!(*.hbs)'],
262+
dest: `<%= config.dist %>/${language}/reference/`
263+
});
264+
}
265+
});
266+
267+
return cp;
268+
})()
263269
},
264270
offlineReference: {
265271
files: [
@@ -319,7 +325,7 @@ module.exports = function(grunt) {
319325
compress: {
320326
main: {
321327
options: {
322-
archive: '<%= config.dist %>/offline-reference/p5-reference.zip',
328+
archive: '<%= config.dist %>/offline-reference/p5-reference.zip'
323329
},
324330
expand: true,
325331
cwd: '<%= config.src %>/offline-reference',
@@ -331,14 +337,11 @@ module.exports = function(grunt) {
331337
all: {
332338
src: [
333339
'<%= config.dist %>/**/*.html',
334-
'!<%= config.dist %>/es/**/*.html',
335-
'!<%= config.dist %>/zh-Hans/**/*.html',
336340
'!<%= config.dist %>/**/CHANGES.html',
337341
'!<%= config.dist %>/**/README.html',
338342
'!<%= config.dist %>/**/p5_featured/**/*.html',
339343
'!<%= config.dist %>/**/learn/*.html',
340-
'!<%= config.dist %>/**/examples/*.html',
341-
'!<%= config.dist %>/reference/assets/index.html'
344+
'!<%= config.dist %>/**/examples/*.html'
342345
],
343346
options: {
344347
ignore: [

contributor_docs/i18n_contribution.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to p5.js website internationalization (i18n)
22

3-
If you want to contribute with p5.js website translations, you are in the right place. The translation of the p5.js website to languages other than English is part of its internationalization - abbreviated [*i18n*](https://en.wikipedia.org/wiki/Internationalization_and_localization) - process. You can improve content that has been already translated - at the reference, examples or other pages within the website - as well as start a new language translation.
3+
If you want to contribute with p5.js website translations, you are in the right place. The translation of the p5.js website to languages other than English is part of its internationalization - abbreviated [*i18n*](https://en.wikipedia.org/wiki/Internationalization_and_localization) - process. You can improve content that has been already translated - the reference, examples or other pages within the website - or start a new language translation.
44

55
## Table of Contents
66

@@ -9,32 +9,34 @@ If you want to contribute with p5.js website translations, you are in the right
99
* [Before submitting a Pull Request](#before-submitting-a-pull-request)
1010
* [File Structure](#file-structure)
1111
* [Start a new translation](#start-a-new-translation)
12-
* [Working on existing translations](working-on-existing-translations)
12+
* [Working on existing translations](#working-on-existing-translations)
1313
* [Translation of all pages except Reference and Examples](#translation-of-all-pages-except-reference-and-examples)
1414
* [Translation of Reference](#translation-of-reference)
1515
* [Translation of Examples](#translation-of-examples)
1616

1717
## How the website works
1818

19-
1. Due to internationalization (i18n), this website is built from templates that retrieve the text content from data files
19+
1. Due to internationalization (i18n), this website is built from templates that retrieve the text content from data files.
2020
2. There are three kind of pages and each works differently:
2121
* [Reference](#translation-of-reference): Pages are built in English and swapped to other languages using JS on the front-end. Translation content is stored in a JSON object.
2222
* [Examples](#translation-of-examples): Examples pages are built from templates with handlebars, while examples are stored in JS files.
23-
* [Other](#translation-of-all-pages-except-reference-and-examples): Pages are built from templates in which handlebars point to the content in the actual language when rendered.
23+
* [Other](#translation-of-all-pages-except-reference-and-examples): Pages are built from templates in which Handlebars point to the content in the actual language when rendered.
2424
3. Every time a modification is submitted the website is rendered again.
2525
4. Built web is stored under `dist/` directory whilst data and templates are stored under `src/` directory. For further information check the [File Structure](#file-structure).
26-
5. When collaborating code editing have to be done in files under `src/`, but not under `dist/` as files in there are removed and recreated on build.
26+
5. When contributing code, editing have to be done in files under `src/`, but not under `dist/` as files in there are removed and recreated on build.
2727

2828
## Setting up before start your contribution
2929

3030
*Please do this only once before you start your contribution.*
3131

3232
1. Install node.js by following the instructions [here](https://nodejs.org/en/download/).
3333
2. [Fork](https://help.github.com/articles/fork-a-repo/) the p5.js-website repository to your Github account. Click the *Fork* button on the upper-right side of the p5.js-website Github repo. This will automatically open your fork repo on Github.
34-
![processing/p5.js-website repository menu. At the right bottom of the menu the "fork" button is highlighted](https://github.com/processing/p5.js-website/raw/master/contributor_docs/assets/fork.png)
34+
35+
![processing/p5.js-website repository menu. At the right bottom of the menu the "fork" button is highlighted](https://github.com/processing/p5.js-website/raw/master/contributor_docs/assets/fork.png)
36+
3537
3. On your fork click the green *Clone or download* button. It will display a bar from where you can copy your `repo_URL`.
3638

37-
![processing/p5.js-website repository menu. The "Clone or download" button is pressed and a tab is displayed under it from which the repository's link can be copied.](https://github.com/processing/p5.js-website/raw/master/contributor_docs/assets/clone.png)
39+
![processing/p5.js-website repository menu. The "Clone or download" button is pressed and a tab is displayed under it from which the repository's link can be copied.](https://github.com/processing/p5.js-website/raw/master/contributor_docs/assets/clone.png)
3840

3941
4. Open your command-line interface (CLI) and [clone](https://help.github.com/articles/cloning-a-repository/) your fork of the p5.js-website repository to `your_directory` on your laptop by typing:
4042
```
@@ -96,7 +98,7 @@ If you want to contribute with p5.js website translations, you are in the right
9698
$ git push
9799
```
98100
99-
5. Commit to your repository at your github account and create a new [Pull Request](https://github.com/processing/p5.js-website/wiki/Pull-requests). Click the *Pull Reques* tab on your fork page and then click the green button *New Pull Request*.
101+
5. Commit to your repository at your github account and create a new [Pull Request](https://github.com/processing/p5.js-website/wiki/Pull-requests). Click the *Pull Request* tab on your fork page and then click the green button *New Pull Request*.
100102
![processing/p5.js-website repository menu. "Pull requests" tab is opened and a green button with the text "New pull request" is displayed a the right bottom of the menu.](https://raw.githubusercontent.com/processing/p5.js-website/master/contributor_docs/assets/pull_request.png)
101103
102104
## File Structure
@@ -116,11 +118,11 @@ p5.js-website/
116118
* `layouts/` – default.hbs is main page template.
117119
* `pages/` – Contains each of the pages of the p5 site, these get inserted in `{{> body }}` tag of default layout.
118120
* `partials/` – These are reusable pieces that can get added to any page or layout, they correspond to other `{{> filename }}` tags in the pages or default layout.
119-
* `Gruntfile.js` – This file contains all the tasks for using assemble and YAML to generate the final, static site. It uses the task runner [grunt](http://gruntjs.com/).
121+
* `Gruntfile.js` – This file contains all the tasks for using Assemble and YAML to generate the final, static site. It uses the task runner [grunt](http://gruntjs.com/).
120122
121123
## Start a new translation
122124
123-
1. Define an abbreviation for your language following the [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) standard. It's expected that abbreviations are two-letter, but for macro languages can be added extra extensions depending on each case.
125+
1. Define an abbreviation for your language following the [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) standard. It's expected that abbreviations are two-letter, but for macro languages extra extensions can be added according to [IETF/IANA language tag specification](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
124126
2. Open a new issue and propose the addition of the new language. If both the proposal and the abbreviation are approved proceed with the next step.
125127
3. Add an entry with the new language abbreviation at `package.json` to the `languages` category -located under the repository root directory. Please keep the language abbreviations in alphabetical order.
126128
@@ -135,22 +137,23 @@ p5.js-website/
135137
136138
4. Duplicate `en.yml` - stored under `src/data/` - and name it `language_abbreviation.yml`. For example, when the Spanish version was created it was named `es.yml`. Check [How the website works](#how-the-website-works) and [File Structure](#file-structure) for further information.
137139
5. Duplicate `es.json` - stored under `src/data/reference/` - and name it `[language_abbreviation].json`.
140+
6. Add a new menu entry in [`src/templates/partials/i18n.hbs`](https://github.com/processing/p5.js-website/blob/master/src/templates/partials/i18n.hbs#L8) like so `<li><a href='#' lang='[language_abbreviation]' data-lang='[language_abbreviation]'>[language_name]</a></li>`.
138141
139142
## Working on existing translations
140143
141144
### Translation of all pages except Reference and Examples
142145
143-
Each webpage is written in [.hbs](https://www.npmjs.com/package/hbs) format -files created with the library Handlebars and written using HTML rules- using handlers to access the i18n data of each language and render. Each handler binds a specific spot on the HTML script with a specific content stored in a database, and is replaced by it when the page is built. Hbs files are stored under `src/template/pages`.
146+
Each webpage is written in [.hbs](https://www.npmjs.com/package/handlebars) format: files created with the Handlebars library and written using HTML rules. It uses handlers to access the i18n data of each language and render them accordingly. Each handler binds a specific spot on the HTML document with a specific content stored in a file, and is replaced by it when the page is built. Hbs files are stored under `src/template/`.
144147
145-
The i18n data is stored in [.yml](https://en.wikipedia.org/wiki/YAML) files in the `src/data` folder of this repo. For example, under the above mentioned path the .yml files for English, Spanish and Chinese can be found as follows:
148+
The i18n data is stored in [.yml](https://en.wikipedia.org/wiki/YAML)(YAML) format in the `src/data` folder of this repo. For example, under the above mentioned path the .yml files for English, Spanish and Chinese can be found as follows:
146149
147150
```filenames
148151
en.yml
149152
es.yml
150153
zh-Hans.yml
151154
```
152155

153-
Within the .hbs pages there are tags that replace the actual content and look like this: `{{#i18n "MyKeyword"}}{{/i18n}}`. For example the *Download* tag at the main bar looks like this:
156+
Within the .hbs pages there are tags that replace the actual content and look like this: `{{#i18n "MyKeyword"}}{{/i18n}}`. For example the *Download* link at the main menu bar looks like this:
154157

155158
```html
156159
<li><a href="{{root}}/download/">{{#i18n "Download"}}{{/i18n}}</a></li>
@@ -172,31 +175,31 @@ In the example above, note that after the `download2` i18n tag there is still a
172175

173176
Each page contains YAML "front matter" at the top which includes a title and (optional) slug field. The title corresponds to the section in which to place the i18n key-value pairs. (Note: each page has only one title, so for partials within the `partials` folder, place the i18n pairs at the top level). The slug corresponds to the folder in which the page will be placed. This should generally match the folder structure within the `pages` folder.
174177

175-
For nested pages -for example `p5js.org/es/learn/color.html`- the slug of the .hbs document must match the upper folder, in this case `learn`. This is directly related with the way handlers are displayed in the .yml file. For example, all the handlers for the `learn` page are written under its slug with a tab as follows:
178+
For nested pages, for example `p5js.org/es/learn/color.html`, the slug of the .hbs document must match the upper folder, in this case `learn`. This is directly related with the way handlers are displayed in the .yml file. For example, all the handlers for the `learn` page are written under its slug with a tab as follows:
176179

177-
```javascript
180+
```yaml
178181
learn:
179182
learn-title: "Aprender"
180183
learn1: "Estos tutoriales proveen una revisión en mayor profundidad o paso a paso sobre temas particulares. Revisa la "
181184
```
182185
183186
But for nested pages it's important not to create a new slug for each page, because it can make the .hbs files not to find the handlers when calling the i18n data. So, for the page color **it is not needed to create a new** `slug: color/` like:
184187

185-
```javascript
188+
```yaml
186189
color:
187190
color-title: "Color"
188191
```
189192

190193
Instead of this, the color-related handler must be added to the `learn` list of handlers. For English version, the site will follow the same top-level hierarchy as the original site. When you switch to a different language, the permalink and file structure will include the language abbreviation immediately following the root url. (ex: `https://p5js.org/es/get-started/`)
191194

192-
**Yml files can break the page compilation** process under syntax issues as double quotes within the text. Each YAML handler must be written as `color-rgb-title: "Color RGB"`, which means that the handler `color-rgb-title` has assigned the content `"Color RGB"` in the current language .yml file.
195+
**YAML files can break the page compilation** process under syntax issues as double quotes within the text. Each YAML handler must be written as `color-rgb-title: "Color RGB"`, which means that the handler `color-rgb-title` has assigned the content `"Color RGB"` in the current language .yml file.
193196

194197
In some cases, the text translated from the original .hbs file (written in HTML) included double quotes used to highlight some idea. In those cases remember to use the scape command `\` before the quotes, otherwise your compiler will interpret it as a syntax error because the handlers finish more than one time.
195198

196199
### Translation of Reference
197200

198201
* The reference works a bit differently. The pages are built in English based on the inline documentation in the source code. They are then swapped out using JS on the front-end.
199-
* The top level keys in the JSON object correspond to the page headings, menu, footer, etc. You can see all the swaps in [this file](https://github.com/processing/p5.js-website/blob/master/dist/reference/index.html#L130).
202+
* The top level keys in the JSON object correspond to the page headings, menu, footer, etc. You can see all the swaps in [this file](https://github.com/processing/p5.js-website/blob/master/src/templates/pages/reference/index.hbs#L60).
200203
* The "p5" key in the JSON object contains individual keys for each reference entry, indexed by variable/function/object name.
201204
* Any entries in the JSON object which are not filled in will be left in English when the page is loaded.
202205
* This is a somewhat hacky solution and not ideal. However, it comes from balancing the desire to have documentation directly in the source code, with the unwieldiness of having multiple languages of documentation inline. It will be our working solution until a better one is found.

0 commit comments

Comments
 (0)