Re: Localization & URLs for Default Language
Rafael Bugajewski <[email protected]> Fri, 6 Sep 2019 13:28:07 +0200
| Newsgroups | gmane.comp.java.tapestry.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, I was comparing a Locale with a String, so please forget my previous = message ;) Everything works as expected now. Thanks for this great idea that is = much more lightweight than writing a link transformer. Best, Rafael > On 2019-06-09, at 01:21 PM, Rafael Bugajewski = <[email protected]> wrote: >=20 > Hello Cezary, >=20 > that=E2=80=99s actually a great idea. I tried to add a service = advisor, but it doesn=E2=80=99t seem to do what I want: >=20 > @Match("PersistentLocale") > public static void adviseNullForDefaultLanguage(MethodAdviceReceiver = receiver) { > MethodAdvice advice =3D new MethodAdvice() { > public void advise(MethodInvocation invocation) { > invocation.proceed(); >=20 > if (invocation.getReturnValue() !=3D null && = invocation.getReturnValue().equals("en")) { > invocation.setReturnValue(null); > } > } > }; >=20 > for (Method m : receiver.getInterface().getMethods()) { > if (m.getName().equals("get")) > receiver.adviseMethod(m, advice); > } > } >=20 > The basic idea was that a method called "get" on the service called = "PersistentLocale" returns null if the return value from the = implementation is "en", but actually nothing happens. >=20 > Any ideas what I=E2=80=99m doing wrong? >=20 > Best, > Rafael >=20 >=20 >> On 2019-06-09, at 12:10 PM, Cezary Biernacki <[email protected]> = wrote: >>=20 >> You can always decorate PersistentLocale and change behaviour of = get() by >> returning null from it, when the original result is your default = locale. >>=20 >> Cezary >>=20 >>=20 >> On Fri, Sep 6, 2019 at 10:45 AM Rafael Bugajewski = <[email protected]> >> wrote: >>=20 >>> Hello, >>>=20 >>> Tapestry supports putting the current locale into the URL path. = I=E2=80=99m >>> injecting PersistentLocale and switching between languages as = advised in >>> the documentation: >>>=20 >>> if (persistentLocale.get() =3D=3D null) { >>> persistentLocale.set(new Locale("de")); >>> } else if = ("en".equalsIgnoreCase(persistentLocale.get().getLanguage())) { >>> persistentLocale.set(new Locale("de")); >>> } else { >>> persistentLocale.set(new Locale("en")); >>> } >>>=20 >>> The problem is that the default language should not have a prefixed = URL >>> path. When the user goes to https://example.com/ the default = language is >>> rendered and it is the desired behavior. When I switch the URL = becomes >>> https://example.com/de/ which is also OK. But now when I try to = switch >>> back to English (to the default language), the URL becomes >>> https://example.com/en/ which I don=E2=80=99t want. Trying to set = Locale.ROOT as >>> the locale for the default language after switching from German = doesn=E2=80=99t >>> work, because "" (which Locale.ROOT effectively represents) isn=E2=80=99= t >>> configured in SymbolConstants.SUPPORTED_LOCALES. >>>=20 >>> The only thing I=E2=80=99ve seen are some older threads where = PersistentLocale was >>> copied, pasted & adjusted to allow null parameters. Is this = workaround the >>> only way to go or is there an official, Tapestry way to not have the = locale >>> in the URL path for the default language? >>>=20 >>> Best, >>> Rafael >>>=20 >>>=20 >>> = --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>>=20 >>>=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]