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
Copy file name to clipboardExpand all lines: README.md
+62-40Lines changed: 62 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,58 +94,47 @@ Please note, the server must support that language. There must be corresponding
94
94
95
95
# Translating images
96
96
97
-
Most pictures are in SVG format. Strings inside it are usually just text, they can be replaced.
97
+
The text in SVG pictures can be translated as well.
98
98
99
-
That's great, as there are many strings in English in images, like tips, notes, etc. They look nice when translated.
99
+
There's a special script forthat. It takes `images.yml` from the repository root, and then replaces stringsin all svgs according to its content.
100
100
101
-
Image translations reside in`images.yml`in the repository root, for example: <https://github.com/javascript-tutorial/ru.javascript.info/blob/master/images.yml>. Please, create it if needed.
101
+
**Step 1.** You should make `images.yml`with translations in the repository root, for example: <https://github.com/javascript-tutorial/ru.javascript.info/blob/master/images.yml>.
102
102
103
103
The file format is "YAML", it's quite easy to understand:
104
104
105
105
```yaml
106
106
code-style.svg: # image file name
107
107
"No space": # English string
108
108
text: "Без пробелов" # translation
109
-
position: "center" # (optional) "center" or "right" - to position translated string.
109
+
position: "center" # (optional) "center" or "right" - to position the translated string, details later
110
110
```
111
111
112
-
The translated string may become longer or shorter. By default, the translated string starts at the same place:
112
+
**Step 2.** Setup git upstream (if you haven't yet) and pull latest changes:
113
113
114
-
```
115
-
|hello world (before)
116
-
|你好世界 (after translation)
117
-
```
118
-
119
-
Sometimes they need to be repositioned:
120
-
121
-
`position: "center"` centers the translated string, good if you have a vertical diagram, keeps text centered:
After `images.yaml` with translations is ready, it's time to apply translations:
127
+
This script checks out all SVG images from `upstream` and replaces the strings according to `images.yml`.
128
+
129
+
**Step 4.** Then you'll need `git add/commit/push` the translated SVGs, as a part of the normal translation flow. You may want to open the translated SVGs directly in the browser to check them before doing so.
130
+
131
+
132
+
> The `--image` parameter allows to translate a single image:
> For Windows: `npm i -g cross-env` and prepend the call with `cross-env` to pass environment variables, like this:
151
140
>
@@ -154,13 +143,46 @@ After `images.yaml` with translations is ready, it's time to apply translations:
154
143
> cross-env NODE_LANG=zh...
155
144
> ```
156
145
157
-
The task takes upstream image version (English), replaces strings to it, then writes to same-named image in the tutorial repo.
158
146
159
-
You may want to open the resulting SVG file directly in the browser to see it.
147
+
## The "overflowing text" problem
148
+
149
+
The translated string may become longer than the original.
150
+
151
+
The replacement script only operates on strings, not other graphics, so a long translated string may not fit the picture.
152
+
153
+
If you'll notice that, you usually can adjust the translation to make it shorter. Besides, most pictures have some extra space for longer text, so a slight increase wouldn't harm.
154
+
155
+
If your translated text absolutely must be longer, let me know, I can adjust the picture.
156
+
157
+
## Positioning
158
+
159
+
160
+
By default, the translated string replaces the original one, in exactly the same place of the image:
161
+
162
+
```
163
+
| hello world (before)
164
+
| 你好世界 (after translation)
165
+
```
166
+
167
+
Sometimes that's not good, e.g. if the string needs to be centeredm e.g in a vertical diagram.
168
+
169
+
The `position: "center"`in`images.yml` centers the translated string:
170
+
```
171
+
|
172
+
hello world
173
+
你好世界
174
+
|
175
+
```
176
+
177
+
The `position: "right"` makes sure that the translated string sticks to the same right edge:
178
+
```
179
+
hello world |
180
+
你好世界 |
181
+
```
182
+
183
+
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/MacOS).
160
184
161
-
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/MacOS).
162
-
163
-
## Extract strings
185
+
## Helper script: extract strings
164
186
165
187
The task to get all strings from an image as YAML (for translation, to add to `images.yml`):
0 commit comments