Skip to content

Commit 046b037

Browse files
committed
Add more supported languages
Add new scripts to build language packs
1 parent c145b01 commit 046b037

File tree

148 files changed

+46950
-18
lines changed

Some content is hidden

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

148 files changed

+46950
-18
lines changed

config/buildlangpack.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
buildlanguage.js - ESP3D WebUI language file builder
3+
4+
Copyright (c) 2021 Luc Lebosse. All rights reserved.
5+
6+
This code is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
This code is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with This code; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
const chalk = require("chalk")
19+
const path = require("path")
20+
const fs = require("fs")
21+
const { Compress } = require("gzipper")
22+
23+
// Vérification des arguments
24+
if (process.argv.length !== 3) {
25+
console.log(chalk.red("Usage: node buildlanguage.js <translation-file.json>"))
26+
process.exit(1)
27+
}
28+
29+
const languageFile = process.argv[2]
30+
const languagesPath = path.normalize(__dirname + "/../languages/")
31+
32+
// Liste des packs à traiter
33+
const targetPacks = ["printerpack", "cncgrblpack", "cncgrblhalpack", "sandtablepack"]
34+
35+
// Lecture du fichier de traduction source
36+
let translations
37+
try {
38+
const translationPath = path.join(languagesPath, languageFile)
39+
const translationContent = fs.readFileSync(translationPath, "UTF-8")
40+
translations = JSON.parse(translationContent)
41+
console.log(chalk.green(`Loaded translations from ${languageFile}`))
42+
} catch (error) {
43+
console.log(chalk.red(`Error loading translation file: ${error.message}`))
44+
process.exit(1)
45+
}
46+
47+
// Fonction pour compresser un fichier
48+
async function compressFile(filePath) {
49+
try {
50+
const sourceDir = path.dirname(filePath)
51+
const gzipper = new Compress(filePath, sourceDir, { verbose: false })
52+
await gzipper.run()
53+
54+
// Renommer le fichier .gz pour correspondre au nom original
55+
fs.renameSync(`${filePath}.gz`, `${filePath}.gz`)
56+
57+
const originalSize = fs.statSync(filePath).size
58+
const compressedSize = fs.statSync(`${filePath}.gz`).size
59+
60+
// Afficher le message de génération du fichier gz
61+
console.log(chalk.green(`Generated ${path.basename(filePath)}.gz for ${path.basename(path.dirname(filePath))}`))
62+
63+
console.log(chalk.blue(`Compression for ${path.basename(filePath)}:`))
64+
console.log(
65+
chalk.blue(
66+
`- Original: ${originalSize} Bytes => Compressed: ${compressedSize} Bytes`,
67+
`(${(100 - 100 * (compressedSize / originalSize)).toFixed(2)}% reduction)`
68+
)
69+
)
70+
} catch (error) {
71+
console.log(chalk.red(`Error compressing ${filePath}: ${error.message}`))
72+
}
73+
}
74+
75+
// Traitement de chaque pack
76+
const processAllPacks = async () => {
77+
for (const packName of targetPacks) {
78+
try {
79+
// Lecture du fichier en.json de référence pour ce pack
80+
const referenceFile = path.join(languagesPath, packName, "en.json")
81+
const referenceContent = fs.readFileSync(referenceFile, "UTF-8")
82+
const reference = JSON.parse(referenceContent)
83+
84+
// Création du nouveau fichier de traduction
85+
const newTranslations = {}
86+
87+
// Ajout de l'identifiant de la target
88+
newTranslations["target_lang"] = packName
89+
90+
// Copie des traductions correspondantes
91+
Object.keys(reference).forEach(key => {
92+
// Skip if reference value is null
93+
if (reference[key] === null) {
94+
console.log(chalk.yellow(`Skipping key "${key}" in ${packName} - null value in reference`))
95+
return
96+
}
97+
98+
const translationValue = translations[key]
99+
// Skip if translation is null or empty string
100+
if (!translationValue || translationValue === "") {
101+
console.log(chalk.yellow(`Skipping key "${key}" in ${packName} - translation empty or missing`))
102+
return
103+
}
104+
105+
// Add valid translation
106+
newTranslations[key] = translationValue
107+
})
108+
109+
// Création du répertoire si nécessaire
110+
const outputDir = path.join(languagesPath, packName)
111+
if (!fs.existsSync(outputDir)) {
112+
fs.mkdirSync(outputDir, { recursive: true })
113+
}
114+
115+
// Sauvegarde du nouveau fichier
116+
const outputFile = path.join(outputDir, languageFile)
117+
fs.writeFileSync(outputFile, JSON.stringify(newTranslations, null, 1), "UTF-8")
118+
119+
console.log(chalk.green(`Generated ${languageFile} for ${packName}`))
120+
121+
// Compression du fichier généré
122+
await compressFile(outputFile)
123+
124+
// Affichage des statistiques
125+
const totalKeys = Object.keys(reference).length
126+
const translatedKeys = Object.keys(newTranslations).length - 1 // -1 pour target_lang
127+
console.log(chalk.blue(`Statistics for ${packName}:`))
128+
console.log(chalk.blue(`- Total keys: ${totalKeys}`))
129+
console.log(chalk.blue(`- Translated keys: ${translatedKeys}`))
130+
console.log(chalk.blue(`- Translation completion: ${((translatedKeys/totalKeys)*100).toFixed(2)}%`))
131+
132+
} catch (error) {
133+
console.log(chalk.red(`Error processing ${packName}: ${error.message}`))
134+
}
135+
}
136+
}
137+
138+
// Exécution du script
139+
processAllPacks().then(() => {
140+
console.log(chalk.green("Translation processing and compression completed"))
141+
})

