@criticalmanufacturing/dev-i18n-transform
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

Translation Resources Transform

Build Status Coverage Status Codacy Badge

i18n transform is a CMF developer tool that easily converts the development translation resources (in typescript) into the gettext PO files and vice-versa.

Transform TS -> PO

Typescript

// Get parser for TS files
let parser = ParserFactory.getParser(
    __dirname, // path to package
    [
        // these files are your ts files, relative to your package
        path.join(__dirname, "test/mocks/multilevelExample/mock.default.ts"),
        path.join(__dirname, "test/mocks/multilevelExample/mock.pt-PT.ts")
    ]
);
// Run parser and get package
let pack = parser.run();

// Get writer for "pt-PT" language
let writer = WriterFactory.getWriter(pack, "pt-PT", "po");

// Run writer and get buffer files
let buffer = writer.run();

// Write buffer (create files)
fs.writeFileSync("output/i18n.po", buffer[0].content);

Gulp

var i18n = require("cmf.dev.i18n").gulp;

gulp.task('i18n-ts-to-po', function() {
    return gulp
        .src([
            // these files are your ts files, relative to your package
            // in this example, __dirname is the package root dir
            path.join(__dirname, "test/**/*.ts"),
            "!**/*.d.ts" // remember to remove *.d.ts files
        ], { cwd: __dirname }) // very important
        .pipe(i18n({
            base: __dirname, // your package root dir
            languages: ["en-EN", "pt-PT", ...], // 
            dest: "po" // destination format, "ts" or "po"
        }))
        .pipe(gulp.dest("output")); // this will create 1 file for each language in dest folder
});

Transform PO -> TS

Typescript

// Get parser for PO files
let parser = ParserFactory.getParser(
    __dirname, // path to package
    [
        // these files are your po files, relative to your package
        path.join(__dirname, "output/i18n.po"),
    ]
);
// Run parser and get package
let pack = parser.run();

// Get writer for "pt-PT" language
let writer = WriterFactory.getWriter(pack, "pt-PT", "ts");

// Run writer and get buffer files
let buffer = writer.run();

// Write buffer (create files)
for(let file of buffer) {
    fs.writeFileSync(path.join("output", file.file), file.content);
}

Gulp

var i18n = require("cmf.dev.i18n").gulp;

gulp.task('i18n-po-to-ts', function() {
    return gulp
        .src([
            // these files are your po files, relative to your package
            // in this example, __dirname is the package root dir
            path.join(__dirname, "output/*.po")
        ], { cwd: __dirname }) // very important
        .pipe(i18n({
            base: __dirname, // your package root dir
            languages: ["en-EN", "pt-PT", ...], // 
            dest: "ts" // destination format, "ts" or "po"
        }))
        .pipe(gulp.dest("output")); // this will create 1 file for each language in dest folder
});

Additional Information

This package was developed during the UX-FAB: Universal Experience for Advanced Fabs project.

Portugal2020

Package Sidebar

Install

npm i @criticalmanufacturing/dev-i18n-transform

Weekly Downloads

1

Version

1.0.12

License

SEE LICENSE IN "license"

Unpacked Size

271 kB

Total Files

85

Last publish

Collaborators

  • pedroapap
  • adeliofernandes
  • jagoncalves
  • francisco-maciel
  • jsantoscmf
  • criticalmanufacturing.com
  • msilva_cmf
  • lmponte