-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a6a0ec
commit e62a494
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
active/langs/* | ||
!placeholder.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const langs = require("./languages-conversion.json"); | ||
const fallbackLanguage = "en_us"; | ||
|
||
const baseDirectory = "langs"; | ||
const baseDirectoryActive = "active/langs"; | ||
|
||
function activate() { | ||
Object.entries(langs).forEach(([key, value]) => { | ||
|
||
const directory = path.join(baseDirectory, value, "bot", "standard"); | ||
|
||
if (!fs.existsSync(directory)) { | ||
console.log(`Skipping non-existent directory: ${directory} for language code ${key}`); | ||
return; | ||
} | ||
|
||
const files = fs.readdirSync(directory); | ||
if (files.length === 0) { | ||
console.log(`No JSON files found in ${directory}.`); | ||
return; | ||
} | ||
|
||
const activeLanguageDirectory = path.join(baseDirectoryActive, value); | ||
|
||
if (!fs.existsSync(activeLanguageDirectory)) | ||
fs.mkdirSync(activeLanguageDirectory); | ||
|
||
const activeLanguageBotDirectory = path.join(baseDirectoryActive, value, "bot"); | ||
|
||
if (!fs.existsSync(activeLanguageBotDirectory)) | ||
fs.mkdirSync(activeLanguageBotDirectory); | ||
|
||
const activeLanguageBotStandardDirectory = path.join(baseDirectoryActive, value, "bot", "standard"); | ||
|
||
if (!fs.existsSync(activeLanguageBotStandardDirectory)) | ||
fs.mkdirSync(activeLanguageBotStandardDirectory); | ||
|
||
files.forEach(file => { | ||
if (!file.endsWith('.json')) { | ||
console.log(`Skipping non-JSON file: ${file}`); | ||
return; | ||
} | ||
|
||
console.log(`Copying ${value}/${file}...`); | ||
const filePath = path.join(directory, file); | ||
try { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const jsonData = JSON.parse(data); | ||
const fallbackLanguageData = require(`./${baseDirectory}/${fallbackLanguage}/bot/standard/${file}`); | ||
// console.log(jsonData); | ||
function checkFields(obj, path = '') { | ||
Object.keys(obj).forEach(key => { | ||
const value = obj[key]; | ||
const currentPath = path ? `${path}.${key}` : key; | ||
|
||
if (typeof value === 'string') { | ||
let pointer = fallbackLanguageData; | ||
const structPath = currentPath.split("."); | ||
for (let i = 0; i < structPath.length - 1; i++) | ||
pointer = pointer[structPath[i]]; | ||
pointer[structPath[structPath.length - 1]] = value; | ||
} else if (typeof value === 'object' && value !== null) { | ||
checkFields(value, currentPath); | ||
} | ||
}); | ||
} | ||
|
||
checkFields(jsonData); | ||
|
||
const activeDirectory = path.join(baseDirectoryActive, value, "bot", "standard"); | ||
|
||
if (!fs.existsSync(activeDirectory)) | ||
fs.mkdirSync(activeDirectory); | ||
|
||
fs.writeFileSync(path.join(activeDirectory, file), JSON.stringify(fallbackLanguageData)); | ||
|
||
} catch (err) { | ||
console.error(`Error processing ${file}:`, err); | ||
foundErrors = true; | ||
} | ||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
module.exports = activate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Autogenerated files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const activate = require("./activate"); | ||
|
||
module.exports = { | ||
activate | ||
}; |