Re: I18N for bookmarkable urls
Yes the solution could work but is no more applicable to Wicket 1.5 since it now uses Mapper instead of old fashioned Url Coding Strategies. I've tried to hack around but I've found no point where to add a default parameter to all the web pages that's the Locale. Also, the BookmarkableLink, for example, should address this issue. If al pages are mounted like ${language}/products/${category} I need the link to take care of this. The whole purpose is for SEO reason, we need google to crawl correctly all the website in all of the languages. So I've to add language as parameter in all links. Of course I can just extend and have my I18NBookmarcableLink. I am wondering about a nicer solution. Any ideas? On Mon, Oct 26, 2009 at 9:08 PM, Ilja Pavkovic ilja.pavko...@binaere-bauten.de wrote: Hi, a better solution (in my eyes.. :)) is something like: import java.util.Locale; import org.apache.wicket.IRequestTarget; import org.apache.wicket.Page; import org.apache.wicket.Session; import org.apache.wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy; public class I18NBookmarkablePageRequestTargetUrlCodingStrategy extends BookmarkablePageRequestTargetUrlCodingStrategy { private Locale locale; public C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass) { this(locale, mountPath, bookmarkablePageClass, null); } private C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass, String pageMapName) { super(mountPath, bookmarkablePageClass, pageMapName); this.locale = locale; } //public IRequestTarget decode(RequestParameters requestParameters) public boolean matches(IRequestTarget requestTarget) { boolean matches = super.matches(requestTarget); if(matches) { matches = locale == null || locale.equals(Session.get().getLocale()) || // also match en and en_US locale.getLanguage().equals(Session.get().getLocale().getLanguage()); } return matches; } } you can use it with: mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.GERMAN,startseite,getHomePage())); mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.ENGLISH,homepage,getHomePage())); Be warned: this is only a hack that may break at your site :)) Am Montag, 26. Oktober 2009 15:25:49 schrieb Bernhard Grünewaldt: Hello, After thinking a bit I came up with a solution (which many of you might call dirty workaround). But since no one else came up with a solution I will stick to it until something better will be provided. The solution can be found here: http://blog.gruenewaldt.net/en/programming/java/apache-wicket-1_4-mounting- urls-for-a-multilanguage-setup-i18n-seo/ Perhaps someone might find that useful. Bernhard Bernhard Grünewaldt schrieb: Hi folks, Since my app will be english and german aswell, that is something I need too. I tried to mount and unmount my pages when the locale changes from german to english or vice versa. I tried using ResourceModel Strings for the urls, but it's not working the way I want it to be. And it would be a massive amount of code for something that seems to be so simple. The problem is, that I want both urls to be accessed via the url like in the example: http://xxx/impressum and http://xxx/imprint should be accessible not depending on a specific locale setting. (Perhaps the locale should change to english or german depending on the url when accessed via a browser bookmark with no session) The problem is, that you can mount a class multiple times, but for creating the BookmarkablePageLinks the first one mounted will be used for the link. (tested with wicket 1.4.3). Wouldn't it be cool to have such a mechanism which uses the Locale setting to generate links and mount pages. For example (Just pseudo code): .mount( new HybridUrlCodingStrategy( impressum, ImprintPage.class, Locale.GERMAN) ); .mount( new HybridUrlCodingStrategy( imprint, ImprintPage.class, Locale.ENGLISH) ); And when you then generate a url you could use: add(new BookmarkablePageLinkVoid( bookmarked, ImprintPage.class, getSession().getLocale()) ); That way both urls would be accessible if bookmarked. And the user gets the url generated in his locale while browsing through the app. Is there a cool(=easy) way to do that or will it lead to a massive code section that mounts and unmounts pages on locale change? Bernhard Ilja Pavkovic
Re: I18N for bookmarkable urls
Ah, I also tried to llok at MountedMapper that has a protected newPageParameters() trying to add there a new parameter with locale but that didn't worked, I couldn't see any moment when the method is actually called while the application is running On Tue, Oct 11, 2011 at 11:34 AM, Daniele Dellafiore dani...@dellafiore.net wrote: Yes the solution could work but is no more applicable to Wicket 1.5 since it now uses Mapper instead of old fashioned Url Coding Strategies. I've tried to hack around but I've found no point where to add a default parameter to all the web pages that's the Locale. Also, the BookmarkableLink, for example, should address this issue. If al pages are mounted like ${language}/products/${category} I need the link to take care of this. The whole purpose is for SEO reason, we need google to crawl correctly all the website in all of the languages. So I've to add language as parameter in all links. Of course I can just extend and have my I18NBookmarcableLink. I am wondering about a nicer solution. Any ideas? On Mon, Oct 26, 2009 at 9:08 PM, Ilja Pavkovic ilja.pavko...@binaere-bauten.de wrote: Hi, a better solution (in my eyes.. :)) is something like: import java.util.Locale; import org.apache.wicket.IRequestTarget; import org.apache.wicket.Page; import org.apache.wicket.Session; import org.apache.wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy; public class I18NBookmarkablePageRequestTargetUrlCodingStrategy extends BookmarkablePageRequestTargetUrlCodingStrategy { private Locale locale; public C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass) { this(locale, mountPath, bookmarkablePageClass, null); } private C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass, String pageMapName) { super(mountPath, bookmarkablePageClass, pageMapName); this.locale = locale; } //public IRequestTarget decode(RequestParameters requestParameters) public boolean matches(IRequestTarget requestTarget) { boolean matches = super.matches(requestTarget); if(matches) { matches = locale == null || locale.equals(Session.get().getLocale()) || // also match en and en_US locale.getLanguage().equals(Session.get().getLocale().getLanguage()); } return matches; } } you can use it with: mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.GERMAN,startseite,getHomePage())); mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.ENGLISH,homepage,getHomePage())); Be warned: this is only a hack that may break at your site :)) Am Montag, 26. Oktober 2009 15:25:49 schrieb Bernhard Grünewaldt: Hello, After thinking a bit I came up with a solution (which many of you might call dirty workaround). But since no one else came up with a solution I will stick to it until something better will be provided. The solution can be found here: http://blog.gruenewaldt.net/en/programming/java/apache-wicket-1_4-mounting- urls-for-a-multilanguage-setup-i18n-seo/ Perhaps someone might find that useful. Bernhard Bernhard Grünewaldt schrieb: Hi folks, Since my app will be english and german aswell, that is something I need too. I tried to mount and unmount my pages when the locale changes from german to english or vice versa. I tried using ResourceModel Strings for the urls, but it's not working the way I want it to be. And it would be a massive amount of code for something that seems to be so simple. The problem is, that I want both urls to be accessed via the url like in the example: http://xxx/impressum and http://xxx/imprint should be accessible not depending on a specific locale setting. (Perhaps the locale should change to english or german depending on the url when accessed via a browser bookmark with no session) The problem is, that you can mount a class multiple times, but for creating the BookmarkablePageLinks the first one mounted will be used for the link. (tested with wicket 1.4.3). Wouldn't it be cool to have such a mechanism which uses the Locale setting to generate links and mount pages. For example (Just pseudo code): .mount( new HybridUrlCodingStrategy( impressum, ImprintPage.class, Locale.GERMAN) ); .mount( new HybridUrlCodingStrategy( imprint, ImprintPage.class, Locale.ENGLISH) ); And when you then generate a url you could use: add(new BookmarkablePageLinkVoid( bookmarked,
Re: I18N for bookmarkable urls
Hello, After thinking a bit I came up with a solution (which many of you might call dirty workaround). But since no one else came up with a solution I will stick to it until something better will be provided. The solution can be found here: http://blog.gruenewaldt.net/en/programming/java/apache-wicket-1_4-mounting-urls-for-a-multilanguage-setup-i18n-seo/ Perhaps someone might find that useful. Bernhard Bernhard Grünewaldt schrieb: Hi folks, Since my app will be english and german aswell, that is something I need too. I tried to mount and unmount my pages when the locale changes from german to english or vice versa. I tried using ResourceModel Strings for the urls, but it's not working the way I want it to be. And it would be a massive amount of code for something that seems to be so simple. The problem is, that I want both urls to be accessed via the url like in the example: http://xxx/impressum and http://xxx/imprint should be accessible not depending on a specific locale setting. (Perhaps the locale should change to english or german depending on the url when accessed via a browser bookmark with no session) The problem is, that you can mount a class multiple times, but for creating the BookmarkablePageLinks the first one mounted will be used for the link. (tested with wicket 1.4.3). Wouldn't it be cool to have such a mechanism which uses the Locale setting to generate links and mount pages. For example (Just pseudo code): .mount( new HybridUrlCodingStrategy( impressum, ImprintPage.class, Locale.GERMAN) ); .mount( new HybridUrlCodingStrategy( imprint, ImprintPage.class, Locale.ENGLISH) ); And when you then generate a url you could use: add(new BookmarkablePageLinkVoid( bookmarked, ImprintPage.class, getSession().getLocale()) ); That way both urls would be accessible if bookmarked. And the user gets the url generated in his locale while browsing through the app. Is there a cool(=easy) way to do that or will it lead to a massive code section that mounts and unmounts pages on locale change? Bernhard Ilja Pavkovic schrieb: Hi, as we need some SEO optimization I want to provide the following bookmarkable pages: http://xxx/impressum http://xxx/imprint the native approach would be somethink like: mountBookmarkablePage(imprint, ImprintPage.class); mountBookmarkablePage(impressum, ImprintPage.class); This looks ugly but works. Now I don't know how to create a bookmarkable links having an url in the expected language. if( getLocale().equals(Locale.GERMAN)) { //create http://xxx/impressum } else { // http://xxx/imprint } Obviously the following code does not help: add(new BookmarkablePageLink(link, ImprintPage.class)); Does anyone have a good idea? Best regards, Ilja Pavkovic - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: I18N for bookmarkable urls
Hi, a better solution (in my eyes.. :)) is something like: import java.util.Locale; import org.apache.wicket.IRequestTarget; import org.apache.wicket.Page; import org.apache.wicket.Session; import org.apache.wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy; public class I18NBookmarkablePageRequestTargetUrlCodingStrategy extends BookmarkablePageRequestTargetUrlCodingStrategy { private Locale locale; public C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass) { this(locale, mountPath, bookmarkablePageClass, null); } private C extends Page I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale locale, String mountPath, ClassC bookmarkablePageClass, String pageMapName) { super(mountPath, bookmarkablePageClass, pageMapName); this.locale = locale; } //public IRequestTarget decode(RequestParameters requestParameters) public boolean matches(IRequestTarget requestTarget) { boolean matches = super.matches(requestTarget); if(matches) { matches = locale == null || locale.equals(Session.get().getLocale()) || // also match en and en_US locale.getLanguage().equals(Session.get().getLocale().getLanguage()); } return matches; } } you can use it with: mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.GERMAN,startseite,getHomePage())); mount(new I18NBookmarkablePageRequestTargetUrlCodingStrategy(Locale.ENGLISH,homepage,getHomePage())); Be warned: this is only a hack that may break at your site :)) Am Montag, 26. Oktober 2009 15:25:49 schrieb Bernhard Grünewaldt: Hello, After thinking a bit I came up with a solution (which many of you might call dirty workaround). But since no one else came up with a solution I will stick to it until something better will be provided. The solution can be found here: http://blog.gruenewaldt.net/en/programming/java/apache-wicket-1_4-mounting- urls-for-a-multilanguage-setup-i18n-seo/ Perhaps someone might find that useful. Bernhard Bernhard Grünewaldt schrieb: Hi folks, Since my app will be english and german aswell, that is something I need too. I tried to mount and unmount my pages when the locale changes from german to english or vice versa. I tried using ResourceModel Strings for the urls, but it's not working the way I want it to be. And it would be a massive amount of code for something that seems to be so simple. The problem is, that I want both urls to be accessed via the url like in the example: http://xxx/impressum and http://xxx/imprint should be accessible not depending on a specific locale setting. (Perhaps the locale should change to english or german depending on the url when accessed via a browser bookmark with no session) The problem is, that you can mount a class multiple times, but for creating the BookmarkablePageLinks the first one mounted will be used for the link. (tested with wicket 1.4.3). Wouldn't it be cool to have such a mechanism which uses the Locale setting to generate links and mount pages. For example (Just pseudo code): .mount( new HybridUrlCodingStrategy( impressum, ImprintPage.class, Locale.GERMAN) ); .mount( new HybridUrlCodingStrategy( imprint, ImprintPage.class, Locale.ENGLISH) ); And when you then generate a url you could use: add(new BookmarkablePageLinkVoid( bookmarked, ImprintPage.class, getSession().getLocale()) ); That way both urls would be accessible if bookmarked. And the user gets the url generated in his locale while browsing through the app. Is there a cool(=easy) way to do that or will it lead to a massive code section that mounts and unmounts pages on locale change? Bernhard Ilja Pavkovic schrieb: Hi, as we need some SEO optimization I want to provide the following bookmarkable pages: http://xxx/impressum http://xxx/imprint the native approach would be somethink like: mountBookmarkablePage(imprint, ImprintPage.class); mountBookmarkablePage(impressum, ImprintPage.class); This looks ugly but works. Now I don't know how to create a bookmarkable links having an url in the expected language. if( getLocale().equals(Locale.GERMAN)) { //create http://xxx/impressum } else { // http://xxx/imprint } Obviously the following code does not help: add(new BookmarkablePageLink(link, ImprintPage.class)); Does anyone have a good idea? Best regards, Ilja Pavkovic
Re: I18N for bookmarkable urls
Hi folks, Since my app will be english and german aswell, that is something I need too. I tried to mount and unmount my pages when the locale changes from german to english or vice versa. I tried using ResourceModel Strings for the urls, but it's not working the way I want it to be. And it would be a massive amount of code for something that seems to be so simple. The problem is, that I want both urls to be accessed via the url like in the example: http://xxx/impressum and http://xxx/imprint should be accessible not depending on a specific locale setting. (Perhaps the locale should change to english or german depending on the url when accessed via a browser bookmark with no session) The problem is, that you can mount a class multiple times, but for creating the BookmarkablePageLinks the first one mounted will be used for the link. (tested with wicket 1.4.3). Wouldn't it be cool to have such a mechanism which uses the Locale setting to generate links and mount pages. For example (Just pseudo code): .mount( new HybridUrlCodingStrategy( impressum, ImprintPage.class, Locale.GERMAN) ); .mount( new HybridUrlCodingStrategy( imprint, ImprintPage.class, Locale.ENGLISH) ); And when you then generate a url you could use: add(new BookmarkablePageLinkVoid( bookmarked, ImprintPage.class, getSession().getLocale()) ); That way both urls would be accessible if bookmarked. And the user gets the url generated in his locale while browsing through the app. Is there a cool(=easy) way to do that or will it lead to a massive code section that mounts and unmounts pages on locale change? Bernhard Ilja Pavkovic schrieb: Hi, as we need some SEO optimization I want to provide the following bookmarkable pages: http://xxx/impressum http://xxx/imprint the native approach would be somethink like: mountBookmarkablePage(imprint, ImprintPage.class); mountBookmarkablePage(impressum, ImprintPage.class); This looks ugly but works. Now I don't know how to create a bookmarkable links having an url in the expected language. if( getLocale().equals(Locale.GERMAN)) { //create http://xxx/impressum } else { // http://xxx/imprint } Obviously the following code does not help: add(new BookmarkablePageLink(link, ImprintPage.class)); Does anyone have a good idea? Best regards, Ilja Pavkovic - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
I18N for bookmarkable urls
Hi, as we need some SEO optimization I want to provide the following bookmarkable pages: http://xxx/impressum http://xxx/imprint the native approach would be somethink like: mountBookmarkablePage(imprint, ImprintPage.class); mountBookmarkablePage(impressum, ImprintPage.class); This looks ugly but works. Now I don't know how to create a bookmarkable links having an url in the expected language. if( getLocale().equals(Locale.GERMAN)) { //create http://xxx/impressum } else { // http://xxx/imprint } Obviously the following code does not help: add(new BookmarkablePageLink(link, ImprintPage.class)); Does anyone have a good idea? Best regards, Ilja Pavkovic -- binaere bauten gmbh · tempelhofer ufer 1a · 10961 berlin +49 · 171 · 9342 465 Handelsregister: HRB 115854 - Amtsgericht Charlottenburg Geschäftsführer: Dipl.-Inform. Ilja Pavkovic, Dipl.-Inform. Jost Becker - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org