Index: src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- src/main/java/com/xpn/xwiki/XWiki.java	(révision 1952)
+++ 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: src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java
===================================================================
--- src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java	(révision 1952)
+++ src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java	(copie de travail)
@@ -18,23 +18,162 @@
  * 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.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+public class XWikiMessageTool {
+
+    private static final String KEY = "bundledocs";
+
+    private ResourceBundle bundle;
+
+    private XWikiContext context;
+
+    private Map previousDates = new HashMap(); // <Long, Date>
+
+    private Map propsCache = new HashMap(); // <Long, Properties>
+
+    private Set docsToRefresh = new HashSet(); // <Long>
+
+    public XWikiMessageTool(ResourceBundle bundle, XWikiContext context) {
+        this.bundle = bundle;
+        this.context = context;
+    }
+
+    /**
+     * Tries first to get the preference "bundledocs" in the wiki preferences.
+     * If not found, this method tries to found the the entry in the config file
+     * under the key "xwiki.bundledocs". Value should be a list of XWiki pages
+     * separated by commas : e.g. : XWiki.trans1,XWiki.trans2,...
+     * 
+     * @return the list of translation documents
+     */
+    private String findDocNamesPreference() {
+        String docNames = context.getWiki().getXWikiPreference(KEY, context);
+        if (docNames == null || "".equals(docNames)) {
+            docNames = context.getWiki().Param("xwiki." + KEY);
+        }
+        return docNames;
+    }
+
+    /**
+     * Retrieve a list of bundle documents. This is done by looking for the
+     * document names in the preferences, then looking for the translated
+     * versions of these documents.
+     * 
+     * @return the bundle documents if at least one can be found, else an empty
+     *         list
+     */
+    private List getBundleDocuments() {
+        XWikiDocument bundleDoc = null;
+        List result = new ArrayList();
+        String docNames = findDocNamesPreference();
+        if (docNames != null) {
+            List docNamesList = Arrays.asList(docNames.split(","));
+            Iterator it = docNamesList.iterator();
+            while (it.hasNext()) {
+                String docName = ((String) it.next()).trim();
+                if (!docName.equals("")) {
+                    try {
+                        // First, looks for a document suffixed by the language
+                        bundleDoc = context.getWiki().getDocument(docName,
+                                context);
+                        bundleDoc = bundleDoc.getTranslatedDocument(context);
+                        if (!bundleDoc.isNew()) {
+                            // Checks for a name update
+                            Long docId = new Long(bundleDoc.getId());
+                            Date docDate = bundleDoc.getDate();
+                            // Check for a doc modification
+                            if (!docDate.equals(previousDates.get(docId))) {
+                                docsToRefresh.add(docId);
+                                previousDates.put(docId, docDate);
+                            }
+                        }
+                        result.add(bundleDoc);
+                    } catch (XWikiException e) {
+                        // Doc not found, discard
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Looks for a translation in the list of documents. It first checks if the
+     * translation can be found in the cache.
+     * 
+     * @param key
+     *            the key identifying the translation
+     * @return the translation or null if not found
+     */
+    private String findTranslation(String key) {
+        if (key == null) {
+            return null;
+        }
+        List bundleDocs = getBundleDocuments();
+        Iterator it = bundleDocs.iterator();
+        while (it.hasNext()) {
+            XWikiDocument bundleDoc = (XWikiDocument) it.next();
+            Long docId = new Long(bundleDoc.getId());
+            Properties props = null;
+            if (docsToRefresh.contains(docId) || !propsCache.containsKey(docId)) {
+                // Cache needs to be updated
+                props = new Properties();
+                if (bundleDoc != null) {
+                    String content = bundleDoc.getContent();
+                    InputStream is = new ByteArrayInputStream(content
+                            .getBytes());
+                    try {
+                        props.load(is);
+                    } catch (IOException e) {
+                        // Cannot do anything
+                    }
+                }
+                // updates cache
+                propsCache.put(docId, props);
+                docsToRefresh.remove(docId);
+            } else {
+                // gets from cache
+                props = (Properties) propsCache.get(docId);
+            }
+            String trad = props.getProperty(key);
+            if (trad != null) {
+                return trad;
+            }
+        }
+        return null;
+    }
+
+    public String get(String key) {
+        String translation = findTranslation(key);
+        if (translation == null) {
+            try {
+                translation = bundle.getString(key);
+            } catch (Exception e) {
+                translation = key;
+            }
+        }
+        return translation;
+    }
+
+}
