Skip to content

Rollup plugin to convert CSV i18n definitions into nested JavaScript objects

License

Notifications You must be signed in to change notification settings

voodoochild/rollup-plugin-i18n-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rollup-plugin-i18n-csv

Rollup plugin to convert CSV i18n definitions into nested JavaScript objects.

Installation

npm install --save-dev rollup-plugin-i18n-csv

Usage

rollup.config.js

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() ]
};

src/i18n.csv

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 ?"

src/index.js

import i18n from "./strings.csv";

console.log(i18n);

// {
//     en : {
//         login : {
//             forgot : {
//                 linktext : "Forgot your password?"
//             }
//         }
//     },
//     ...
// }

Missing translations

If a translation is missing the value will default to the English value wrapped with [[ ]] for visibility.

Custom object path

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?"
//     },
//     ...
// }

License

MIT

About

Rollup plugin to convert CSV i18n definitions into nested JavaScript objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published