Skip to content

Commit 4b27324

Browse files
authored
Prepare site for translation (#364)
* Setup better redirects * Fix frontmatter script * Fix encoding issue in scripts * re-disable languages
1 parent 1549146 commit 4b27324

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+166
-89
lines changed

-debug.html

+3
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
{% include debug/todo.html content=page.content forceRender=true %}
1414
<hr>
1515
{% endfor %}
16+
17+
<h2>Redirects</h2>
18+
<pre><code>{% include_relative _redirects %}</code></pre>
1619
</div>

.gitignore

+4-68
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,8 @@ _site
44
.DS_Store
55
.idea
66

7-
af/
8-
ar/
9-
ca/
10-
cs/
11-
da/
12-
de/
13-
el/
14-
en/
15-
es-ES/
16-
fa-IR/
17-
fi/
18-
fr/
19-
he/
20-
hu/
21-
id-ID/
22-
it/
23-
ja/
24-
ko/
25-
mr-IN/
26-
nl/
27-
no-NO/
28-
pl/
29-
pt-BR/
30-
pt-PT/
31-
ro/
32-
ru/
33-
sk-SK/
34-
sr/
35-
sv-SE/
36-
tr/
37-
uk/
38-
vi/
39-
zh-Hans/
40-
zh-Hant/
7+
lang/*
8+
!lang/en/
419

42-
_data/i18n/af.yml
43-
_data/i18n/ar.yml
44-
_data/i18n/ca.yml
45-
_data/i18n/cs.yml
46-
_data/i18n/da.yml
47-
_data/i18n/de.yml
48-
_data/i18n/el.yml
49-
_data/i18n/en.yml
50-
_data/i18n/es-ES.yml
51-
_data/i18n/fa-IR.yml
52-
_data/i18n/fi.yml
53-
_data/i18n/fr.yml
54-
_data/i18n/he.yml
55-
_data/i18n/hu.yml
56-
_data/i18n/id-ID.yml
57-
_data/i18n/it.yml
58-
_data/i18n/ja.yml
59-
_data/i18n/ko.yml
60-
_data/i18n/mr-IN.yml
61-
_data/i18n/nl.yml
62-
_data/i18n/no-NO.yml
63-
_data/i18n/pl.yml
64-
_data/i18n/pt-BR.yml
65-
_data/i18n/pt-PT.yml
66-
_data/i18n/ro.yml
67-
_data/i18n/ru.yml
68-
_data/i18n/sk-SK.yml
69-
_data/i18n/sr.yml
70-
_data/i18n/sv-SE.yml
71-
_data/i18n/tr.yml
72-
_data/i18n/uk.yml
73-
_data/i18n/vi.yml
74-
_data/i18n/zh-Hans.yml
75-
_data/i18n/zh-Hant.yml
10+
_data/i18n/*.yml
11+
!_data/i18n/en.yml

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ build: test-jekyll
1616
@jekyll build
1717

1818
serve-production: test-jekyll
19+
@make crowdin-download
1920
@JEKYLL_ENV=production jekyll serve
2021

2122
build-production: test-jekyll
23+
@make crowdin-download
2224
@JEKYLL_ENV=production jekyll build
2325

24-
crowdin-sync: test-crowdin
26+
crowdin-upload: test-crowdin
2527
@crowdin-cli upload sources --auto-update -b master
28+
29+
crowdin-download: test-crowdin
2630
@crowdin-cli download -b master
31+
@ruby ./scripts/normalize-frontmatter.rb
32+
@ruby ./scripts/normalize-toc.rb
2733

2834
###
2935
# Misc stuff:

_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ redcarpet:
6464
extensions: [with_toc_data]
6565

6666
# Blog Settings
67-
permalink: /blog/:year/:month/:day/:title
67+
permalink: /blog/:year/:month/:day/:title/
6868
paginate: 1
6969

7070

_includes/debug/toc.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% include vars.html %}
2+
13
{% assign shouldRender = false %}
24

35
{% if jekyll.environment == "development" %}
@@ -8,7 +10,7 @@
810
{% assign shouldRender = true %}
911
{% endif %}
1012

11-
{% if shouldRender %}
13+
{% if shouldRender and vars_active_language.tag == 'en' %}
1214
{% assign lines = include.content | newline_to_br | strip_newlines | split: '<br />' %}
1315

1416
{% assign insideCodeBlock = false %}

_includes/navigation.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@
3636
{% include svg/language.svg class="navbar-icon" %}
3737
{{vars_active_language.name}}
3838
</a>
39-
<div class="dropdown-menu" aria-labelledby="dropdownNavLanguage">
39+
<div class="dropdown-menu" aria-labelledby="dropdownNavLanguage" id="dropdownNavLanguageMenu">
4040
{% for language in site.data.languages %}
4141
{% if language.enabled %}
42-
<a href="{{site.baseurl}}/{{language.tag}}/{{vars_url_relative}}"
43-
class="dropdown-item{% if vars_active_language.tag == language.tag %} active{% endif %}">
42+
<a href="{{site.baseurl}}/lang/{{language.tag}}/{{vars_url_relative}}"
43+
class="dropdown-item{% if vars_active_language.tag == language.tag %} active{% endif %}"
44+
data-lang="{{language.accept_languages[0]}}">
4445
{{language.name}}
4546
</a>
4647
{% endif %}

_includes/vars.html

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{% assign vars_url_parts = page.url | split: "/" | shift %}
2-
{% assign vars_url_language = vars_url_parts[0] %}
3-
{% assign vars_url_relative = vars_url_parts | shift | join: "/" | replace: ".html", "" %}
2+
{% assign vars_url_language = vars_url_parts[1] %}
3+
{% assign vars_url_relative = vars_url_parts | shift | shift | join: "/" | replace: ".html", "" %}
44
{% assign vars_temp_matched_languages = site.data.languages | where: "tag", vars_url_language %}
55
{% assign vars_active_language = vars_temp_matched_languages[0] %}
66
{% unless vars_active_language %}
77
{% assign vars_active_language = site.data.languages[0] %}
88
{% endunless %}
99
{% assign i18n = site.data.i18n[vars_active_language.tag] %}
10-
{% assign url_base = site.baseurl | append: "/" | append: vars_active_language.tag %}
10+
11+
{% if jekyll.environment == "development" %}
12+
{% assign url_base = site.baseurl | append: "/lang/" | append: vars_active_language.tag %}
13+
{% else %}
14+
{% assign url_base = site.baseurl %}
15+
{% endif %}

_layouts/default.html

+20
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,25 @@
4343
{% for script in page.scripts %}
4444
<script type="text/javascript" src="{{script}}"></script>
4545
{% endfor %}
46+
47+
{% if jekyll.environment == "production" %}
48+
<script>
49+
// Takes over language dropdown to set cookie
50+
var langMenu = document.getElementById('dropdownNavLanguageMenu');
51+
var langMenuItems = langMenu.getElementsByClassName('dropdown-item');
52+
53+
for (var i = 0; i < langMenuItems.length; i++) {
54+
var langMenuItem = langMenuItems[i];
55+
56+
langMenuItem.addEventListener('click', function(event) {
57+
event.preventDefault();
58+
var target = event.currentTarget;
59+
var lang = target.dataset.lang;
60+
document.cookie = 'nf_lang=' + lang;
61+
location.reload();
62+
});
63+
}
64+
</script>
65+
{% endif %}
4666
</body>
4767
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

_redirects

+36-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,44 @@ layout: null
1919
/latest-rc.deb https://github.com/yarnpkg/yarn/releases/download/v{{site.latest_rc_version}}/yarn_{{site.latest_rc_version}}_all.deb 302
2020
/latest-rc.rpm https://github.com/yarnpkg/yarn/releases/download/v{{site.latest_rc_version}}/yarn-{{site.latest_rc_version}}-1.noarch.rpm 302
2121

22-
/en / 302
22+
{% capture _redirects %}
2323

24-
{% for language in site.data.languages %}
25-
{% if language.enabled %}
26-
{% if language.tag != "en" %}
24+
{% assign urls_sorted = site.pages | map: "url" | sort %}
25+
{% assign urls_filtered = "" | split: "," | pop %}
26+
27+
{% for url in urls_sorted %}
28+
{% assign first_nine_chars = url | slice: 0, 9 %}
29+
{% if first_nine_chars == "/lang/en/" %}
30+
{% assign url_stripped = url | replace: "/lang/en/", "/" %}
31+
{% assign urls_filtered = urls_filtered | push: url_stripped %}
32+
{% endif %}
33+
{% endfor %}
34+
35+
{% assign redirects = "" | split: "," | pop %}
36+
37+
{% assign redirects = redirects | push: "# old /en/ url redirects" %}
38+
39+
{% for url in urls_filtered %}
40+
{% capture redirect %}/en{{url}} {{url}} 301{% endcapture %}
41+
{% assign redirects = redirects | push: redirect %}
42+
{% endfor %}
43+
44+
{% assign redirects = redirects | push: "" %}
45+
{% assign redirects = redirects | push: "# language redirects" %}
46+
47+
{% for url in urls_filtered %}
48+
{% for language in site.data.languages %}
49+
{% if language.enabled %}
2750
{% for accept_language in language.accept_languages %}
28-
/ /{{language.tag}} 302 Language={{accept_language}}
51+
{% capture redirect %}{{url}} /lang/{{language.tag}}{{url}} 200 Language={{accept_language}}{% endcapture %}
52+
{% assign redirects = redirects | push: redirect %}
2953
{% endfor %}
3054
{% endif %}
31-
32-
/{{language.tag}}/docs/install_ci /{{language.tag}}/docs/install-ci 302
33-
{% endif %}
55+
{% endfor %}
3456
{% endfor %}
57+
58+
{% capture newline %}
59+
{% endcapture %}
60+
61+
{% endcapture %}
62+
{{redirects | join: newline}}

crowdin.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ api_key_env: CROWDIN_API_KEY
33
base_path: .
44

55
files:
6-
- source: '/en/**/*'
7-
translation: '/%locale%/**/%original_file_name%'
6+
- source: '/lang/en/**/*'
7+
translation: '/lang/%locale%/**/%original_file_name%'
88
languages_mapping:
99
locale:
1010
af: af

index.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
---
2-
layout: pages/homepage
3-
redirect_from: /en/
2+
layout: null
43
---
4+
<!doctype html>
5+
<html>
6+
<head>
7+
<meta charset="utf-8">
8+
<title></title>
9+
</head>
10+
<body>
11+
<a href="lang/en/">Click here to see the site</a>
12+
</body>
13+
</html>

lang/en/compare.md

+3

lang/en/docs/index.md

+3

lang/en/docs/install-ci.md

+3

lang/en/docs/install.md

+3

lang/en/docs/nightly.md

+3

lang/en/users.md

+3

scripts/normalize-frontmatter.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sourceRegex = /^---\n.*?\n---/m
2+
targetRegex = /^\* \* \*\n.*?\n\* \* \*/m
3+
4+
langsDir = File.join('.', 'lang')
5+
langs = Dir.entries(langsDir).drop(2).reject {|lang| lang == 'en' }
6+
7+
# Build up a hashmap with all of the source front-matters
8+
# { relativePath => frontMatter }
9+
englishFiles = Dir.glob(File.join(langsDir, 'en', '**', '*.*'))
10+
english = {}
11+
englishFiles.each {|file|
12+
path = file.sub(File.join(langsDir, 'en'), '')
13+
contents = IO.read file
14+
result = contents.match sourceRegex
15+
english[path] = result
16+
}
17+
18+
# Go through every file in every language and replace the broken front-matter
19+
# with the source front-matter by relative path
20+
langs.each {|lang|
21+
files = Dir.glob(File.join(langsDir, lang, '**', '*.*'))
22+
files.each {|file|
23+
path = file.sub(File.join(langsDir, lang), '')
24+
contents = IO.read file
25+
replacement = english[path]
26+
if replacement
27+
result = contents
28+
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
29+
.gsub(targetRegex) {|c| replacement }
30+
File.write(file, result)
31+
end
32+
}
33+
}

scripts/normalize-toc.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sourceRegex = /\[\]\(#toc-(.*?)\)\{#toc-.*?\}/
2+
3+
langsDir = File.join('.', 'lang')
4+
langs = Dir.entries(langsDir).drop(2).reject {|lang| lang == 'en' }
5+
6+
langs.each {|lang|
7+
files = Dir.glob(File.join(langsDir, lang, '**', '*.*'))
8+
file = files[20]
9+
files.each {|file|
10+
contents = IO.read file
11+
result = contents
12+
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
13+
.gsub(sourceRegex, '<a class="toc" id="toc-\1" href="#toc-\1"></a>')
14+
File.write(file, result)
15+
}
16+
}

0 commit comments

Comments
 (0)