Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes.

For example, I should be able to submit web forms,view data on website in user’s localized language like Japanese language in Japan , Chinese language in China country.

Let’s say we want to add internationalization support for Japanese language.i.e user should be able to enter Japanese characters in web forms and it should be saved in same format as entered by user in database and also should be displayed in same language on web page.

I have followed below steps to incorporate internationalization support to my web application.

I have used Spring MVC,Hibernate,MYSQL (Oracle) database , Jboss (Web Logic) application server.

  1. Make sure you have Japanese language support (Region specific installation) installed into operating system. If not, please install it.
  2. Place Spring framework’s in built character encoding filter as a first filter in filter chain (web.xml) to make sure it runs first during request processing and runs last during response processing.
    <filter>  
        <filter-name>encodingFilter</filter-name>
         <filter-class>
                  org.springframework.web.filter.CharacterEncodingFilter
         </filter-class>
          <init-param>
                  <param-name>encoding</param-name>
                  <param-value>UTF-8</param-value>
          </init-param>
          <init-param>
    <!-- set forceEncoding to true if you want to override encoding of servlet -->
                  <param-name>forceEncoding</param-name>
                  <param-value>true</param-value> 
          </init-param>
    </filter>
     
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  3. Set JSP Page encoding to UTF-8 by adding below mentioned code at top of JSP.
    <%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. Set Hibernate connection encoding scheme to UTF-8 by adding following property to hibernate-cfg.xml         <property name="hibernate.connection.characterEncoding">UTF-8         </property>Note : If using JBoss application server, please make sure you have appended characterEncoding=UTF-8 to connection-url in database service configuration file (For ex. mysql-ds.xml for mySQL database) as mentioned below.
    <datasources>
     
    <local-tx-datasource>
     
        <jndi-name>WSCDS</jndi-name>
     
       <connection-url>
       jdbc:mysql://{ipaddress}:{port}/{database_name}?characterEncoding=UTF-8
       </connection-url>
     
    <driver-class>com.mysql.jdbc.Driver</driver-class>
     
    <user-name>{username}</user-name>
     
    <password>{password}</password>  
     
    <metadata>
     
       <type-mapping>mySQL</type-mapping>
     
    </metadata>
  5. Run your web application, Enter Japanese characters in web forms, it should be insert in database in Japanese language and also should be displayed on web page in same language.

 

TextArea.html

<html>
<head>
<script type="text/javascript" src="behaviour.js"></script>
<script type="text/javascript" src="textarea_maxlen.js"></script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-24837008-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>
<p>
Limit 120 Characters: 
<TEXTAREA rows="5" cols="30" maxlength="120" showremain="limitOne">
</TEXTAREA> <br>
</p><p>Limit 50 Characters: <TEXTAREA rows="2" cols="30" maxlength="50" showremain="limitTwo"></TEXTAREA> </body>
</html>

Behaviour.js


/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*
 Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
 of Simon Willison (see comments by Simon below).

 Description:

      Uses css selectors to apply javascript behaviours to enable
      unobtrusive javascript in html documents.

   Usage:

        var myrules = {
                'b.someclass' : function(element){
                        element.onclick = function(){
                                alert(this.innerHTML);
                        }
                },
                '#someid u' : function(element){
                        element.onmouseover = function(){
                                this.innerHTML = "BLAH!";
                        }
                }
        };

        Behaviour.register(myrules);

        // Call Behaviour.apply() to re-apply the rules (if you
        // update the dom, etc).

   License:

        This file is entirely BSD licensed.

   More information:

        http://ripcord.co.nz/behaviour/

*/

var Behaviour = {
        list : new Array,

        register : function(sheet){
                Behaviour.list.push(sheet);
        },

        start : function(){
                Behaviour.addLoadEvent(function(){
                        Behaviour.apply();
                });
        },

        apply : function(){
                for (h=0;sheet=Behaviour.list[h];h++){
                        for (selector in sheet){
                                list = document.getElementsBySelector(selector);

                                if (!list){
                                        continue;
                                }

                                for (i=0;element=list[i];i++){
                                        sheet[selector](element);
                                }
                        }
                }
        },

        addLoadEvent : function(func){
                var oldonload = window.onload;

                if (typeof window.onload != 'function') {
                        window.onload = func;
                } else {
                        window.onload = function() {
                                oldonload();
                                func();
                        }
                }
        }
}

Behaviour.start();

/*
   The following code is Copyright (C) Simon Willison 2004.

   document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names,
     class names and ids and can be nested. For example:

       elements = document.getElementsBySelect('div#main p a.external')

     Will return an array of all 'a' elements with 'external' in their
     class attribute that are contained inside 'p' elements that are
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }

    if (!currentContext[0]){
        return;
    }

    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

/* That revolting regular expression explained
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute
   Tag
*/


textarea_maxlength.js

var CSSrules = {
    'textarea' : function(element){
            element.onkeydown = function(event){
                return doKeyPress(element,event);
            }
            ,
            element.onpaste = function(){
                return doPaste(element);
            }
            ,
            element.onkeyup = function(){
                return doKeyUp(element);
            }
            ,
            element.onblur = function(){
                return doKeyUp(element);
            }
    }
}

Behaviour.register(CSSrules);

var detect = navigator.userAgent.toLowerCase();

