Grails Cookbook - A collection of tutorials and examples

Grails localeSelect Tag Example

The Grails localeSelect tag (<g:localeSelect>) can be used to generate a dropdown list of locales. This will show a simple example on how to use this tag.

Example

Here is a simple controller code:

package asia.grails.demo
class TestController {
    def prepareForm() {
        Locale localeInstance = Locale.getDefault()
        [localeInstance:localeInstance]
    }
    def submitForm(String locale) {
        render "<p>locale: ${locale}</p>"
    }
}

And this is a sample GSP code that shows how to use the tag:

<g:form action="submitForm" >
    <fieldset class="form">
        <g:localeSelect name="locale" value="${localeInstance}" />
    </fieldset>
    <fieldset class="buttons">
        <g:submitButton name="submitForm" value="Submit" />
    </fieldset>
</g:form>

The locale is submitted as String to the controller.

Here is the sample rendered HTML:

<select name="locale" id="locale" >
    <option value="ja_JP" >ja, JP,  Japanese (Japan)</option>
    <option value="es_PE" >es, PE,  Spanish (Peru)</option>
    ...
    <option value="es_HN" >es, HN,  Spanish (Honduras)</option>
</select>

And here is the sample screenshot:
lo1
lo2

Reference

For convenience, here is the list of locales and their displayed description.

