||This page (and all pages in the Tech: namespace) is a developer discussion about a feature that is either proposed for inclusion in JAMWiki or one that has already been implemented. This page is NOT documentation of JAMWiki functionality - for a list of documentation, see Category:JAMWiki.
|Status of this feature
: IMPLEMENTED. This feature was included with JAMWiki 0.5.0
Allow users to select a default language, rather than relying solely on browser locale.
The code is now in the Subversion trunk repository, is running on jamwiki.org, and will be included in JAMWiki 0.5.0. Language can be changed either by appending "?locale=locale" to a JAMWiki URL, or by modifying default locale from the Special:Account page.
User should be able to specific their preferred language. Currently translations default to whatever language is specified by the browser. See also Tech:Preferred Language.
- I added a Spring LocaleChangeInterceptor in svn. The language can be changed by appending a request parameter 'locale'. For example
will switch to german language.
- This should be made accessible by the user interface. However, it's already useful if JAMWiki is embedded in another application (e.g. portal). -- Rainer 12-Dec-2006 02:37 PST
- I just took a quick look at the Spring Javadoc so this may be incorrect, but as I understand things, to use the LocaleChangeInterceptor programatically the only step is to make sure that the session attribute LOCALE_SESSION_ATTRIBUTE_NAME has a value set to the user's preferred locale? If that's the case then it's easy enough to implement this functionality, and I can add a "Default locale" option to the Special:Account page. My inclination would be to store that value in the jam_wiki_user table since I think it's a Wiki specific value - do LDAP or other authentication systems typically store a "preferred locale" or default language field? -- Ryan 12-Dec-2006 22:52 PST
- Right, you can set the session attribute or call setLocale() on the controller. Note that there are other LocaleResolvers like CookieLocaleResolver, which stores the Locale in a browser cookie. I chose SessionLocaleResolver because a session exists already, but another resolver might serve your needs better.
- Regarding whether JAMWiki should store a default locale: Some environments will store the default locale in a central location. Portals will do it, it's common for SSO environments, and it is easily possible using LDAP. Can JAMWiki's default locale be overridden from extern, e.g. by a request parameter? Will that change be applied to the current session only, or will it change the stored default locale? Maybe the easiest solution is to use CookieLocaleResolver, which will store the selected locale permanantly (on a given browser) without the need for a database backed solution and without interfering with SSO and LDAP. -- Rainer 13-Dec-2006 05:24 PST
- Since users may log on from different machines I don't know if a cookie-based solution is the best option - ideally a user could choose a default locale and have it automatically set everytime they log in. Perhaps adding it to the jam_wiki_user table and allowing the value to be overridden (as you've suggested) is the best option? Then if a user wanted to change locale they could just modify their account settings, as Mediawiki does it. -- Ryan 13-Dec-2006 22:31 PST
- Sounds good. It should be possible to change the (current) locale without using the user account form, though. If JAMWiki is embedded in a portal the portal server must be able to change the current user language in JAMWiki if the portal's locale is changed. As long as the LocalChangeInterceptor still works it doesn't matter whether the locale is stored in the session or a cookie, and whether it is initialized from database. -- Rainer 13-Dec-2006 23:06 PST
- I've added code to allow a user to choose a default locale, but it doesn't do anything yet - I had problems getting that part working. Even with the new code it's still possible to set the locale using your trick of passing a "request=de" parameter in the URL, or by setting the session value. Let me know if you have any comments. -- Ryan 14-Dec-2006 23:41 PST
- Everything should now be working and is running on jamwiki.org. Note that anyone who has already upgraded to a JAMWiki 0.5.x beta will need to manually modify their database by executing the command "alter table jam_wiki_user add column default_locale VARCHAR(8)". Let me know you have any feedback or problems. -- Ryan 16-Dec-2006 09:46 PST
- Is the Utilities (method .buildLocale("en_US")) class which is used in the JFlexParserTest missing in SVN? (ok it's only a test class but not complete) --Axel Kramer 16-Dec-2006 14:49 PST
- Are you sure it's missing? I'm not at home at the moment, but browsing the Subversion repository shows the method is present. Maybe I'm misunderstanding the problem... -- Ryan 16-Dec-2006 15:58 PST
- it seems to be a missing import statement in JFlexParserTest:
- OK, thanks for fixing it! I hadn't built using the junit target, so sorry for missing that! -- Ryan 17-Dec-2006 10:09 PST