Rollup plugin to convert CSV i18n definitions into nested JavaScript objects.
npm install --save-dev rollup-plugin-i18n-csv
import buble from "rollup-plugin-buble";
import i18nCsv from "rollup-plugin-i18n-csv";
export default {
entry : "src/index.js",
targets : [
{ dest : pkg.main, format : "cjs" },
{ dest : pkg.module, format : "es" }
],
plugins : [ buble(), i18nCsv() ]
};
key,en,de,es,fr
login.forgot.linktext,"Forgot your password?","Passwort vergessen?","¿Has olvidado tu contraseña?","Vous avez oublié votre mot de passe ?"
import i18n from "./strings.csv";
console.log(i18n);
// {
// en : {
// login : {
// forgot : {
// linktext : "Forgot your password?"
// }
// }
// },
// ...
// }
If a translation is missing the value will default to the English value wrapped with [[
]]
for visibility.
If an alternative object output structure is required you can supply a function which takes the CSV row and current field as arguments:
i18nCsv({
path : (row, field) => ([ field, row.key ])
})
// {
// en : {
// "login.forgot.linktest" : "Forgot your password?"
// },
// ...
// }
MIT