LocaleDescription
ja_JPja, JP, Japanese (Japan)
es_PEes, PE, Spanish (Peru)
enen, English
ja_JPja, JP, Japanese (Japan,JP)
es_PAes, PA, Spanish (Panama)
sr_BAsr, BA, Serbian (Bosnia and Herzegovina)
mkmk, Macedonian
es_GTes, GT, Spanish (Guatemala)
ar_AEar, AE, Arabic (United Arab Emirates)
no_NOno, NO, Norwegian (Norway)
sq_ALsq, AL, Albanian (Albania)
bgbg, Bulgarian
ar_IQar, IQ, Arabic (Iraq)
ar_YEar, YE, Arabic (Yemen)
huhu, Hungarian
pt_PTpt, PT, Portuguese (Portugal)
el_CYel, CY, Greek (Cyprus)
ar_QAar, QA, Arabic (Qatar)
mk_MKmk, MK, Macedonian (Macedonia)
svsv, Swedish
de_CHde, CH, German (Switzerland)
en_USen, US, English (United States)
fi_FIfi, FI, Finnish (Finland)
isis, Icelandic
cscs, Czech
en_MTen, MT, English (Malta)
sl_SIsl, SI, Slovenian (Slovenia)
sk_SKsk, SK, Slovak (Slovakia)
itit, Italian
tr_TRtr, TR, Turkish (Turkey)
zhzh, Chinese
thth, Thai
ar_SAar, SA, Arabic (Saudi Arabia)
nono, Norwegian
en_GBen, GB, English (United Kingdom)
sr_CSsr, CS, Serbian (Serbia And Montenegro)
ltlt, Lithuanian
roro, Romanian
en_NZen, NZ, English (New Zealand)
no_NOno, NO, Norwegian (Norway,Nynorsk)
lt_LTlt, LT, Lithuanian (Lithuania)
es_NIes, NI, Spanish (Nicaragua)
nlnl, Dutch
ga_IEga, IE, Irish (Ireland)
fr_BEfr, BE, French (Belgium)
es_ESes, ES, Spanish (Spain)
ar_LBar, LB, Arabic (Lebanon)
koko, Korean
fr_CAfr, CA, French (Canada)
et_EEet, EE, Estonian (Estonia)
ar_KWar, KW, Arabic (Kuwait)
sr_RSsr, RS, Serbian (Serbia)
es_USes, US, Spanish (United States)
es_MXes, MX, Spanish (Mexico)
ar_SDar, SD, Arabic (Sudan)
in_IDin, ID, Indonesian (Indonesia)
ruru, Russian
lvlv, Latvian
es_UYes, UY, Spanish (Uruguay)
lv_LVlv, LV, Latvian (Latvia)
iwiw, Hebrew
pt_BRpt, BR, Portuguese (Brazil)
ar_SYar, SY, Arabic (Syria)
hrhr, Croatian
etet, Estonian
es_DOes, DO, Spanish (Dominican Republic)
fr_CHfr, CH, French (Switzerland)
hi_INhi, IN, Hindi (India)
es_VEes, VE, Spanish (Venezuela)
ar_BHar, BH, Arabic (Bahrain)
en_PHen, PH, English (Philippines)
ar_TNar, TN, Arabic (Tunisia)
fifi, Finnish
de_ATde, AT, German (Austria)
eses, Spanish
nl_NLnl, NL, Dutch (Netherlands)
es_ECes, EC, Spanish (Ecuador)
zh_TWzh, TW, Chinese (Taiwan)
ar_JOar, JO, Arabic (Jordan)
bebe, Belarusian
is_ISis, IS, Icelandic (Iceland)
es_COes, CO, Spanish (Colombia)
es_CRes, CR, Spanish (Costa Rica)
es_CLes, CL, Spanish (Chile)
ar_EGar, EG, Arabic (Egypt)
en_ZAen, ZA, English (South Africa)
th_THth, TH, Thai (Thailand)
el_GRel, GR, Greek (Greece)
it_ITit, IT, Italian (Italy)
caca, Catalan
hu_HUhu, HU, Hungarian (Hungary)
frfr, French
en_IEen, IE, English (Ireland)
uk_UAuk, UA, Ukrainian (Ukraine)
pl_PLpl, PL, Polish (Poland)
fr_LUfr, LU, French (Luxembourg)
nl_BEnl, BE, Dutch (Belgium)
en_INen, IN, English (India)
ca_ESca, ES, Catalan (Spain)
ar_MAar, MA, Arabic (Morocco)
es_BOes, BO, Spanish (Bolivia)
en_AUen, AU, English (Australia)
srsr, Serbian
zh_SGzh, SG, Chinese (Singapore)
ptpt, Portuguese
ukuk, Ukrainian
es_SVes, SV, Spanish (El Salvador)
ru_RUru, RU, Russian (Russia)
ko_KRko, KR, Korean (South Korea)
vivi, Vietnamese
ar_DZar, DZ, Arabic (Algeria)
vi_VNvi, VN, Vietnamese (Vietnam)
sr_MEsr, ME, Serbian (Montenegro)
sqsq, Albanian
ar_LYar, LY, Arabic (Libya)
arar, Arabic
zh_CNzh, CN, Chinese (China)
be_BYbe, BY, Belarusian (Belarus)
zh_HKzh, HK, Chinese (Hong Kong SAR China)
jaja, Japanese
iw_ILiw, IL, Hebrew (Israel)
bg_BGbg, BG, Bulgarian (Bulgaria)
inin, Indonesian
mt_MTmt, MT, Maltese (Malta)
es_PYes, PY, Spanish (Paraguay)
slsl, Slovenian
fr_FRfr, FR, French (France)
cs_CZcs, CZ, Czech (Czech Republic)
it_CHit, CH, Italian (Switzerland)
ro_ROro, RO, Romanian (Romania)
es_PRes, PR, Spanish (Puerto Rico)
en_CAen, CA, English (Canada)
de_DEde, DE, German (Germany)
gaga, Irish
de_LUde, LU, German (Luxembourg)
dede, German
es_ARes, AR, Spanish (Argentina)
sksk, Slovak
ms_MYms, MY, Malay (Malaysia)
hr_HRhr, HR, Croatian (Croatia)
en_SGen, SG, English (Singapore)
dada, Danish
mtmt, Maltese
plpl, Polish
ar_OMar, OM, Arabic (Oman)
trtr, Turkish
th_THth, TH, Thai (Thailand,TH)
elel, Greek
msms, Malay
sv_SEsv, SE, Swedish (Sweden)
da_DKda, DK, Danish (Denmark)
es_HNes, HN, Spanish (Honduras)


Other Grails Tag Examples


Tags: Grails Tag, localeSelect