On Mar 4, 2004, at 11:00 AM, [EMAIL PROTECTED] wrote:
Curt,
That sounds like an interesting approach. Unfortunately, I am not completely following what you are saying regarding regular expressions in a HashMap. Would you mind giving a simple example of one of your log messages to clarify your approach?
If you had a message that was fixed text, then the matching regular expression would be the original message and the replacement pattern would be the localized message. So if you did,
log.warn("Hello, world");
You might have an external resource that would have an entry like:
<message match="Hello, world">
<translation xml:lang="fr">Bonjour de monde</translation>
</message>If you had a message with a parameterized section:
if (log.isWarnEnabled()) {
log.warn("Elapsed time " + elapsed.toString() + " ms");
}Then your resource might contain
<message match="Elapsed time (.*) ms">
<translation xml:lang="fr">Temps �coul� \1 ms</translation>
</message>Your appender would be configured with the resource containing the translations and a locale, it would read all the entries and place the translation entries in a hash map keyed with a small initial fixed fragment of the match pattern, likely two or three characters. You would likely have multiple messages for the same key, so you would need to support arrays for values.
When a message is rendered, you would the first two or three characters to get you a relatively small set of patterns, you would evaluate if the message matched any of the patterns and if so you would use the replacement pattern to generate the localized message.
For this approach to work, you need:
1. Message that do not start with parameterized text. If you need to support those, you could fallback on a brute force evaluation of all available matching patterns if the hashmap lookup doesn't find a match.
2. Messages that are not effected by locale settings.
3. Avoid parameterized values that are difficult to localize using regular expressions. For example, you would want to use a date representation like "03/04/2004" instead of "Thursday, March 4, 2004". The first would be fairly simple to transform to "04/03/2004"
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
