RE: I18n/l10n

"Aapo Laakkonen" <[email protected]>
Newsgroups gmane.comp.web.maverick.general
Organization ProjectCast Oy
Message-ID <002601c381cf$b371d120$ee5241c1@zodiac>
> But what if there would not be just one message
> but instead one message (selected at runtime)
> out of a possible number of messages.

Can you show me use case of this?

> The view would then have to either [1] select
> the localized message at runtime or [2]
> include every possible message at compiletime
> and display one of them based on some property
> returned at runtime.

No it doesn't, I can write code like this:

#if (${errors.username})
	@error.username@
#else
	@welcome@ $!{user.name}
#end

Then the right message is selected at runtime. No resource bundle
lookups.

> And [2] - if I realize correctly - is just like [1],
> it would still require some ResourceBundle-like
> functionality (which ofcourse could be implemented
> using Velocity macros).

#err and #msg macros are only intended to provide string replacements,
of cource I can write dynamic replacements also (based on locale and
text in resource bundle):

#msg("@text.with.replacements@", ["@welcome@"])

And resource bundle would then look like this:

@welcome@=a welcome message
@text.with.replacements@=This is {1}

And it would render:

This is a welcome message

and with finnish bundle:

@welcome@=tervetuloviesti
@text.with.replacements@=Tämä on {1}

it would render:

Tämä on tervetuloviesti

All those @...@ are replaced with ant replace task in build time and
site is generated for each resource bundle e.g.:

fi/index.vm
en/index.vm

And the correct template is chosen in runtime with maverick's shunting.

> Anyway, it's not really a problem, just something
> I was thinking about > since your "build-time" approach
> looks interesting enough to consider.

Do you still see problems with this?

-----Oorspronkelijk bericht-----
Van: Aapo Laakkonen [mailto:[email protected]]
Verzonden: Tuesday, September 23, 2003 12:54 PM
Aan: [email protected]
Onderwerp: RE: [Mav-user] I18n/l10n

> At the moment, I use a combination of (1) and (2).
> A disadvantage of (4) - if I see it correctly -
> is that I create messages at runtime (f.e. validation
> error messages) and it would be more complicated in
> the view if I had to create them at compiletime.

Yes, but as I see those validation messages come from resource bundles?

So that makes me wondering how would it make it more complicated.

Here is example what I'm thinking (in velocity):

<html>
<head><title>@title@</title></head>
<body>
<h1>@welcome.message@</h1>
<p>
#if (${errors.message})
	#err("@error.message@", ["$!{user.name}"])
#else
	#msg("@user.details@"), ["$!{user.name}", "$!{user.age}"]); #end
</p> </body> </html>

And here is the resource bundle:

@title@=TITLE
@welcome.message@=HELLO
@error.message@=User {1} was not found in db.
@user.details@=Hi {1}, it seems that your are getting older, {2} years
behind and counting.

#err and #msg are velocity macros that do parameter replaces. As you
see, the static messages are translated build-time and parameter
replacing happens in runtime.

Another possibility would be to write #evel macro and then everything
looks like this:

<html>
<head><title>@title@</title></head>
<body>
<h1>@welcome.message@</h1>
<p>
#if (${errors.message})
	#eval("@error.message@")
#else
	#eval("@user.details@");
#end
</p>
</body>
</html>

And resource bundle looks like this:

@title@=TITLE
@welcome.message@=HELLO
@error.message@=User $!{user.name} was not found in db.
@user.details@=Hi $!{user.name}, it seems that your are getting older,
$!{user.age} years behind and counting.


What do you think?



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
[INVALID FOOTER]
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.