Reputation: 596
I am developing web application using Tapestry5. In my application I want to integrate multilanguage concept. I have two properties files are app_it.properties and app_fr.properties. But without value, only key.
app_it.properties
aboutus=
termsandcondns=
privacy=
app_fr.properties
aboutus=
termsandcondns=
privacy=
Here I want to set key's value at run time. That key's values getting from my database based on the country code. Is it possible to set.
Please help me.
Upvotes: 0
Views: 169
Reputation: 356
You could contribute your own implementation of org.apache.tapestry5.ioc.Resource
, which might prevent the need to use Tapestry’s internal APIs.
@Contribute(ComponentMessagesSource.class)
public static void provideMessages(OrderedConfiguration<Resource> configuration) {
configuration.add("DBMessages", new Resource() {
// implement interface methods
});
}
You could, of course, construct that Resource instance from within a separate service that provides the Resource with a database connection or whatever you want to get your messages from. The tricky bit might be how to implement methods that are clearly designed for a file/directory structure, when working with something more dynamic.
/**
* Returns a Resource based on a relative path, relative to the folder containing the resource. Understands the "."
* (current folder) and ".." (parent folder) conventions, and treats multiple sequential slashes as a single slash.
* <p/>
* Virtual resources (resources fabricated at runtime) return themselves.
*/
Resource forFile(String relativePath);
or
/**
* Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the
* Resource.
*/
String getFolder();
Well, I guess you’d have to have a peek at the Tapestry source code and look at how the existing Resource implementations work.
Upvotes: 0
Reputation: 27994
In tapestry, all services are overridable via tapestry IOC
In this instance, you will provide a custom, database based implementation of ComponentMessagesSource
If you want to completely remove the property file based functionality, you will override the ComponentMessagesSource. If not, you'll likely decorate the existing service and use a combination of property files and database values.
Upvotes: 1