-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: automatic translation registration
Automatically load translations
- Loading branch information
Showing
6 changed files
with
236 additions
and
21 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
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,23 @@ | ||
import { Resource } from "i18next"; | ||
|
||
import de from "./de.json"; | ||
import en from "./en.json"; | ||
import fi from "./fi.json"; | ||
import fr from "./fr.json"; | ||
import lb from "./lb.json"; | ||
import lt from "./lt.json"; | ||
import pl from "./pl.json"; | ||
import pt from "./pt.json"; | ||
|
||
const translations: Resource = { | ||
de: { translation: de }, | ||
en: { translation: en }, | ||
fi: { translation: fi }, | ||
fr: { translation: fr }, | ||
lb: { translation: lb }, | ||
lt: { translation: lt }, | ||
pl: { translation: pl }, | ||
pt: { translation: pt } | ||
}; | ||
|
||
export default translations; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const i18nFolder = "./i18n"; | ||
const files = fs.readdirSync(i18nFolder); | ||
const jsonFiles = files.filter(file => file.endsWith('.json')).map(file => path.basename(file, '.json')); | ||
|
||
|
||
const imports = `import { Resource } from "i18next";\n\n` + jsonFiles.map(lang => `import ${lang} from "./${lang}.json";`).join('\n'); | ||
|
||
const translationsObject = `const translations: Resource = { | ||
${jsonFiles.map(lang => `${lang}: { translation: ${lang} }`).join(',\n ')} | ||
}; | ||
export default translations; | ||
`; | ||
|
||
|
||
const outputPath = "./i18n/index.ts"; | ||
const content = `${imports}\n\n${translationsObject}`; | ||
|
||
fs.writeFileSync(outputPath, content, 'utf-8'); | ||
console.log('Finished loading translations.'); |
Oops, something went wrong.