You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by oliverw <ol...@weichhold.com> on 2008/02/15 19:52:36 UTC
Multiple Homepage Mountpoints for Localization
Hi
I just wanted to make sure that my idea makes some sense if implemented this
way. My prerequisites:
1. I want to mount my homepage and all it's children (which are not that
many) multiple times at different mountpoints
2. Each mountpoint is prefixed with a language identifier which ultimately
decides in which language the content is presented (the site consists to 95%
of dynamic content which resides pre-localized in a database). Example:
http://domain.com -> homepage english
http://domain.com/items -> item info page english
http://domain.com/de -> homepage german
http://domain.com/de/items-> item info page german
In order to achieve the desired behavior I've subclassed the WebRequestCycle
like shown below. Since I'm still pretty new to wicket, I would like to know
if this is how it should be done the "Wicket Way" or if there's a better
solution.
class MyRequestCycle extends WebRequestCycle
{
public MyRequestCycle(WebApplication application, WebRequest request,
Response response)
{
super(application, request, response);
// init locale map
mapPatch2Locale = new HashMap<String, Locale>();
mapPatch2Locale.put("de", Locale.GERMAN);
mapPatch2Locale.put("fr", Locale.FRENCH);
mapPatch2Locale.put("es", new Locale("es"));
}
/** Maps Request Path to associated Locale **/
HashMap<String, Locale> mapPatch2Locale;
protected void onBeginRequest()
{
super.onBeginRequest();
// adjust locale to url prefix
String path = getRequest().getPath();
Locale locale = null;
Set<String> keys = mapPatch2Locale.keySet();
while(keys.iterator().hasNext())
{
String _path = keys.iterator().next();
if(path.equals(_path) || path.startsWith(_path + "/"))
{
locale = mapPatch2Locale.get(_path);
break;
}
}
// default is english
if(locale == null)
locale = Locale.ENGLISH;
// setup locale for this request
getSession().setLocale(locale);
}
}
--
View this message in context: http://www.nabble.com/Multiple-Homepage-Mountpoints-for-Localization-tp15507606p15507606.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Multiple Homepage Mountpoints for Localization
Posted by oliverw <ol...@weichhold.com>.
Possible. Although I have to admit that the HybridUrlCodingStrategy source
code looks quite intimidating :) Without debugging through the whole thing I
do not even know where to begin.
Jonathan Locke wrote:
>
>
> what about writing or subclassing a url coding strategy to use the first
> part of the url to set the session's locale?
>
>
> oliverw wrote:
>>
>> Hi
>>
>> I just wanted to make sure that my idea makes some sense if implemented
>> this way. My prerequisites:
>>
>> 1. I want to mount my homepage and all it's children (which are not that
>> many) multiple times at different mountpoints
>> 2. Each mountpoint is prefixed with a language identifier which
>> ultimately decides in which language the content is presented (the site
>> consists to 95% of dynamic content which resides pre-localized in a
>> database). Example:
>>
>> http://domain.com -> homepage english
>> http://domain.com/items -> item info page english
>>
>> http://domain.com/de -> homepage german
>> http://domain.com/de/items-> item info page german
>>
>> In order to achieve the desired behavior I've subclassed the
>> WebRequestCycle like shown below. Since I'm still pretty new to wicket, I
>> would like to know if this is how it should be done the "Wicket Way" or
>> if there's a better solution.
>>
>> class MyRequestCycle extends WebRequestCycle
>> {
>> public MyRequestCycle(WebApplication application, WebRequest request,
>> Response response)
>> {
>> super(application, request, response);
>>
>> // init locale map
>> mapPatch2Locale = new HashMap<String, Locale>();
>> mapPatch2Locale.put("de", Locale.GERMAN);
>> mapPatch2Locale.put("fr", Locale.FRENCH);
>> mapPatch2Locale.put("es", new Locale("es"));
>> }
>>
>> /** Maps Request Path to associated Locale **/
>> HashMap<String, Locale> mapPatch2Locale;
>>
>> protected void onBeginRequest()
>> {
>> super.onBeginRequest();
>>
>> // adjust locale to url prefix
>> String path = getRequest().getPath();
>> Locale locale = null;
>>
>> Set<String> keys = mapPatch2Locale.keySet();
>> while(keys.iterator().hasNext())
>> {
>> String _path = keys.iterator().next();
>> if(path.equals(_path) || path.startsWith(_path + "/"))
>> {
>> locale = mapPatch2Locale.get(_path);
>> break;
>> }
>> }
>>
>> // default is english
>> if(locale == null)
>> locale = Locale.ENGLISH;
>>
>> // setup locale for this request
>> getSession().setLocale(locale);
>> }
>> }
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Multiple-Homepage-Mountpoints-for-Localization-tp15507606p15509840.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Multiple Homepage Mountpoints for Localization
Posted by Jonathan Locke <jo...@gmail.com>.
what about writing or subclassing a url coding strategy to use the first
part of the url to set the session's locale?
oliverw wrote:
>
> Hi
>
> I just wanted to make sure that my idea makes some sense if implemented
> this way. My prerequisites:
>
> 1. I want to mount my homepage and all it's children (which are not that
> many) multiple times at different mountpoints
> 2. Each mountpoint is prefixed with a language identifier which ultimately
> decides in which language the content is presented (the site consists to
> 95% of dynamic content which resides pre-localized in a database).
> Example:
>
> http://domain.com -> homepage english
> http://domain.com/items -> item info page english
>
> http://domain.com/de -> homepage german
> http://domain.com/de/items-> item info page german
>
> In order to achieve the desired behavior I've subclassed the
> WebRequestCycle like shown below. Since I'm still pretty new to wicket, I
> would like to know if this is how it should be done the "Wicket Way" or if
> there's a better solution.
>
> class MyRequestCycle extends WebRequestCycle
> {
> public MyRequestCycle(WebApplication application, WebRequest request,
> Response response)
> {
> super(application, request, response);
>
> // init locale map
> mapPatch2Locale = new HashMap<String, Locale>();
> mapPatch2Locale.put("de", Locale.GERMAN);
> mapPatch2Locale.put("fr", Locale.FRENCH);
> mapPatch2Locale.put("es", new Locale("es"));
> }
>
> /** Maps Request Path to associated Locale **/
> HashMap<String, Locale> mapPatch2Locale;
>
> protected void onBeginRequest()
> {
> super.onBeginRequest();
>
> // adjust locale to url prefix
> String path = getRequest().getPath();
> Locale locale = null;
>
> Set<String> keys = mapPatch2Locale.keySet();
> while(keys.iterator().hasNext())
> {
> String _path = keys.iterator().next();
> if(path.equals(_path) || path.startsWith(_path + "/"))
> {
> locale = mapPatch2Locale.get(_path);
> break;
> }
> }
>
> // default is english
> if(locale == null)
> locale = Locale.ENGLISH;
>
> // setup locale for this request
> getSession().setLocale(locale);
> }
> }
>
>
--
View this message in context: http://www.nabble.com/Multiple-Homepage-Mountpoints-for-Localization-tp15507606p15508899.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org