You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
63
63
64
-
```
64
+
```bash
65
65
./edit en
66
66
```
67
67
@@ -71,12 +71,32 @@ Windows, Unix systems and macOS are supported. For Windows, you'll need to call
71
71
72
72
Then access the site at `http://127.0.0.1:3000`.
73
73
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
+
74
81
7. Edit the tutorial
75
82
76
83
As you edit text files in the tutorial text repository (cloned at step 5),
77
84
the webpage will reload automatically.
78
85
79
86
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
+
80
100
# Change server language
81
101
82
102
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`.
85
105
86
106
E.g. if you cloned `ru` tutorial, it makes sense to use `ru` locale for the server as well:
87
107
88
-
```
108
+
```bash
89
109
cd /js/server
90
110
./edit ru ru
91
111
```
92
112
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 forthat languagein the code of the server, otherwise it exists with an error. As of now, `ru`, `en`, `zh`, `tr` and `ja` are fully supported.
94
114
95
-
# Dev mode
115
+
#Translating images
96
116
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 textin SVG pictures can be translated as well.
98
118
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.
100
124
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
101
132
```
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
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
+
| 你好世界
104
179
```
105
180
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:
107
182
108
183
```
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
109
232
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
111
234
```
112
235
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
+
113
242
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`.
114
243
115
244
Afterwards, call `./dev <server language>` to run the server:
116
245
117
-
```
246
+
```bash
118
247
cd /js/server
119
248
./dev en
120
249
```
@@ -127,17 +256,13 @@ Again, that's for developing the server code itself, not writing the tutorial.
127
256
128
257
# Troubleshooting
129
258
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
-
132
259
Please ensure you have Node.js version 10+ (`node -v` shows the version).
133
260
134
261
If it still doesn't work – [file an issue](https://github.com/javascript-tutorial/server/issues/new). Please mention OS and Node.js version.
135
262
136
263
Please pull the very latest git code and install latest NPM modules before publishing an issue.
137
264
138
-
## Known Issues
139
-
140
-
### For Linux users. inotify and monitored files
265
+
## Linux: inotify and monitored files
141
266
142
267
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.
0 commit comments