// Keep user from entering more than maxLength characters
function doKeyPress(obj,evt){
    maxLength = obj.getAttribute("maxlength");
    var e = window.event ? event.keyCode : evt.which;
    if ( (e == 32) || (e == 13) || (e > 47)) { //IE
        if(maxLength && (obj.value.length > maxLength-1)) {
            if (window.event) {
                window.event.returnValue = null;
            } else {
                evt.cancelDefault;
                return false;
            }
        }
    }
}
function doKeyUp(obj){
    maxLength = obj.getAttribute("maxlength");
     if(maxLength && obj.value.length > maxLength){
           obj.value = obj.value.substr(0,maxLength);
     }
    sr = obj.getAttribute("showremain");
    if (sr) {
        document.getElementById(sr).innerHTML = maxLength-obj.value.length;
    }
}

// Cancel default behavior and create a new paste routine
function doPaste(obj){
maxLength = obj.getAttribute("maxlength");
     if(maxLength){
        if ((window.event) && (detect.indexOf("safari") + 1 == 0)) { //IE
          var oTR = obj.document.selection.createRange();
          var iInsertLength = maxLength - obj.value.length + oTR.text.length;
          try {
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          oTR.text = sData;
          }
          catch (err) {
          }
          if (window.event) { //IE
            window.event.returnValue = null;
     } else {
            //not IE
            obj.value = obj.value.substr(0,maxLength);
            return false;
        }
        }
     }
}



public class Trimming {


    public static void main(String[] s)
    {
        String oldStr = "                 Mr Ketan                  Prajapati               ";

        System.out.println("Original String : "+oldStr);
        System.out.println("Applying left trimming : "+Trimming.ltrim(oldStr));
        System.out.println("Applying right trimming : "+Trimming.rtrim(oldStr));
        /*
         * If simply want to remove all white spaces , pass "" as a replaceWith in trim(String source, String replaceWith)
         * function
         */
        System.out.println("Applying left & right trimming : "+Trimming.trim(oldStr,""));

        /*
         * If  wants to remobe leading & trailling white spaces and replace one or more whitespaces
         * between words with some characters  , pass that character as a replaceWith in trim(String source, String replaceWith)
         * function e.g "_" in below function
         */
        System.out.println("Applying left & right trimming : "+Trimming.trim(oldStr,"_"));
    }

     /* remove leading whitespace */
    public static String ltrim(String source) {
        return source.replaceAll("^\\s+", "");
    }

    /* remove trailing whitespace */
    public static String rtrim(String source) {
        return source.replaceAll("\\s+$", "");
    }

    /* replace multiple whitespaces between words with string specified by replaceWith */
    public static String itrim(String source, String replaceWith) {
        return source.replaceAll("\\b\\s{1,}\\b", replaceWith);
    }

    /* replace leading and trailing whitespace and replace or remove one or more whitespaces
    betwwen words with string specified by replaceWith*/
    public static String trim(String source, String replaceWith) {
        return itrim(ltrim(rtrim(source)), replaceWith);
    }

    /*remove leading & trailing whitespaces */
    public static String lrtrim(String source) {
        return ltrim(rtrim(source));
    }
}


Click to see output


<!--
Document   : How to check whether CKEDITOR value is blank or not
Created on : Jul 29, 2011, 12:00:21 PM
Author     : Ketan Prajapati
-->

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>check whether CKEDITOR value is blank or not</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">google.load("jquery", "1.3.2");</script>

<script type="text/javascript" src="http://ckeditor.com/apps/ckeditor/3.6.1/ckeditor.js?1311599564"></script>
<script type="text/javascript" src="http://ckeditor.com/apps/ckeditor/3.6.1/_source/lang/_languages.js?1311599564"></script>

<!--
I have used online repositoty for Jquery & CKEDITOR , you can also use already downloaded CKEDITOR.js & jquery**.js
-->

<script type="text/javascript">

</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">

function validate(obj)
{
$(".errDiv").remove();
if(validateCKEDITORforBlank($.trim(CKEDITOR.instances.textarea_1.getData().replace(/<[^>]*>|\s/g, '')))){
$("#textarea_1").parent().append("<div class='errDiv' id='errDiv' style='color:red;'>Please enter inputs</div>");
CKEDITOR.instances.textarea_1.setData("");
}
else
{
$("#textarea_1").parent().append("<div class='errDiv' id='errDiv' style='color:green;'></div>");
document.getElementById("errDiv").innerHTML ="Input Text:"+CKEDITOR.instances.textarea_1.getData();
}
}

function validateCKEDITORforBlank(field)
{
var vArray = new Array();
vArray = field.split("&nbsp;");
var vFlag = 0;
for(var i=0;i<vArray.length;i++)
{
if(vArray[i] == '' || vArray[i] == "")
{
continue;
}
else
{
vFlag = 1;
break;
}
}
if(vFlag == 0)
{
return true;
}
else
{
return false;
}
}
</script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-24837008-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</head>
<body>
<table border="1" width="100%">
<thead>
<tr>
<th colspan="2" style="margin-left: 1 px;">How to check whether CKEDITOR value is blank or not</th>
</tr>
</thead>
<tbody>
<tr>
<td width="30%">Input Text  :</td>
<td width="70%">
<textarea rows="5" id="textarea_1" name="textarea_1"></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'textarea_1',
{
fullPage : false
});
</script>
</td>
</tr>
<tr>
<td></td>
<td><input name="button" type="button" id="button" value="Check" onclick="return validate(this)"/></td>
</tr>
<tr>
<td colspan="2">
Note : CKEDITOR takes 2 or more white spaces as & nbsp,so using trim() function will not treat field as empty even though white spaces are equal to blank.
<BR>
Same is problem with enter, tab also,In such case you can use above function.
</td>
</tr>
</tbody>
</table>

</body>
</html>