Skip to content

Commit ee29ae7

Browse files
authored
Merge branch 'master' into tech_details_fswatches
2 parents 60696f3 + 68eb948 commit ee29ae7

File tree

33 files changed

+622
-97
lines changed

33 files changed

+622
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# OS or Editor folders
1313
.DS_Store
14+
.vscode
1415
.idea
1516
.cache
1617
.project

README.md

Lines changed: 151 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Windows, Unix systems and macOS are supported. For Windows, you'll need to call
1717

1818
Please use Node.js 10+.
1919

20-
(Maybe later, optional) If you're going to change images, please install [GraphicsMagick](http://www.graphicsmagick.org/).
20+
(Maybe later, optional) If you're going to change images, please install [ImageMagick](https://imagemagick.org/script/download.php).
2121

2222
2. Install global Node modules:
2323

24-
```
24+
```bash
2525
npm install -g bunyan gulp@4
2626
```
2727

@@ -31,7 +31,7 @@ Windows, Unix systems and macOS are supported. For Windows, you'll need to call
3131

3232
4. Clone the tutorial server into it:
3333

34-
```
34+
```bash
3535
cd /js
3636
git clone https://github.com/javascript-tutorial/server
3737
git clone https://github.com/javascript-tutorial/engine server/modules/engine
@@ -45,23 +45,23 @@ Windows, Unix systems and macOS are supported. For Windows, you'll need to call
4545
4646
The English version is `en.javascript.info`.
4747
48-
```
48+
```bash
4949
cd /js
5050
git clone https://github.com/javascript-tutorial/en.javascript.info
5151
```
5252
5353
6. Run the site
5454
55-
Install local modules:
55+
First, install local modules:
5656
57-
```
57+
```bash
5858
cd /js/server
5959
npm install
6060
```
6161
62-
Run the site with the same language. Above we cloned `en` tutorial, so:
62+
Run the site with the `./edit` command with the language argument. Above we cloned `en` tutorial, so:
6363
64-
```
64+
```bash
6565
./edit en
6666
```
6767
@@ -71,12 +71,32 @@ Windows, Unix systems and macOS are supported. For Windows, you'll need to call
7171
7272
Then access the site at `http://127.0.0.1:3000`.
7373
74+
> To change the port, set the `PORT` environment variable:
75+
> ```bash
76+
> # Runs the server at http://127.0.0.1:8080
77+
> PORT=8080 ./edit en
78+
> ```
79+
> For Windows, read the note about environment variables below.
80+
7481
7. Edit the tutorial
7582
7683
As you edit text files in the tutorial text repository (cloned at step 5),
7784
the webpage will reload automatically.
7885
7986
87+
# Windows: Environment variables
88+
89+
For Windows, to pass environment variables, such as `PORT`, you can install `npm i -g cross-env` and prepend calls with `cross-env`, like this:
90+
91+
```bash
92+
cd /js/server
93+
cross-env PORT=8080 ./edit en
94+
```
95+
96+
In the examples below, the commands are without `cross-env`, prepend it please, if you're on Windows.
97+
98+
Alternatively, you can use other Windows-specific ways to set environment variables, such as a separate `set PORT=8080` command.
99+
80100
# Change server language
81101

82102
The server uses English by default for navigation and design.
@@ -85,36 +105,145 @@ You can set another language it with the second argument of `edit`.
85105

86106
E.g. if you cloned `ru` tutorial, it makes sense to use `ru` locale for the server as well:
87107

88-
```
108+
```bash
89109
cd /js/server
90110
./edit ru ru
91111
```
92112

93-
Please note, the server must support that language. There must be corresponding locale files for that language in the code of the server, otherwise it exists with an error. As of now, `ru`, `en`, `zh` and `ja` are fully supported.
113+
Please note, the server must support that language. There must be corresponding locale files for that language in the code of the server, otherwise it exists with an error. As of now, `ru`, `en`, `zh`, `tr` and `ja` are fully supported.
94114

95-
# Dev mode
115+
# Translating images
96116

97-
If you'd like to edit the server code (assuming you're familiar with Node.js), *not* the tutorial text, then there are two steps to do.
117+
The text in SVG pictures can be translated as well.
98118

99-
First, run the command that imports (and caches) the tutorial:
119+
There's a special script for that. The translated strings should be in the `images.yml` file in the repository root, such as <https://github.com/javascript-tutorial/ru.javascript.info/blob/master/images.yml>. The script replaces strings in all svgs according to `images.yml`.
120+
121+
Here are the steps to translate images.
122+
123+
**Step 1.** Create `images.yml` with translations in the repository root.
100124
125+
The file format is "YAML", it's quite easy to understand:
126+
127+
```yaml
128+
code-style.svg: # image file name
129+
"No space": # English string
130+
text: "Без пробелов" # translation
131+
position: "center" # (optional) "center" or "right" - to position the translated string
101132
```
102-
cd /js/server
103-
NODE_LANG=en TUTORIAL_ROOT=/js/en.javascript.info npm run gulp engine:koa:tutorial:import
133+
134+
**Step 2.** Setup git upstream (if you haven't yet) and pull latest changes:
135+
136+
```bash
137+
cd /js/zh.javascript.info # in the tutorial folder
138+
git remote add upstream https://github.com/javascript-tutorial/en.javascript.info
139+
git fetch upstream master
140+
```
141+
142+
**Step 3.** Run the translation task:
143+
```bash
144+
cd /js/server # in the server folder
145+
# adjust NODE_LANG to your language
146+
NODE_LANG=zh npm run gulp -- engine:koa:tutorial:figuresTranslate
147+
```
148+
149+
This script checks out all SVG images from `upstream` and replaces the strings according to `images.yml`.
150+
151+
Now images in the tutorial folder are translated, but not committed yet.
152+
153+
**Step 4.** Then you'll need `git add/commit/push` the translated SVGs, as a part of the normal translation flow.
154+
155+
You may want to open the translated SVGs directly in the browser to take a look at them before committing. Just to make sure that the translation looks all right. If an image is untranslated on refresh, force the browser to "reload without cache" ([hotkeys](https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache#Bypassing_cache)).
156+
157+
158+
> To translate a single image, use the `--image` parameter of the script:
159+
> ```bash
160+
> # replace strings only in try-catch-flow.svg
161+
> NODE_LANG=zh npm run gulp -- engine:koa:tutorial:figuresTranslate --image try-catch-flow.svg
162+
> ```
163+
164+
165+
## Positioning
166+
167+
By default, the translated string replaces the original one, starting in exactly the same place of the image.
168+
169+
Before the translation:
170+
171+
```
172+
| hello world
173+
```
174+
175+
After the translation (`` is at the same place where `h` was, the string is left-aligned):
176+
177+
```
178+
| 你好世界
104179
```
105180

106-
For Windows: `npm i -g cross-env` and prepend the call with `cross-env` to pass environment variables, like this:
181+
Sometimes that's not good, e.g. if the string needs to be centered, e.g. like this:
107182
108183
```
184+
|
185+
hello world
186+
|
187+
```
188+
189+
(The "hello world" is centered between two `|`).
190+
191+
The `position: "center"` in `images.yml` centers the translated string, so that it will replace the original one and stay "in the middle" of the surrounding context:
192+
```
193+
|
194+
你好世界
195+
|
196+
```
197+
198+
The `position: "right"` makes sure that the translated string sticks to the same right edge:
199+
```
200+
hello world |
201+
你好世界 |
202+
```
203+
204+
P.S In order for positioning to work, you need to have ImageMagick installed: <https://imagemagick.org/script/download.php> (or use packages for Linux or homebrew/macports for MacOS).
205+
206+
## Helper script: extract strings
207+
208+
The task to get all strings from an image as YAML (for translation, to add to `images.yml`):
209+
210+
```bash
211+
cd /js/server
212+
NODE_LANG=zh npm run gulp engine:koa:tutorial:imageYaml --image hello.svg
213+
```
214+
215+
216+
## The "overflowing text" problem
217+
218+
The replacement script only operates on strings, not other graphics, so a long translated string may not fit the picture. Most pictures have some extra space for longer text, so a slight increase doesn't harm, but sometimes that happens.
219+
220+
Usually, you should adjust the translated text, make it shorter to fit.
221+
222+
If your translated string absolutely must be longer and doesn't fit, let me know, I can adjust the picture.
223+
224+
225+
# Dev mode
226+
227+
If you'd like to edit the server code (assuming you're familiar with Node.js), *not* the tutorial text, then there are two steps to do.
228+
229+
First, run the command that imports (and caches) the tutorial:
230+
231+
```bash
109232
cd /js/server
110-
cross-env NODE_LANG=en...
233+
NODE_LANG=en TUTORIAL_ROOT=/js/en.javascript.info npm run gulp engine:koa:tutorial:import
111234
```
112235
236+
> For Windows: `npm i -g cross-env` and prepend the call with `cross-env` to pass environment variables, like this:
237+
> ```bash
238+
> cd /js/server
239+
> cross-env NODE_LANG=en...
240+
> ```
241+
113242
In the code above, `NODE_LANG` sets server language, while `TUTORIAL_ROOT` is the full path to tutorial repo, by default is `/js/$NODE_LANG.javascript.info`.
114243
115244
Afterwards, call `./dev <server language>` to run the server:
116245
117-
```
246+
```bash
118247
cd /js/server
119248
./dev en
120249
```
@@ -127,17 +256,13 @@ Again, that's for developing the server code itself, not writing the tutorial.
127256

