Skip to content

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

License

Notifications You must be signed in to change notification settings

pillarsjs/textualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Textualization

For reasons of time and advancement in technologies, especially JS, this project is no longer maintained.

Thank you for your support and interest in this project.

We personally think this is a good example of simplifying JS code in Node for these purposes and hopefully we'll have enough time to come back to this idea or something similar.

This project has favored great relationships and has provided a lot of learning for its participants

See you later! <3
















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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •