Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

How do you i18n your drop-downs?

As I'm developing this morning and pulling a drop-down list from the database, it hit me - I'm not internationalizing these drop-down values. Sure, putting them in the database makes it easier for admins to edit the values, but if a user visits the site with a Spanish locale, they're going to get English drop-downs. So how do I fix this?

Is the best solution to put the drop-down choices in Struts' ApplicationResources.properties file so that I can render the values with <bean:message/> or <fmt:message/>? How do you do it in your webapps?

In some cases, I guess it doesn't matter as the values need to be in English. Take for instance, AppFuse's edit user screen (user/pass: mraible/tomcat). The list of roles comes from the database and should always be in English because the form-based authentication depends on having an English role_name value in the user_role.role_name column - since this is the value coded in web.xml.

Posted in Java at Feb 18 2004, 10:37:10 AM MST 8 Comments
Comments:

I use a localized table in the db that I put in cache. all my localized strings that have business meanings are in the db the rest are in ApplicationResources. Before I had property files with helper class to load them in the business layer but it is easier to store them in the db since i added an interface for the client to add and delete properites from the db.

Posted by Unknown on February 18, 2004 at 06:03 PM MST #

So you're saying that you have a table for each locale? I'm assuming you then pass the Locale (or String?) down to the persistence layer to figure out which table to select? I wonder if Hibernate has some built-in support for locales so it can switch tables based on locale?

Maybe I should use something like these message resource implementations. I'd rather see a MVC-framework-agnostic way of doing this though...

Posted by Matt Raible on February 18, 2004 at 06:39 PM MST #

No . I have one table for the locale languages(id, name.code) and one table for localized strings. and any table that needs a localized string references the localized strings table.

Posted by Unknown on February 18, 2004 at 06:52 PM MST #

I simply use Cocoon's I18N transformer (http://cocoon.apache.org/2.1/userdocs/transformers/i18n-transformer.html), which integrates nicely with Cocoon Forms (a.k.a. Woody, http://wiki.cocoondev.org/Wiki.jsp?page=Woody). What else do you need? ;-)

Posted by Ugo Cei on February 18, 2004 at 08:59 PM MST #

I wrote an article for O'Reilly awhile back called "Designing Internationalized User Interface Components for Web Applications", which does have an OptionList JSP tag example. The code can be found here. Hope this helps. The example illustrates more the importance of proper sorting as opposed to where you pull the text and values for the option list items.

Posted by David Czarnecki on February 18, 2004 at 09:01 PM MST #

I use both resource bundles (JSTL format tag) for those lists that do not need to be updated (e.g. states) and db for those that need to be managed by the client.

Posted by Harold Neiper on February 19, 2004 at 02:17 AM MST #

This is for drop down lists which don't have to be updated by the users. For every form bean that has country drop down list, each has getCountryOptions() method. That method then calls a 'DropDownListCreator' class. And this class provides a method that constructs a Collection of LabelValueBean s based on a locale in the request. We specify a list of codes for the country options as the LabelValueBean's value, and each code is mapped to keys in a property file which in turn provide the LabelValueBean's label.

Otherwise, the 'DropDownListCreator' can query the database and construct a Collection of LabelValueBean accordingly.

At the end, multiple form beans can re-use the same Collection, combine this with OSCache if you really want to avoid reconstructing the Collections.

Posted by Harod Ruthgar on February 19, 2004 at 02:57 AM MST #

I would like to recieve any examples from any one for the i18n tranformers in cocoon , i can find it very hard to implement specially that i want to make a menu from three languages , english , russian , arabic and when click on any language will retrieve a menu translated to the langauage clicked. Regards

Posted by mahmoud on August 04, 2006 at 08:49 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed