Wednesday, July 04, 2012

Pentaho CE ReportViewer Localization is not localizing

When creating reports and publishing them under Pentaho it would be nice if you could localize the web interface just like for dashboards etc...

This showed out not to be as simple as expected.

I spent some time searching Google and then I posted the following forum post at How to translate the remaining labels on the ReportViewer. I was pretty busy for a few days and then I went back and searched Google some more and it seemed like I missed a pretty obvious link Report Viewer Localization. After following this only just doing the steps on the pentaho-reporting-engine-classic-core-platform-plugin-4.1.0-stable.jar file some of the labels were translated.

All was however not well since there was quite a few labels and strings that could be localized still. Searching inside all the jar files for specific strings led me to belive that I needed to translate some messages.properties files in the pentaho-reporting-engine-classic-core-3.8.3-GA.jar file as well.

This task was a bit larger than the previous jar file so I was pretty satisfied when it was time to upload the file to the server and test it. My woes were not over yet though, and nothing I did seemed to work. I contacted some knowledgeable Pentaho developers at Sigma Infosolutions and asked them if they could have a look at the problem and it showed out that a small code change was required in the Pentaho code to make the localization work.

Index: Messages.java
===================================================================
--- Messages.java (revision 662)
+++ Messages.java (working copy)
@@ -1,36 +1,38 @@
-// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 7/2/2012 5:25:55 PM
-// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
-// Decompiler options: packimports(3) 
-// Source File Name:   Messages.java
-
-package org.pentaho.reporting.engine.classic.core.parameters;
-
-import java.util.Locale;
-
-import org.pentaho.reporting.libraries.base.util.ObjectUtilities;
-import org.pentaho.reporting.libraries.base.util.ResourceBundleSupport;
-
-public class Messages extends ResourceBundleSupport
-{
-  private static Messages instance;
-
-  public static Messages getInstance()
-  {
-    // its ok that this one is not synchronized. I dont care whether we have multiple instances of this
-    // beast sitting around, as this is a singleton for convinience reasons.
-    if (instance == null)
-    {
-      instance = new Messages();
-    }
-    return instance;
-  }
-
-  /**
-   * Creates a new instance.
-   */
-  private Messages()
-  {
-    super(Locale.getDefault(), "org.pentaho.reporting.engine.classic.core.parameters.messages",
-        ObjectUtilities.getClassLoader(Messages.class));
-  }
-}
+// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 7/2/2012 5:25:55 PM
+// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
+// Decompiler options: packimports(3) 
+// Source File Name:   Messages.java
+
+package org.pentaho.reporting.engine.classic.core.parameters;
+
+import org.pentaho.platform.util.messages.LocaleHelper;
+
+import org.pentaho.reporting.libraries.base.util.ObjectUtilities;
+import org.pentaho.reporting.libraries.base.util.ResourceBundleSupport;
+
+public class Messages extends ResourceBundleSupport
+{
+  private static Messages instance;
+
+  public static Messages getInstance()
+  {
+    // its ok that this one is not synchronized. I dont care whether we have multiple instances of this
+    // beast sitting around, as this is a singleton for convinience reasons.
+ /*Changed the singleton Instance to the non-singleton Instance by removing the if(instance=null) condition */    
+ //if (instance == null)
+    //{
+      instance = new Messages();
+    //}
+    return instance;
+  }
+
+  /**
+   * Creates a new instance.
+   */
+  private Messages()
+  {
+ /*Changed the Locale.getDefault() to LocaleHelper.getLocale() in order to localize the parameters according to the selected locale*/
+    super(LocaleHelper.getLocale(), "org.pentaho.reporting.engine.classic.core.parameters.messages",
+        ObjectUtilities.getClassLoader(Messages.class));
+  }
+}