You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by diogoeag <di...@gmail.com> on 2011/06/30 16:13:32 UTC

Database based localization

Hi,

I'm using tapestry 5.2.5 and trying to override the a service to get
database based localization. I've searched in the forum and the solutions
present here don't work.

What service should I override? ComponentMessagesSource.class or
Messages.class?

I've tried to do as in the manual:

  @Contribute(ServiceOverride.class)
  public static void
setupApplicationServiceOverrides(MappedConfiguration&lt;Class,Object&gt;
configuration)
  {
    configuration.addInstance(ComponentMessagesSource.class,
DatabaseSource.class);
  }

But I get an error saying:

Caused by: java.lang.IllegalArgumentException: Service 'ServiceOverride' is
configured using org.apache.tapestry5.ioc.OrderedConfiguration, not
org.apache.tapestry5.ioc.MappedConfiguration.

Anyone got something like this implemented and working? Is there any other
way to do this?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Database-based-localization-tp4538988p4538988.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Database based localization

Posted by diogoeag <di...@gmail.com>.
Hi,

thanks, meanwhile I had also found that link. Thanks anyway.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Database-based-localization-tp4538988p4539938.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Database based localization

Posted by Christian Köberl <ta...@gmail.com>.
On 2011-06-30 16:13, diogoeag wrote:
> I'm using tapestry 5.2.5 and trying to override the a service to get
> database based localization. I've searched in the forum and the solutions
> present here don't work.

Did you try "T5 : Expanding Messages Catalog for localization from 
arbitrary source" (http://markmail.org/thread/frvx2mbmq34wg4xu) - I 
think this should still work.

> What service should I override? ComponentMessagesSource.class or
> Messages.class?
> I've tried to do as in the manual:
>
>    @Contribute(ServiceOverride.class)
>    public static void
> setupApplicationServiceOverrides(MappedConfiguration&lt;Class,Object&gt;
> configuration)
>    {
>      configuration.addInstance(ComponentMessagesSource.class,
> DatabaseSource.class);
>    }
>
> But I get an error saying:
>
> Caused by: java.lang.IllegalArgumentException: Service 'ServiceOverride' is
> configured using org.apache.tapestry5.ioc.OrderedConfiguration, not
> org.apache.tapestry5.ioc.MappedConfiguration.

Just tried that with a dummy implementation (returning "hello" for all 
messages) of DatabaseSource and it worked (based on 5.2.5 quickstart). 
Don't know how you get this exception!?

> Anyone got something like this implemented and working? Is there any other
> way to do this?

Another way is not to override a service but contribute to it - in this 
case to ComponentMessagesSource. In your module class you add the 
contribution:

public static void contributeComponentMessagesSource(
     OrderedConfiguration<Resource> configuration)
{
     configuration.add("DatabaseCatalog", DatabaseResource.class);
}

The problem here ist that you have to implement Resource which is made 
for file systems and not for databases but I guess it should work 
anyway. Just return some arbitary value like "db" in 'getFile' method - 
Tapestry will call 'forFile' with any locale combination relevant for 
rendering in - in this case "db_en_US", "db_en" and "db". Return the 
database values in properties format when 'openStream' is called.

Hope that works - when I think about it maybe it's better to override or 
decorate the service.

-- 
Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org