Reactjs 国际化反应应用程序。如何提取消息?
我有一个使用typescript、babel和react的应用程序,我想将国际化添加到我的应用程序中。 例如,如何将我的en.json提取到其他地区 我的./src/translations中有翻译 en.jsonReactjs 国际化反应应用程序。如何提取消息?,reactjs,frontend,babeljs,Reactjs,Frontend,Babeljs,我有一个使用typescript、babel和react的应用程序,我想将国际化添加到我的应用程序中。 例如,如何将我的en.json提取到其他地区 我的./src/translations中有翻译 en.json { "page.login.title: "Login", "page.login.link.forgot.passowrd: "Forgot password" } { "page.login.title: "Login", "page.login.link.fo
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Forgot password"
}
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Forgot password"
}
ru.json
{
"page.login.title: "Страница входа",
}
{
"page.login.title: "Страница входа",
"page.login.link.forgot.passowrd: "Forgot password"
}
ua.json
{
"page.login.link.forgot.passowrd: "Забув пароль"
}
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Забув пароль"
}
如何获取文件夹中的文件。/src/解压缩后的翻译如下
en.json
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Forgot password"
}
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Forgot password"
}
ru.json
{
"page.login.title: "Страница входа",
}
{
"page.login.title: "Страница входа",
"page.login.link.forgot.passowrd: "Forgot password"
}
ua.json
{
"page.login.link.forgot.passowrd: "Забув пароль"
}
{
"page.login.title: "Login",
"page.login.link.forgot.passowrd: "Забув пароль"
}
我已经在nodejs上写了脚本
const fs = require('fs');
const MAIN_LANGUAGE = './src/translations/en.json';
const LANG_DIR = './src/translations/';
const mainLocale = JSON.parse(
fs.readFileSync(MAIN_LANGUAGE, 'utf8', error => {
if (error) throw error;
})
);
fs.readdirSync(LANG_DIR).forEach(file => {
const currentLocale = JSON.parse(
fs.readFileSync(`${LANG_DIR}/${file}`, 'utf8', error => {
if (error) throw error;
})
);
const updatedCurrentLocale = JSON.stringify(
{ ...mainLocale, ...currentLocale },
null,
2
);
fs.writeFileSync(
`${LANG_DIR}/${file}`,
updatedCurrentLocale,
'utf8',
error => {
if (error) throw error;
}
);
console.log(`READY LOCALE: ${file}`);
});