Index: core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- core/src/main/java/com/xpn/xwiki/XWiki.java (revision 1952)
+++ core/src/main/java/com/xpn/xwiki/XWiki.java (copie de travail)
@@ -2581,7 +2581,7 @@
             if (bundle == null) {
                 bundle = ResourceBundle.getBundle("ApplicationResources");
             }
-            XWikiMessageTool msg = new XWikiMessageTool(bundle);
+            XWikiMessageTool msg = new XWikiMessageTool(bundle, context);
             context.put("msg", msg);
             VelocityContext vcontext = ((VelocityContext) context.get("vcontext"));
             if (vcontext != null) {
Index: core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java
===================================================================
--- core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java  (revision 1952)
+++ core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java  (copie de travail)
@@ -18,23 +18,122 @@
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  *
  */
-
-package com.xpn.xwiki.web;
-
-import java.util.ResourceBundle;
-
-public class XWikiMessageTool {
-    private ResourceBundle bundle;
-
-    public XWikiMessageTool(ResourceBundle bundle) {
-      this.bundle = bundle;
-    }
-
-    public String get(String key) {
-        try {
-         return bundle.getString(key);
-        } catch (Exception e) {
-            return key;
-        }
-    }
-}
+
+package com.xpn.xwiki.web;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Properties;
+import java.util.ResourceBundle;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+public class XWikiMessageTool {
+    private static final String KEY = "bundledoc";
+
+    private ResourceBundle bundle;
+
+    private XWikiContext context;
+
+    private String previousDocName = "";
+
+    private Date previousDocDate = new Date();
+
+    private boolean needsRefresh = true;
+
+    private Properties cache = null;
+
+    public XWikiMessageTool(ResourceBundle bundle, XWikiContext context) {
+        this.bundle = bundle;
+        this.context = context;
+    }
+
+    /**
+     * Tries to retrieve the bundle document. This is done by looking for the
+     * document name in the preferences, then appending the current language.
+     * @return the bundle document, null if the document cannot be found
+     */
+    private XWikiDocument getBundleDocument() {
+        XWikiDocument bundleDoc = null;
+        String keyName = context.getWiki().getXWikiPreference(KEY, context);
+        if (keyName != null && !keyName.equals("")) {
+            String lang = context.getWiki().getDocLanguagePreference(context);
+            String docName = keyName + "_" + lang;
+            try {
+                //First, looks for a document suffixed by the language
+                bundleDoc = context.getWiki().getDocument(docName, context);
+                if (!bundleDoc.isNew()) {
+                    // Checks for a name update
+                    if (!previousDocName.equals(docName)) {
+                        needsRefresh = true;
+                        this.previousDocName = docName;
+                    }
+                    Date docDate = bundleDoc.getDate();
+                    // Check for a doc modification
+                    if (!previousDocDate.equals(docDate)) {
+                        needsRefresh = true;
+                        this.previousDocDate = docDate;
+                    }
+                } else {
+                    //If not found, looks for the default document
+                    bundleDoc = context.getWiki().getDocument(keyName, context);
+                    if (!bundleDoc.isNew()) {
+                        // Checks for a name update
+                        if (!previousDocName.equals(keyName)) {
+                            needsRefresh = true;
+                            this.previousDocName = keyName;
+                        }
+                        Date docDate = bundleDoc.getDate();
+                        // Check for a doc modification
+                        if (!previousDocDate.equals(docDate)) {
+                            needsRefresh = true;
+                            this.previousDocDate = docDate;
+                        }
+                    } else {
+                        return null;
+                    }
+                }
+            } catch (XWikiException e) {
+                // Doc not found, discard
+            }
+        }
+        return bundleDoc;
+    }
+
+    private String findTranslation(String key) {
+        XWikiDocument bundleDoc = getBundleDocument();
+        if (needsRefresh) {
+            // Cache needs to be updated
+            cache = new Properties();
+            if (bundleDoc != null) {
+                String content = bundleDoc.getContent();
+                InputStream is = new ByteArrayInputStream(content.getBytes());
+                try {
+                    cache.load(is);
+                } catch (IOException e) {
+                    // Cannot do anything
+                }
+            }
+            needsRefresh = false;
+        }
+        // get from cache
+        return cache.getProperty(key);
+    }
+
+    public String get(String key) {
+        String translation = findTranslation(key);
+        if (translation == null) {
+            try {
+                translation = bundle.getString(key);
+            } catch (Exception e) {
+                translation = key;
+            }
+        }
+        return translation;
+    }
+
+}
