Skip to content

Commit cda6ff4

Browse files
committed
minor fixes
1 parent 988b6f3 commit cda6ff4

File tree

1 file changed

+62
-40
lines changed

1 file changed

+62
-40
lines changed

README.md

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -94,58 +94,47 @@ Please note, the server must support that language. There must be corresponding
9494
9595
# Translating images
9696
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.
9898
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 for that. It takes `images.yml` from the repository root, and then replaces strings in all svgs according to its content.
100100

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>.
102102

103103
The file format is "YAML", it's quite easy to understand:
104104
105105
```yaml
106106
code-style.svg: # image file name
107107
"No space": # English string
108108
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
110110
```
111111
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:
113113

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:
122-
```
123-
|
124-
hello world
125-
你好世界
126-
|
114+
```bash
115+
cd /js/zh.javascript.info
116+
git remote add upstream https://github.com/javascript-tutorial/en.javascript.info
117+
git fetch upstream master
127118
```
128119

129-
`position: "right"` makes sure that the translated string keeps the same right edge:
130-
```
131-
hello world |
132-
你好世界 |
120+
**Step 3.** Run the translation task:
121+
```bash
122+
cd /js/server
123+
# set NODE_LANG to your language
124+
NODE_LANG=zh glp engine:koa:tutorial:figuresTranslate
133125
```
134126

135-
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:
133+
> ```bash
134+
> # replace strings only in try-catch-flow.svg
135+
> NODE_LANG=zh glp engine:koa:tutorial:figuresTranslate --image try-catch-flow.svg
136+
> ```
136137
137-
1. Setup git upstream (if you haven't yet) and pull latest changes:
138-
```bash
139-
cd /js/zh.javascript.info
140-
git remote add upstream https://github.com/javascript-tutorial/en.javascript.info
141-
git fetch upstream master
142-
```
143-
2. Run the translation task:
144-
```bash
145-
cd /js/server
146-
# without --image it applies all translations (to all images)
147-
NODE_LANG=zh glp engine:koa:tutorial:figuresTranslate --image try-catch-flow.svg
148-
```
149138
150139
> For Windows: `npm i -g cross-env` and prepend the call with `cross-env` to pass environment variables, like this:
151140
>
@@ -154,13 +143,46 @@ After `images.yaml` with translations is ready, it's time to apply translations:
154143
> cross-env NODE_LANG=zh...
155144
> ```
156145
157-
The task takes upstream image version (English), replaces strings to it, then writes to same-named image in the tutorial repo.
158146
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).
160184

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
164186

165187
The task to get all strings from an image as YAML (for translation, to add to `images.yml`):
166188

0 commit comments

Comments
 (0)