codeconsole opened a new pull request, #15940:
URL: https://github.com/apache/grails-core/pull/15940

   ## Summary
   
   Grails already ships the *switch-language* half of i18n — 
`I18nAutoConfiguration` wires a `SessionLocaleResolver` and a `?lang=`-driven 
`LocaleChangeInterceptor`, and `FormTagLib` has a `g:localeSelect`. What was 
missing was a way to discover **which locales an application is actually 
translated into** (`g:localeSelect` lists all ~150 
`Locale.getAvailableLocales()`, which is not useful as a language switcher) and 
a ready-made selector in the generated app.
   
   This PR adds that discovery to `grails-i18n` and surfaces a language 
dropdown in the default `create-app` layout. Because a generated web app 
already ships the `messages_*.properties` bundles (via the forge default 
plugins / the `base` profile skeleton), a freshly created app shows a 
fully-populated language switcher out of the box with no configuration.
   
   ## Changes
   
   **`grails-i18n`**
   - New `AvailableLocaleResolver` — scans the classpath for 
`messages_*.properties` and returns the translated locales (plus the 
configurable default locale, `grails.i18n.default.locale`, default `en`), 
sorted by display name and cached.
   - `I18nAutoConfiguration` registers it as a bean 
(`@ConditionalOnMissingBean`).
   - `I18nGrailsPlugin` publishes the list to the servlet context 
(`availableLocales`) on startup and re-scans on dev-mode bundle changes. 
Reading a servlet-context attribute keeps consumers decoupled from this module 
(no new compile dependency in `grails-gsp` / `grails-forge`).
   
   **`grails-gsp`**
   - `g:localeSelect` gains an `available="true"` attribute that lists only the 
translated locales instead of every JVM locale. Default behaviour is unchanged.
   
   **Generated app (`grails-forge` template + classic `web` profile skeleton)**
   - The default `main.gsp` navbar gets a Bootstrap language dropdown that 
iterates the published locales and switches via the existing `?lang=` 
interceptor. It renders only when more than one locale is available.
   
   **Docs**
   - `localeSelect` tag reference + the "Changing Locales" guide.
   
   ## Tests
   - `AvailableLocaleResolverSpec` (resolver discovery, sorting, default 
locale, caching, immutability)
   - `LocaleSelectAvailableSpec` (`available="true"` behaviour + a render test 
of the generated navbar snippet producing correct `?lang=` links)
   - `GrailsGspSpec` gains a check that the generated layout contains the 
dropdown
   
   All green.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to