textualization

Internationalization (i18n) for Node.js => i18n('path.to.mi.text',{...params...},lang);

Showing:

Popularity

Downloads/wk

44

GitHub Stars

5

Maintenance

Last Commit

4yrs ago

Contributors

4

Package

Dependencies

3

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Textualization

license Build Status npm version Github release npm downloads

Very simple internationalization (aka i18n) manager for Node.js

Textualization offers the possibility of not writing any user text message in your JS code. Allows to translate your code into any language without having to learn a complex methodology.


Textualization in 5 minutes:

Usual way for writing without i18n support:

var message = "User " + username + " has been disconnected at " + time + ".";

Usual way for programming with others i18n systems, something like:

var message = i18n.translate(
  "User %s has been disconnected at %s",
  [user.firstName+" "+user.lastName, time.toUTCString()],
  language
);

And a translation sheet entry similar to:

...
"User %s %s has been disconnected at %s." = "El usuario %s %s se ha desconectado a las %s.";
...
...

Textualization way:

var message = i18n('user.messages.logOut',{user:user, time:time}));

And translate by JS/JSON i18n sheets, with direct dot-notation reference {} or evaluated expressions ·{}·:

{
  user: {
    messages: {
      logOut: "The user {user.firstName} {user.lastName} has been disconnected at ·{time.toUTCString()}·",
      ...
    },
    ...
  },
  ...
}

More possible uses (See String.format):

...:"The user ·{username.toUpperCase()}· has been logged out.",
...:"New properties ·{Object.keys(props).join(',')}· added!",
...:"Welcome {user.firstName} {user.lastName}!"

Easy numerals/plurals for every language:

i18n('mail.inbox.status', 5);             // Short version
i18n('mail.inbox.status', {_num_:5,...}); // For support of aditional params

Translation entry as array of numeral options:

...:[
      "No messages in the inbox",
      "There is a message in the inbox",
      "There are {_num_} messages in the inbox"
    ]

And direct objects and arrays parsing as JSON.

"The Object {myObj} is loaded." ==> "The Object {a:'A',b:'B'} is loaded."
"The Array {myArray} is loaded." ==> "The Array ['A','B','C'] is loaded."

Along with a simple translation sheet load system:

// Hypothetical working directory
myApp/
     /languages/
               /en.js
               /es.js
               /de.js
               /ru.js
i18n.load('nameSpace', './languages');
i18n.languages = ['en', 'es'];

Textualization load from directory ./languages only i18n.languages defined, and refresh translations cache if this property changes.

Additionally is possible to use functions in translations sheets.

({
  hello: "Hello {name}!",
  bye: function (){return "Good bye" + name;}, // contextualized evaluation.
  ...
})

The brackets at the beginning and end of the statement are optionals. In some text editors allows to have a correct syntax highlighting.

Nothing more, that's all. Simple?

This repository is part of the Pillars.js core libraries. Any contribution, collaboration, issues... is well come ;)

contact Us!:

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial