• Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Server for the Modern Javascript Tutorial

Tutorial Server

Hi everyone!

This is a standalone server for the javascript tutorial https://javascript.info.

You can use it to run the tutorial locally and translate it into your language.

Windows, Unix systems and macOS are supported. For Windows, you'll need to call scripts with ".cmd" extension, that are present in the code alongside with Unix versions.

Installation

  1. Install Git and Node.js.

    These are required to update and run the project. For Windows just download and install, otherwise use standard OS install tools (packages or whatever convenient).

    (Maybe later, optional) If you're going to change images, please install ImageMagick, use packages for Linux or homebrew/macports for MacOS.

  2. Install global Node modules:

    npm install -g bunyan gulp@4
  3. Create the root folder.

    Create a folder /js for the project.

    You can also use another directory as the root, then change the paths below: replace /js with your root.

  4. Clone the tutorial server into it:

    cd /js
    git clone https://github.com/javascript-tutorial/server
    git clone https://github.com/javascript-tutorial/engine server/modules/engine

    Please note, there are two clone commands. That's not a typo: modules/engine is cloned from another repository.

    And please don't forget when pulling an updated server code: modules/engine needs to be pulled too.

  5. Clone the tutorial text into it.

    The repository starts with the language code, e.g for the French version fr.javascript.info, for Russian – ru.javascript.info, for Chinese zh.javascript.info etc.

    The English version is en.javascript.info.

    The tutorial text repository should go into the repo subfolder, like this:

    cd /js/server/repo
    git clone https://github.com/javascript-tutorial/en.javascript.info
  6. Run the site

    Install local NPM modules:

    cd /js/server
    npm install

    Run the site with the ./edit command with the language argument. Above we cloned en tutorial, so:

    ./edit en

    This will import the tutorial from /js/server/repo/en.javascript.info and start the server.

    Wait a bit while it reads the tutorial from the disk and builds static assets.

    Then access the site at http://127.0.0.1:3000.

    To change the port, set the PORT environment variable:

    # Runs the server at http://127.0.0.1:8080
    PORT=8080 ./edit en

    For Windows, read the note about environment variables below.

  7. Edit the tutorial

    As you edit text files in the tutorial text repository (cloned at step 5), the webpage will reload automatically.

Windows: Environment variables

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:

cd /js/server
cross-env PORT=8080 ./edit en

In the examples below, the commands are without cross-env, prepend it please, if you're on Windows.

Alternatively, you can use other Windows-specific ways to set environment variables, such as a separate set PORT=8080 command.

Change server language

The server uses English by default for navigation and design.

You can set another language it with the second argument of edit.

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

cd /js/server
./edit ru ru

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, ko and ja are fully supported.

Translating images

Please don't translate SVG files manually.

They are auto-generated from the English variant, with the text phrases substituted from images.yml file in the repository root, such as https://github.com/javascript-tutorial/ru.javascript.info/blob/master/images.yml.

So you need to translate the content of images.yml and re-generate the SVGs using a script.

Here are the steps to translate images.

