Re: about multi-language support

Jonathan Revusky <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
On Tue, Jul 6, 2010 at 3:41 PM, PeiSong <[email protected]> wrote:
> Does it affect the performance?

Well, yes. Of course it does. There are probably two extra hash
lookups (possibly synchronized). Whether the difference is important
is just a practical question. You'd have to measure it.

> On a website there may be hundreds of translations, if all turn into dynamic keys/values, may slow down the speed right?

Well, it certainly is slower. The code in the class I pointed to can
be adapted, of course. If it comes down to one or two extra hash table
lookups, it will probably not be a performance bottleneck in most web
applications. Probably.

But I can't really answer that. It is something you have to measure in
your application.

> Also need inject the resources manually in each controller.
> What's the best practice for it? Thank you.

I don't know what most people do. I wrote that
ResourceBundleLocalizedString class a long time ago and nobody ever
asks about it. You know, I think that what most multilingual web apps
do (and really, I'm just guessing) is that they build up the data
model each time for each page request, and based on the preferred
locale of the page request, the data model contains different strings.
So, probably most people aren't using the approach that you see in
that class.

But... in the above, I am just guessing. I really do not know what
most people do. :-)

Maybe some people will tell you now. (I hope.)

JR

>
> On Jul 6, 2010, at 9:17 PM, Jonathan Revusky wrote:
>
>> On Tue, Jul 6, 2010 at 2:53 PM, PeiSong <[email protected]> wrote:
>>> Seems so. But I guess this class is for internal use?
>>
>> No, it's not just for internal use. It was really just meant as an
>> example. It can also be directly used.
>>
>>
>>> So how can I use localizedString in the template? Any sample code? thank you.
>>
>> Just new them and put them directly in your data model if you want.
>> Something like:
>>
>> model.put("some_key", new ResourceBundleLocalizedString("some_key",
>> "my_resource_bundle_lookup_key"));
>>
>> (Though the above is obviously verbose and you would probably
>> encapsulate this in your code somehow. Also you could define a
>> trivial subclass of DefaultObjectWrapper that actually wraps strings this way.)
>>
>> JR
>>
>>>
>>> On Jul 6, 2010, at 8:24 PM, Jonathan Revusky wrote:
>>>
>>>> It's certainly possible to do this quite cleanly. Just as an example,
>>>> look at the surce code for the class
>>>> freemarker.template.ResourceBundleLocalizedString
>>>>
>>>> JR
>>>>
>>>> On Tue, Jul 6, 2010 at 12:05 PM, PeiSong <[email protected]> wrote:
>>>>> Hi,
>>>>>
>>>>> Does freemarker support resouce bundle to load language keys/values?
>>>>>
>>>>> If we use multiple templates we hv to change each template when there are any changes, I don't think it's a good idea. Thank you.
>>>>>
>>>>> PeiSong
>>>>> ------------------------------------------------------------------------------
>>>>> This SF.net email is sponsored by Sprint
>>>>> What will you do first with EVO, the first 4G phone?
>>>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>>>>> _______________________________________________
>>>>> FreeMarker-user mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> This SF.net email is sponsored by Sprint
>>>> What will you do first with EVO, the first 4G phone?
>>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>>>> _______________________________________________
>>>> FreeMarker-user mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> This SF.net email is sponsored by Sprint
>>> What will you do first with EVO, the first 4G phone?
>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>>> _______________________________________________
>>> FreeMarker-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>> _______________________________________________
>> FreeMarker-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.