Re: Localization & URLs for Default Language
Rafael Bugajewski <[email protected]> Fri, 6 Sep 2019 13:21:54 +0200
| Newsgroups | gmane.comp.java.tapestry.user |
|---|---|
| Message-ID | <[email protected]> |
Hello Cezary,
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:
@Match("PersistentLocale")
public static void adviseNullForDefaultLanguage(MethodAdviceReceiver =
receiver) {
MethodAdvice advice =3D new MethodAdvice() {
public void advise(MethodInvocation invocation) {
invocation.proceed();
if (invocation.getReturnValue() !=3D null && =
invocation.getReturnValue().equals("en")) {
invocation.setReturnValue(null);
}
}
};
for (Method m : receiver.getInterface().getMethods()) {
if (m.getName().equals("get"))
receiver.adviseMethod(m, advice);
}
}
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.
Any ideas what I=E2=80=99m doing wrong?
Best,
Rafael
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]