Javascript i18n Message Generator In Jawr

Posted By : Rahul Singh | 28-Jan-2018

Javascript i18n message generator

There are many rich applications available which handled and displayed messages by javascript components. In Java web applications, Resource Bundle available to support internationalization. The process is messages are stored in many properties files with different languages. for example Resource Bundle (such as messages) and suffixes that specify (such as 'messages_en' for English) with different locale supported.

 

Jawr generating messages automatically for a javascript based data structure which adopt the properties format. Each property in the properties file is converted to a function that returns the message, supporting variable substitution with the standard Resource Bundle format.

 

Example, "messages_en.properties" that contains the following messages in English:

 

para1.hello.world=Hello World!
para2.user.salutation=Welcome, {0}!!

 

By using a generator, we are able to access the messages from javascript like this:

 

 alert( messages.para1.hello.world() );
 alert( "---------
"+messages.para2.user.salutation('Rahul') );
        

Here two consecutive messages will be displayed "Hello World!!" and "Welcome Rahul!!" we can also use another language with the same message with the help of Jawr technology which includes a language-specific of the messages given by the user.

Example, "messages_es.properties" that contains the following messages in Spanish:

para1.hello.world=Hola Edmundo!
para2.user.salutation=Bienvenido, {0}!

 

For user-specific Jawr is able to set message locale in many languages (stored in .properties files) rather than one language like English. Scripts can access the properties according to receiving messages languages. I18n is the best way to customizable to prefer any specific language for any suitable application. Mapping a message generator:

jawr.js.bundle.lib.id=/bundles/global.js
jawr.js.bundle.lib.mappings=messages:com.myapp.messages_es,/js/lib/**

 

Defining the message namespace:

jawr.js.bundle.lib.mappings=messages:com.myapp.messages(mynamespace),/js/lib/**  

 

Filtering messages:

jawr.js.bundle.lib.mappings=messages:com.myapp.messages[javascript.messages],/js/lib/**

 

Example 1:


function testMessages(functionPath,id) 

{
  var arg=functionPath.split('.'),root=window.messages;
  for(var i=0;i

 

Example 2:


function testMessages(functionPath) {
  var args=functionPath.split('.'),root=window.messages;
  for(var i=0;i

 

Basically, i18n is the concept of managing users according to their region and languages which help the application in globally.

 

------Thanks--------

About Author

Author Image
Rahul Singh

Rahul singh is a Java Developer and having experience in developing Applications. He is a quick learner.

Request for Proposal

Name is required

Comment is required

Sending message..