select language or country from a drop down list

900 views
Skip to first unread message

gerry

unread,
Oct 12, 2011, 9:44:28 AM10/12/11
to Google Web Toolkit
Hi all,

I am building an application where the user needs to specify the name
of a work of art, like a poem or song, and I need him to specify its
language. I want to make it possible that he can choose the language
from a drop-down list, and I also want to know the three character
code of the ISO-639-2 standard for the language he selects so that I
can store it in my database (like Eng for English, Ger for German
etc.).

Is there a standard way I can select language in gwt using a drop down
menu and mapping them to the ISO standard code?

I also want to do the same thing for selecting countries through a
drop-down menu and mapping them to their ISO-3166 code (FR for France,
DE for Germany etc.).

Thanks a lot,
Gerasimos

Thad

unread,
Oct 12, 2011, 10:10:56 AM10/12/11
to Google Web Toolkit
What you want sounds like what I do with
com.google.gwt.user.client.ui.ListBox. Look at
addItem(java.lang.String item, java.lang.String value). The item is
what the user sees (the language) while value contains what you're
interested in (the country code).

gerry

unread,
Oct 12, 2011, 10:39:07 AM10/12/11
to Google Web Toolkit
Hi Thad,

Thanks for your reply. In your suggestion I will have to type all the
countries and their codes myself, while I was hoping I could do it in
a more automated way, like I could do if I could use the
java.util.Locale package (method static String[] getISOCountries() for
example) which is not supported by GWT. But it seems I can't do
anything simpler than what you suggest.

Thanks.

Alan Chaney

unread,
Oct 12, 2011, 11:15:20 AM10/12/11
to google-we...@googlegroups.com
What you can do is to write a small java application to generate the
list for you, using the static Locale class methods as you mention below
. You can create json, text or xml and import it into your drop down list.

This will save you a lot of tedious typing.

On 10/12/2011 7:39 AM, gerry wrote:
> Hi Thad,
>
> Thanks for your reply. In your suggestion I will have to type all the
> countries and their codes myself, while I was hoping I could do it in
> a more automated way, like I could do if I could use the
> java.util.Locale package (method static String[] getISOCountries() for
> example) which is not supported by GWT. But it seems I can't do
> anything simpler than what you suggest.

HTH

Alan

gerry

unread,
Oct 13, 2011, 3:58:32 AM10/13/11
to Google Web Toolkit
Hi Alan,

Yes that 's a good idea. Thanks

Prakash

unread,
Oct 13, 2011, 6:53:11 AM10/13/11
to google-we...@googlegroups.com
Gerry,

See whether this class meets your requirements.


Above class contains two letter mapping for most country names. 

-Prakash M.

gerry

unread,
Oct 13, 2011, 7:36:40 AM10/13/11
to Google Web Toolkit
Yes! This is what I need about countries. Do you know if there is a
similar class for languages (mapping languages to codes)?

Thanks

On 13 Οκτ, 13:53, Prakash <prakash.masilam...@gmail.com> wrote:
> Gerry,
>
> See whether this class meets your requirements.
>
> http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/googl...

Kim Ras

unread,
Oct 13, 2011, 12:09:37 PM10/13/11
to Google Web Toolkit
Hi,
I have been looking at the same thing.. and the OOTB language
functions is great in connection with the Resource strings..
My application has a big content driven thing that fitts in the the
standard model, and then it has a more static set of informations.. in
the statuic area I have been thinging of a simple way where you
redirect the page the a HTML page that is coded using the Standard
language codes like EN, DA, GE etc.. Like this:

startPage_EN.html

I know it sounds low practical but if you do not plan to code any of
the pahes just use plain HTML for the part with songs and poems

Regards
Kim
> > -Prakash M.- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -

Prakash

unread,
Oct 13, 2011, 1:32:57 PM10/13/11
to google-we...@googlegroups.com
i dont know of any class, but i had seen locale list box in GWT showcase : http://gwt.google.com/samples/Showcase/Showcase.html
Source code of Showcase app is included in SDK. Check that out ..

Hope this helps.


-prakash m


gerry

unread,
Oct 14, 2011, 4:42:09 AM10/14/11
to Google Web Toolkit
What I did eventually for the languages is take a document like this:
http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt, store it in
the war folder, and parse it line by line to get all languages and
their codes and put them in my drop down list.

For countries, I used the class that Prakash suggested above:
ListBox country = new ListBox();
DefaultLocalizedNames loc = new DefaultLocalizedNames();
for (int i=0; i<loc.getSortedRegionCodes().length; i++) {
String code = loc.getSortedRegionCodes()[i];
country.addItem(loc.getRegionName(code), code);
Reply all
Reply to author
Forward
0 new messages