32 lines
911 B
TypeScript
32 lines
911 B
TypeScript
/**
|
|
* Import translations from the /messages folder and
|
|
* convert them to typesafe-i18n files.
|
|
*/
|
|
import type { BaseTranslation } from "typesafe-i18n";
|
|
import {
|
|
storeTranslationToDisk,
|
|
type ImportLocaleMapping,
|
|
} from "typesafe-i18n/importer";
|
|
import type { Locales } from "../src/i18n/i18n-types";
|
|
import fs from "fs";
|
|
|
|
const importTranslationFile = async (path: string, locale: string) => {
|
|
const data = fs.readFileSync(path, "utf-8");
|
|
const translation = JSON.parse(data);
|
|
|
|
const localeMapping: ImportLocaleMapping = {
|
|
locale,
|
|
translations: translation,
|
|
};
|
|
|
|
const result = await storeTranslationToDisk(localeMapping);
|
|
|
|
console.log(`translations imported for locale '${result}'`);
|
|
};
|
|
|
|
fs.readdirSync("messages").forEach((file) => {
|
|
if (file.endsWith(".json")) {
|
|
const locale = file.substring(0, file.length - 5);
|
|
importTranslationFile(`messages/${file}`, locale);
|
|
}
|
|
});
|