config/buildtemplate.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const cncgrblhalpack = [
4646
]
4747
const printerpack = [
4848
{ id: "globals", path: "src/targets/translations/en.json" },
49-
5049
{
5150
id: "printers3D",
5251
path: "src/targets/Printer3D/translations/en.json",
@@ -86,8 +85,13 @@ const processList = [
8685
{ targetPath: "printerpack", files: printerpack },
8786
{ targetPath: "sandtablepack", files: sandtablepack },
8887
]
88+
89+
// Object to store all unique translations
90+
let masterTranslations = {}
91+
8992
if (readable) console.log(chalk.green("Processing in readable mode"))
9093
else console.log(chalk.green("Processing in production mode"))
94+
9195
processList.map((element) => {
9296
let resultfile = {}
9397

@@ -101,6 +105,10 @@ processList.map((element) => {
101105
Object.keys(currentFile).map((key) => {
102106
if (!resultfile[key] && typeof currentFile[key] != "undefined") {
103107
resultfile[key] = currentFile[key]
108+
// Add to master translations if not already present
109+
if (!masterTranslations[key]) {
110+
masterTranslations[key] = currentFile[key]
111+
}
104112
} else {
105113
if (resultfile[key] != currentFile[key]) {
106114
console.log(chalk.red("In " + sourcepath))
@@ -132,4 +140,12 @@ processList.map((element) => {
132140
)
133141
})
134142

143+
// Save master translations file
144+
console.log(chalk.green("Saving master translations file"))
145+
fs.writeFileSync(
146+
path.join(path.normalize(__dirname + "/../languages/"), "master_translations.json"),
147+
JSON.stringify(masterTranslations, "", readable ? " " : ""),
148+
"UTF-8"
149+
)
150+
135151
console.log(chalk.green("Processing done"))

dist/Plotter/HP-GL/index.html.gz

-73.4 KB
Binary file not shown.

languages/cncgrblhalpack/en.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"S12": "About %s",
1515
"S13": "Dashboard",
1616
"S14": "Settings",
17-
"S15": "Donation for ESP3D",
1817
"S16": "Firmware",
1918
"S17": "Interface",
2019
"S18": "Browser version",
@@ -146,8 +145,6 @@
146145
"S140": "GCODE command",
147146
"S141": "File name",
148147
"S142": "Command",
149-
"S143": "SD",
150-
"S144": "SD",
151148
"S145": "Authentication Required",
152149
"S146": "User Name",
153150
"S147": "Password",
@@ -395,6 +392,7 @@
395392
"resume_script": "Resume script",
396393
"stop_script": "Stop script",
397394
"polling_on": "Polling enabled",
395+
"wifi mode": "Wifi mode",
398396
"language": "Language",
399397
"CN1": "mm/min",
400398
"CN2": "XY feed rate",

0 commit comments

Comments
 (0)