5 Dec, 2008 in Grails by khelll

Grails and Arabic localization

A little problem that i faced with grails , was setting the locale dynamically, i followed this nice article , and here is how i could manage it :

  1. I made a new file called messages_ar.properties that contains the arabic localization under the i18n folder.
  2. I made a simple beforeinterceptor:
    def beforeInterceptor = {
            def key = "org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER"
            def localeResolver = request.getAttribute(key)
            localeResolver.setLocale(request, response, new Locale("ar","JO"))
        }

Of course you can use grails/Filters to save yourself repeating the same code in every controller.

However what i want to mention is the locale object, which in case of Arabic localization, was seeking the country argument ( “JO” in our case) :

new Locale("ar","JO")

While for other localizations like German one it doesn’t seek this second argument, so this snippet of code will work for them :)

new Locale("de")

Also you can change this country argument value to match this rule :

The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:

http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html

I hope that was helpful :) , enjoy!

2 Responses so far | Have Your Say!

  1. phiras - Gravatar

    phiras  |  December 5th, 2008 at 12:37 pm #

    Congrats for the new blog!

  2. Abdullah - Gravatar

    Abdullah  |  December 6th, 2008 at 9:36 am #

    Congratulations :D

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">