Fork me on GitHub

2 Aug 2011

Avoiding accidental i18n in Grails

We’re developing an app that’s exclusively for a UK audience so i18n really isn’t an issue for us. However recently we got bitten by some i18n creeping in where we didn’t want it. Specifically, when using Grails’ g:dateFormat tag the default behaviour is to format the date according to the Locale specified in the user’s Accept-Language header. Even though we are explicitly specifying a format pattern for the date Java is aware of localized day names for some languages so the output can vary. The result is that on a page full of English text there suddenly appears a Spanish or Swedish day name. What makes things worse is that as we use server-side content caching and a CDN if a user with a non-English Accept-Language header is the first to see a particular page or bit of dynamically retrieved content then the cache is primed and until it expires everyone will see the non-English day name text.
The solution in a Grails app is as simple as replacing Spring’s standard localeResolver bean with an instance of FixedLocaleResolver. Just add the following to grails-app/conf/spring/resources.groovy:
localResolver(org.springframework.web.servlet.i18n.FixedLocaleResolver, Locale.UK)
This changes the way Spring works out the request locale and any locale-aware tags should just fall into place.

12 comments:

Shin Tai said...

Same with formatNumber and where type is currency.

I came across that when my system settings were English (US) which got passed down by Firefox into the headers.

qinbincai123 said...

My voice tried to find the wind to hike81ai touch her hearing.Another's.
She will be another's.As she was before my kisses.
Wholesale New Era Hats
Cheap New Era Hats
Wholesale Hats
New Era 59fifty Hats
Cheap Hats

Bella Tran said...

Thanks for publishing this blog
descargar mobogenie | baixar facebook | baixar mobogenie | descargar facebook | facebook descargar | descargar mobogenie | whatsapp descargar and whatsapp gratis | mobogenie descargar

Alice Taylor said...

Thanks for all your information, Website is very nice and informative content
monkey go happy 2cat mario 2learn to fly 2 | happy wheels demo | mahjong online | pacman game | monkey go happy 3 | cat mario 3learn to fly 3 | happy wheels 2 | mahjong | pacman games

Anjali Sharma said...

New Year is the best event for everyone so celebrate this New Year 2017 with us and send some wonderful and awesome New Year Wishes, Greeting, Quotes and many more for your Love ones.
New Year Wishes 2017

buyket said...


نستخدم افضل المكينات المخصصه في تنظيف الموكيت والسجاد الخاص بالمساجد والتي تعمل عن طريق تنظيف موكيت المساجد بالمنظفات الحديثه لكي نصل الي اعلي مستوي من التنظيف

كما ان جودة التنظيف الخاص بتنظيف الموكيت تعتمد علي نوعيته مع استخدام المكينات الحديثه وبالاضافه الي الايدي العامله المدربه حديثا

شركة تنظيف مساجد بالرياض

ngocanh said...

Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.I actually appreciate your own position and I will be sure to come back here.
hotmail login l login hotmai l hotmail log in l hotmail sign in l hotmail sign up

aliamay said...

iPl cricket live and all the updates of cricket.. Ipl 2017 will be scheduled all the news and updates of this season. Get all the news and updates of live cricket on just a single click.

我愛你 said...




More than wonderful article Dear Sir, Please continue what I have invented It is really very special with my greetings
العاب تلبيس بنات 2018
العاب طبخ فلاش
العاب سيارات

قمة الدقة للخدمات said...

شركة كشف تسربات المياه بالاحساء
شركة تسليك مجارى بالدمام

ali gamal said...


شركة تسليك مجاري بالدمام

شركة تسليك مجاري بالاحساء

شركة تنظيف وصيانة مسابح بالدمام

Love Kpop said...

I'm puzzled with lots of exercises. I was afraid I could not do the right time despite my hard work. I need a support person.
http://run3play.com