npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-tarjeem

v0.2.1

Published

Gulp plugin with function-style, dictionary agnostic which compile javascript source codes into localized scripts.

Downloads

10

Readme

Gulp Tarjeem

Here in short this Gulp plugin is,

Function-style, dictionary agnostic translation gulp plugin which compile javascript source codes into localized scripts.

"Do one thing and do it well"

This project restricted to, or only feature

  • Function-styled
  • Compile javascript source code to localized scripts
  • Dictionary agnostic (as long as it converted to JSON)
  • One dictionary into one output for each file passed through

If above points deviated, please report a bug.

Usage

In gulpfile.js

First, install gulp-tarjeem as a development dependency:

# Not published yet :(
npm install --save-dev gulp-tarjeem

Then, add it to your gulpfile.js:

var translate = require('gulp-tarjeem');

gulp.task('translate', function() {
  var translations = ['en', 'id'];

  translations.forEach(function(translation){
    gulp.src('app/script/**/*.js')
      .pipe(translate(options))
      .pipe(gulp.dest('dist/script/' + translation));
  });
});

or better, handle errors:

gulp.task('translate', function() {
  var translations = ['en', 'id'];

  translations.forEach(function(translation){
    gulp.src('app/script/**/*.js')
      .pipe(
        translate(options)
        .on('error', function(){
          console.error(arguments);
        })
      )
      .pipe(gulp.dest('dist/script/' + translation));
  });
});

In your locales

You may put locale in a directory with language abbrev as it's name.

locales/en.json

{ "title": "My new Gulp plugin, call it Tarjeem" }

locales/id.json

{ "title": "Plugin Gulp baru milik saya, sebut saja Tarjeem" }

In your script.js

Then you can "calling" transl plugin with an argument of a key in your locales you specified earlier.

Something like this will do,

document.getElementById('title').text(transl("title"))

will be compiled into

// File: en/script.js
document.getElementById('title').text("My new Gulp plugin, call it Tarjeem")
// File: id/script.js
document.getElementById('title').text("Plugin Gulp baru milik saya, sebut saja Tarjeem")

If you're still not sure, please look at tests.

API

translate(dictionaryFilePath)

gulp-tarjeem is called with a string

dictionaryFilePath

Type: String

The string is a path to a locale-file-name.js with your locales. Please look at test/locales for examples.

translate(options)

gulp-tarjeem is called with an object

options

Type: Object

An Object with the following properties that affect how this plugin works,

  • .dictionaryFilePath String. Path to locale file.
  • .dictionaryObject Object. Dictionary to lookup instead of locale specified above. If you specify this, dictionaryFilePath property will be ignored.
  • .syntaxFnName String. Function name to match. Default: transl
  • .fileToDictFn Function, signature function(filecontent) => Object. Custom function to convert whatever dictionaryFilePath content might be into Javascript key-value object.
  • .translatorFn Function, signature function(key, dictionary) => string. Custom function to convert translation key into translated output string. Default: Convert dot-separated namespace "some.name.space" into dictionaryObject['some']['name']['space'].

Tips & Trick

This plugin is actually very flexible. A String in Javascript can be chained with built in method such as toUpperCase(), toLowerCase(). So, you can do lots of things.

// Chain with .toUpperCase()
var message1 = transl("title").toUpperCase();

// Process with function
var message2 = String.toUpperCase(transl("title"));

// Chain to replace a placeholder
var message3 = transl("title").replace(':year', new Date.getFullYear());

TODO:

  • refactor tests
  • work on matchers (sigh...)

License

This work adapted from @arathunku's MIT-licensed (https://github.com/arathunku/gulp-translator).

Further work contribution licensed into Mozilla Public License 2.0 (MPL-2.0).