Step 1. Setup git upstream (if you haven't yet) and pull latest changes from English version:

cd /js/server/repo/zh.javascript.info # in the tutorial folder

git remote add upstream https://github.com/javascript-tutorial/en.javascript.info

git fetch upstream master

Step 2. Create images.yml with translations in the repository root.

An example of such file (in Russian): https://github.com/javascript-tutorial/ru.javascript.info/blob/master/images.yml

The file format is YAML.

Here's a quote:

code-style.svg:  # image file name
  "No space":    # English string
    text: "Без пробелов" # translation
    position: "center" # (optional) "center" or "right" - to position the translated string
  "between the function name and parentheses":
    position: "center"
    text: "между именем функции и скобками"

As you can see, for each image file there's a name (such as code-style.svg), and then goes the list of its English phrases (such as "No space"), accompanied by translations:

  • text is the translated text
  • position (not always needed, details will come soon) is the relative position of the text.

Initially, the file may be empty, then you can fill it with images one by one.

Only the mentioned images will be translated.

Step 3. Use the helper script to get a list of strings to translate:

The script is executed from the server root, like this:

# Adjust NODE_LANG to your language

❯ NODE_LANG=zh npm run gulp -- engine:koa:tutorial:imageYaml --image code-style.svg

Here's an example of its output:

code-style.svg:
  '2': ''
  No space: ''
  between the function name and parentheses: ''
  between the parentheses and the parameter: ''
  Indentation: ''
  2 spaces: ''
  'A space ': ''
  after for/if/while…: ''
  '} else { without a line break': ''
  Spaces around a nested call: ''
  An empty line: ''
  between logical blocks: ''
  Lines are not very long: ''
  A semicolon ;: ''
  is mandatory: ''
  Spaces: ''
  around operators: ''
  Curly brace {: ''
  on the same line, after a space: ''
  A space: ''
  between: ''
  arguments: ''
  A space between parameters: ''

As we can see, the script returns a text snippet that can be inserted into images.yml fully or partially.

E.g. like this:

code-style.svg:
  'A space ': 'Пробел'

Or like this, if we want to position the translation in the center (see below for more examples):

code-style.svg:
  'A space ':
    position: 'center'
    text: 'Пробел'

Step 4. Run the translation task:

cd /js/server # in the server folder

# adjust NODE_LANG to your language

NODE_LANG=zh npm run gulp -- engine:koa:tutorial:figuresTranslate

This script checks out all SVG images from upstream (English version) and replaces the strings inside them according to images.yml. So they become translated.

The new translated SVGs are the tutorial folder now, but not committed yet.

You can see them with git status.

Take a moment to open and check them, e.g. in Chrome browser, just to ensure that the translation looks good.

P.S. If an image appears untranslated on refresh, force the browser to "reload without cache" (hotkeys).

Step 5. Then you'll need to git add/commit/push the translated SVGs, as a part of the normal translation flow.

...And voilà! SVGs are translated!

Normally, the translation script looks for all images listed in images.yml. To translate a single image, use the --image parameter of the script:

# replace strings only in try-catch-flow.svg
NODE_LANG=zh npm run gulp -- engine:koa:tutorial:figuresTranslate --image try-catch-flow.svg

Read on for more advanced options and troubleshooting.

Positioning

For the positioning to work, sure you have installed ImageMagick mentioned in the installation step.

By default, the translated string replaces the original one, starting in exactly the same place of the image.

Before the translation:

| hello world

After the translation ( is at the same place where h was, the string is left-aligned):

| 你好世界

Sometimes that's not good, e.g. if the string needs to be centered, e.g. like this:

     |
hello world
     |

Here, the "hello world" is centered between two vertical lines |.

Then, if we just replace the string, it would become:

     |
你好世界
     |

As we can see, the new phrase is shorter. We should move it to the right a bit.

The position: "center" in images.yml does exactly that.

It centers the translated string, so that it will replace the original one and stay "in the middle" of the surrounding context.

Here's the text with position: "center", centered as it should be:

   |
你好世界
   |

The position: "right" makes sure that the translated string sticks to the same right edge:

hello world |
    你好世界 |

That's also useful for images when we expect the text to stick to the right.

The "overflowing text" problem

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.

If the translated text is much longer, please try to change it, make it shorter to fit.

If the translated text absolutely must be longer and doesn't fit, let me know, we'll see how to adjust the picture.

Troubleshooting images translation

If you add a translation to images.yml, but after running the script the SVG remains the same, so that the translation doesn't "catch up":

  1. Ensure that you have the latest server code and translation repos, fetched the upstream.
  2. Check if the English version has the file with the same name. The file could have been renamed.
  3. Check that there's only 1 file with the given name in the tutorial. Sometimes there may be duplicates.
  4. Check that the translated string in images.yml is exactly as in SVG: use the helper script (Step 3) to extract all strings.

If it still doesn't work – file an issue.

Dev mode

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.

First, run the command that imports (and caches) the tutorial:

cd /js/server
NODE_LANG=en npm run gulp engine:koa:tutorial:import

For Windows: npm i -g cross-env and prepend the call with cross-env to pass environment variables, like this:

cd /js/server
cross-env NODE_LANG=en...

Afterwards, call ./dev <server language> to run the server:

cd /js/server
./dev en

Running ./dev uses the tutorial that was imported and cached by the previous command.

It does not "watch" tutorial text, but it reloads the server after code changes.

Again, that's for developing the server code itself, not writing the tutorial.

Troubleshooting

Please ensure you have Node.js version 10+ (node -v shows the version).

If it still doesn't work – file an issue. Please mention OS and Node.js version.

Please pull the very latest git code and install latest NPM modules before publishing an issue.

Linux: inotify and monitored files

The server's tools use inotify by default on Linux to monitor directories for changes. In some cases there may be too many items to monitor.

! Samples code below work correctly for Ubuntu.

You can get your current inotify files watch limit by:

$> cat /proc/sys/fs/inotify/max_user_watches

When this limit is not enough to monitor all files, you have to increase the limit for the server to work properly.

You can set a new limit temporary by:

$> sudo sysctl fs.inotify.max_user_watches=524288
$> sudo sysctl -p

It is very important that you refer to the documentation for your operating system to change this parameter permanently.

--
Yours,
Ilya Kantor
[email protected]

More Repositories

1

en.javascript.info

Modern JavaScript Tutorial
HTML
23,433
star
2

zh.javascript.info

现代 JavaScript 教程(The Modern JavaScript Tutorial),以最新的 ECMAScript 规范为基准,通过简单但足够详细的内容,为你讲解从基础到高阶的 JavaScript 相关知识。
HTML
9,799
star
3

ru.javascript.info

Современный учебник JavaScript
HTML
3,808
star
4

ko.javascript.info

모던 JavaScript 튜토리얼(The Modern JavaScript Tutorial in Korean )
HTML
1,853
star
5

es.javascript.info

Spanish translation of javascript.info site.
HTML
555
star
6

ja.javascript.info

現代の JavaScript チュートリアル
HTML
408
star
7

tr.javascript.info

Modern JavaScript Tutorial in Turkish
HTML
347
star
8

uk.javascript.info

Modern JavaScript Tutorial in Ukrainian (JavaScript українською 🇺🇦)
HTML
330
star
9

pt.javascript.info

Tutorial de JavaScript Moderno em Português
HTML
224
star
10

fr.javascript.info

Modern JavaScript Tutorial
HTML
210
star
11

fa.javascript.info

Modern JavaScript Tutorial in Persian (Farsi)
HTML
200
star
12

id.javascript.info

Tutorial JavaScript Modern dalam Bahasa Indonesia
HTML
143
star
13

bn.javascript.info

Modern JavaScript Tutorial in Bengali
HTML
118
star
14

it.javascript.info

Modern JavaScript Tutorial in Italian
HTML
82
star
15

ar.javascript.info

Modern JavaScript Tutorial in Arabic
HTML
59
star
16

vi.javascript.info

Modern JavaScript Tutorial in Vietnamese
HTML
38
star
17

pl.javascript.info

Modern JavaScript Tutorial in Polish
HTML
38
star
18

zh-hant.javascript.info

Modern JavaScript Tutorial in Chinese Traditional
HTML
36
star
19

de.javascript.info

Modern JavaScript Tutorial in German
HTML
34
star
20

hi.javascript.info

Modern JavaScript Tutorial in Hindi
HTML
28
star
21

uz.javascript.info

Modern JavaScript Tutorial in Uzbek
HTML
28
star
22

ro.javascript.info

Modern JavaScript Tutorial in Romanian
HTML
27
star
23

az.javascript.info

Modern JavaScript Tutorial in Azerbaijani
HTML
24
star
24

engine

JavaScript
21
star
25

translate

Modern JavaScript Tutorial Translation
JavaScript
21
star
26

th.javascript.info

Modern JavaScript Thai Version
HTML
19
star
27

ka.javascript.info

Modern JavaScript Tutorial in Georgian
HTML
15
star
28

el.javascript.info

Modern JavaScript Tutorial in Greek (Μοντέρνο JavaScript Tutorial στα Ελληνικά)
HTML
10
star
29

bg.javascript.info

Modern JavaScript Tutorial in Bulgarian
HTML
10
star
30

hy.javascript.info

Modern JavaScript Tutorial in Armenian
HTML
9
star
31

ug.javascript.info

Modern JavaScript Tutorial in Uyghur
HTML
8
star
32

test.javascript.info

Modern JavaScript Tutorial in Test
HTML
7
star
33

kk.javascript.info

Modern JavaScript Tutorial in Kazakh
HTML
6
star
34

ta.javascript.info

Modern JavaScript Tutorial in Tamil
HTML
6
star
35

te.javascript.info

Modern JavaScript Tutorial in Telugu
HTML
6
star
36

ky.javascript.info

Modern JavaScript Tutorial in Kyrgyz
HTML
5
star
37

lt.javascript.info

Modern JavaScript Tutorial in Lithuanian
HTML
5
star
38

ca.javascript.info

Modern JavaScript Tutorial in Catalan
HTML
4
star
39

he.javascript.info

Modern JavaScript Tutorial in Hebrew
HTML
4
star
40

nl.javascript.info

Modern JavaScript Tutorial in Dutch
HTML
4
star
41

ms.javascript.info

Modern JavaScript Tutorial in Malay
HTML
3
star
42

pa.javascript.info

Modern JavaScript Tutorial in Punjabi
HTML
3
star
43

my.javascript.info

Modern JavaScript Tutorial in Burmese
HTML
3
star
44

hu.javascript.info

Modern JavaScript Tutorial in Hungarian
HTML
3
star
45

cs.javascript.info

Modern JavaScript Tutorial in Czech
HTML
3
star
46

sr.javascript.info

Modern JavaScript Tutorial in Serbian
HTML
3
star
47

sq.javascript.info

Modern JavaScript Tutorial in Albanian
HTML
2
star
48

tk.javascript.info

Modern JavaScript Tutorial in Turkmen
HTML
2
star
49

v2.javascript.info

Modern JavaScript Tutorial in v2
HTML
2
star
50

ml.javascript.info

Modern JavaScript Tutorial in Malayalam
HTML
2
star
51

project

Git Crash Course demo repository
HTML
2
star
52

hr.javascript.info

Modern JavaScript Tutorial in Croatian
HTML
2
star
53

km.javascript.info

Modern JavaScript Tutorial in Central Khmer
HTML
2
star
54

ku.javascript.info

Modern JavaScript Tutorial in Kurdish | فێرکاری مۆدێرن جاڤاسکڕێپت بە زمانی کوردی
HTML
2
star
55

fi.javascript.info

Modern JavaScript Tutorial in Finnish
HTML
1
star
56

bs.javascript.info

Modern JavaScript Tutorial in Bosnian
HTML
1
star
57

da.javascript.info

Modern JavaScript Tutorial in Danish
HTML
1
star
58

me.javascript.info

Savremen JavaScript tutorijal na crnogorskom jeziku !
HTML
1
star
59

ur.javascript.info

Modern JavaScript Tutorial in Urdu
HTML
1
star
60

sk.javascript.info

Modern JavaScript Tutorial in Slovak
HTML
1
star
61

si.javascript.info

Modern JavaScript Tutorial in Sinhala
HTML
1
star
62

pt-PT-old.javascript.info

Modern JavaScript Tutorial in Portuguese
HTML
1
star
63

ro-old.javascript.info

The translated version of https://github.com/iliakan/javascript-tutorial-en in Romanian.
HTML
1
star