From 20e50e16353facb072555788766e1652f1152869 Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 13 Jun 2006 22:40:23 +0000 Subject: [PATCH] Added support for referencing other translation messages directly from a translation message. So you can define something like: m.coins = Doubloons m.buy_coins = Purchase {m.coins} and then later override m.coins and all instances of it will be properly changed. Very useful for our rebranding efforts. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1858 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/servlet/MessageManager.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/java/com/samskivert/servlet/MessageManager.java b/src/java/com/samskivert/servlet/MessageManager.java index a21633da..e5a838e4 100644 --- a/src/java/com/samskivert/servlet/MessageManager.java +++ b/src/java/com/samskivert/servlet/MessageManager.java @@ -150,16 +150,17 @@ public class MessageManager return getMessage(req, key, args); } - // load up the matching resource bundles (the array will contain - // the site-specific resources first and the application resources - // second); use the locale preferred by the client if possible + // load up the matching resource bundles (the array will contain the + // site-specific resources first and the application resources second); + // use the locale preferred by the client if possible ResourceBundle[] bundles = resolveBundles(req); + String message = null; if (bundles != null) { int blength = bundles.length; - for (int i = 0; i < blength; i++) { + for (int i = 0; message == null && i < blength; i++) { try { if (bundles[i] != null) { - return bundles[i].getString(path); + message = bundles[i].getString(path); } } catch (MissingResourceException mre) { // no complaints, just try the bundle in the enclosing @@ -168,6 +169,26 @@ public class MessageManager } } + // if we found a message, check it for embedded message links + if (message != null) { + int oidx = -1; + while ((oidx = message.indexOf("{", oidx+1)) != -1) { + int cidx = message.indexOf("}", oidx+1); + if (cidx == -1) { + // something's funny, just stop fiddling + break; + } + String ref = message.substring(oidx+1, cidx); + if (ref.length() > 0 && !Character.isDigit(ref.charAt(0))) { + String refmsg = getMessage(req, ref, true); + message = message.substring(0, oidx) + + refmsg + message.substring(cidx+1); + oidx += refmsg.length(); + } + } + return message; + } + if (reportMissing) { // if there's no translation for this path, complain about it Log.warning("Missing translation message [path=" + path +