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
This commit is contained in:
@@ -150,16 +150,17 @@ public class MessageManager
|
|||||||
return getMessage(req, key, args);
|
return getMessage(req, key, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load up the matching resource bundles (the array will contain
|
// load up the matching resource bundles (the array will contain the
|
||||||
// the site-specific resources first and the application resources
|
// site-specific resources first and the application resources second);
|
||||||
// second); use the locale preferred by the client if possible
|
// use the locale preferred by the client if possible
|
||||||
ResourceBundle[] bundles = resolveBundles(req);
|
ResourceBundle[] bundles = resolveBundles(req);
|
||||||
|
String message = null;
|
||||||
if (bundles != null) {
|
if (bundles != null) {
|
||||||
int blength = bundles.length;
|
int blength = bundles.length;
|
||||||
for (int i = 0; i < blength; i++) {
|
for (int i = 0; message == null && i < blength; i++) {
|
||||||
try {
|
try {
|
||||||
if (bundles[i] != null) {
|
if (bundles[i] != null) {
|
||||||
return bundles[i].getString(path);
|
message = bundles[i].getString(path);
|
||||||
}
|
}
|
||||||
} catch (MissingResourceException mre) {
|
} catch (MissingResourceException mre) {
|
||||||
// no complaints, just try the bundle in the enclosing
|
// 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 (reportMissing) {
|
||||||
// if there's no translation for this path, complain about it
|
// if there's no translation for this path, complain about it
|
||||||
Log.warning("Missing translation message [path=" + path +
|
Log.warning("Missing translation message [path=" + path +
|
||||||
|
|||||||
Reference in New Issue
Block a user