-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
i18n.js
66 lines (61 loc) · 1.83 KB
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { supportedLanguages } from './../../i18n';
// This is kind of a mess for some languages.
// Try to be as short as possible.
// Make sure you use a real code (e.g. "ja", not "jp").
// Some resources:
// http://www.rfc-editor.org/rfc/bcp/bcp47.txt
// https://www.w3.org/International/articles/language-tags/
// https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
// https://discuss.httparchive.org/t/what-are-the-invalid-uses-of-the-lang-attribute/1022
export const codeToLanguage = code =>
supportedLanguages[code].replace(/ /g, ' ' /* nbsp */);
export const loadFontsForCode = code => {
switch (code) {
case 'ru':
case 'bg':
import('../fonts/fonts-shared.cyrillic.css');
import('../fonts/fonts-post.cyrillic.css');
break;
case 'uk':
import('../fonts/fonts-shared.cyrillic.css');
import('../fonts/fonts-post.cyrillic.css');
import('../fonts/fonts-shared.latin-ext.css');
import('../fonts/fonts-post.latin-ext.css');
break;
case 'cs':
case 'da':
case 'de':
case 'es':
case 'fi':
case 'fr':
case 'hu':
case 'it':
case 'nl':
case 'no':
case 'pl':
case 'pt-br':
case 'sk':
case 'sr':
case 'sq':
case 'sv':
case 'tr':
import('../fonts/fonts-shared.latin-ext.css');
import('../fonts/fonts-post.latin-ext.css');
break;
case 'vi':
import('../fonts/fonts-shared.vietnamese.css');
import('../fonts/fonts-post.vietnamese.css');
break;
case 'fa':
import('../fonts/fonts-post.persian.css');
break;
default:
break;
}
};
// TODO: the curried signature is weird.
export const createLanguageLink = (slug, lang) => {
const rawSlug = slug.replace(`${lang}/`, '');
return targetLang =>
targetLang === 'en' ? rawSlug : `${targetLang}${rawSlug}`;
};