-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #588 from FrostCo/translation_system_updates
Translation system updates
- Loading branch information
Showing
6 changed files
with
63 additions
and
29 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,4 @@ | ||
import BuildTranslation from './buildTranslationClass.js'; | ||
|
||
const buildTranslation = new BuildTranslation(); | ||
buildTranslation.run(); |
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,52 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export default class BuildTranslation { | ||
constructor() { | ||
this.localesDir = path.join('locales'); | ||
this.translations = {}; | ||
} | ||
|
||
build() { | ||
this.translations = this.combineLocaleFiles(this.localesDir); | ||
} | ||
|
||
get combinedTranslationsPath() { | ||
return path.join('src', 'script', 'translations.js'); | ||
} | ||
|
||
combineLocaleFiles(root) { | ||
const combined = {}; | ||
|
||
// Iterate through each language directory (e.g., 'en', 'fr') | ||
fs.readdirSync(root).forEach((locale) => { | ||
combined[locale] = {}; | ||
const localeDir = path.join(root, locale); | ||
|
||
// Iterate through each namespace file in the language directory | ||
fs.readdirSync(localeDir).forEach((file) => { | ||
const namespace = path.basename(file, '.json'); | ||
const filePath = path.join(localeDir, file); | ||
const fileContents = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
|
||
// Assign the namespace contents to the appropriate language | ||
combined[locale][namespace] = fileContents; | ||
}); | ||
}); | ||
|
||
return combined; | ||
} | ||
|
||
get output() { | ||
return `export const translations = ${JSON.stringify(this.translations, null, 2)};\n\nexport default translations;\n`; | ||
} | ||
|
||
run() { | ||
this.build(); | ||
this.writeCombinedTranslations(); | ||
} | ||
|
||
writeCombinedTranslations() { | ||
fs.writeFileSync(this.combinedTranslationsPath, this.output, 'utf8'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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