128257
# Troubleshooting
129258

130-
If you have a very old copy of the English tutorial, please rename `1-js/05-data-types/09-destructuring-assignment/1-destructuring-assignment` to `1-js/05-data-types/09-destructuring-assignment/1-destruct-user`.
131-
132259
Please ensure you have Node.js version 10+ (`node -v` shows the version).
133260

134261
If it still doesn't work – [file an issue](https://github.com/javascript-tutorial/server/issues/new). Please mention OS and Node.js version.
135262
136263
Please pull the very latest git code and install latest NPM modules before publishing an issue.
137264
138-
## Known Issues
139-
140-
### For Linux users. inotify and monitored files
265+
## Linux: inotify and monitored files
141266
142267
The server's tools use [inotify](https://en.wikipedia.org/wiki/Inotify) by default on Linux to monitor directories for changes. In some cases there may be too many items to monitor.
143268

@@ -158,9 +283,7 @@ $> sudo sysctl fs.inotify.max_user_watches=524288
158283
$> sudo sysctl -p
159284
```
160285

161-
It is very important that you refer to the documentation for your operating system to change this parameter permanently
286+
It is very important that you refer to the documentation for your operating system to change this parameter permanently.
287+
288+
--<br>Yours,<br>Ilya Kantor<br>iliakan@javascript.info
162289

163-
--
164-
Yours,
165-
Ilya Kantor
166-
iliakan@javascript.info

dev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
set -e
66

77
export NODE_LANG=$1
8+
export TUTORIAL_LANG=$1
89
export NODE_ENV=development
910
export ASSET_VERSIONING=query
1011
export WATCH=1
1112
export SITE_HOST=http://javascript.local
1213
export TUTORIAL_EDIT=
1314
export NODE_PRESERVE_SYMLINKS=1
1415

16+
# Use a local bunyan if no other is found in the current environment
17+
if ! [ -x "$(command -v bunyan)" ]; then
18+
export PATH="$PATH:./node_modules/bunyan/bin"
19+
fi
20+
1521
npm --silent run gulp dev | bunyan -o short -l debug
1622

edit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
export TUTORIAL_ROOT="../$1.javascript.info"
1010
export NODE_LANG="${2:-en}"
11+
export TUTORIAL_LANG=$1
1112
export NODE_ENV=production
1213
export TUTORIAL_EDIT=1
1314
export NODE_PRESERVE_SYMLINKS=1

edit.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
set NODE_LANG=%2
99
)
1010

11+
@set TUTORIAL_LANG=%1
1112
@set NODE_ENV=production
1213
@set TUTORIAL_EDIT=1
1314
@set ASSET_VERSIONING=query

0 commit comments

Comments
 (0)