-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathi18next.config.js
More file actions
109 lines (102 loc) · 2.2 KB
/
Copy pathi18next.config.js
File metadata and controls
109 lines (102 loc) · 2.2 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* This defines the configuration for `i18next-cli extract`, which can be used to scan PsychoPy
* Studio's code for strings which need to have a translation defined.
*/
import { parse } from "svelte/compiler";
import { walk } from "estree-walker";
let functions = ["t", "i18next.t", "translate"]
const SvelteExtractor = {
name: "svelte-extractor",
onLoad: (code, path) => {
// ignore non-Svelte files
if (!path.endsWith(".svelte")) {
return undefined
}
// parse file
let ast = parse(code, {
filename: path
});
// array in which to store output
let extracted = [];
// extract from instance
if (ast.instance) {
extracted.push(
code.slice(
ast.instance.content.start, ast.instance.content.end
)
)
}
// extract from module
if (ast.module) {
extracted.push(
code.slice(
ast.module.content.start, ast.module.content.end
)
)
}
// extract from html
if (ast.html) {
walk(ast.html, {
enter(node, parent, prop, index) {
// we're only interested in mustage tags
if (node?.type !== "MustacheTag") {
return
}
// add content to extracted array
extracted.push("(" + code.slice(
node.expression.start, node.expression.end
) + ")")
}
})
}
return extracted.join("\n")
}
}
/** @type {import('i18next-cli').I18nextToolkitConfig} */
export default {
locales: [
"ar-001",
"cs-CZ",
"da-DK",
"de-DE",
"el-GR",
"en-NZ",
"en-US",
"es-CO",
"es-ES",
"es-US",
"et-EE",
"fa-IR",
"fi-FI",
"fr-FR",
"he-IL",
"hi-IN",
"hu-HU",
"it-IT",
"ja-JP",
"ko-KR",
"ms-MY",
"nl-NL",
"nn-NO",
"pl-PL",
"pt-PT",
"ro-RO",
"ru-RU",
"sv-SE",
"tr-TR",
"zh-CN",
"zh-TW",
],
extract: {
input: ["src/**/*.{svelte,js,svelte.js}"],
output: "src/lib/translation/locales/{{language}}.json",
primaryLanguage: "en-US",
removeUnusedKeys: false,
defaultValue: undefined,
defaultNS: false,
functions: functions
},
plugins: [
SvelteExtractor
]
}