]> source.dussan.org Git - sonarqube.git/commitdiff
New API for Ruby and Java side
authorDavid Festal <david.festal@serli.com>
Thu, 16 Jun 2011 13:02:53 +0000 (15:02 +0200)
committerDavid Festal <david.festal@serli.com>
Mon, 4 Jul 2011 20:52:55 +0000 (22:52 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb

index 8438b706622ad3edf24bd5ff79567ffb549f8aea..c66ae9c134a7e6a2be73a2b3da0642a2ad3df8a8 100644 (file)
@@ -138,11 +138,14 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension
     }
   }
 
-  public String message(final Locale locale, final String key, final String defaultText, final Object... objects) {
+  public String message(final Locale locale, final String key, final String defaultText, final Object... objects)
+  {
     String result = defaultText;
     try {
       String bundleBaseName = keys.get(key);
       if (bundleBaseName == null) {
+        if (result == null)
+          throw new MissingResourceException("UNKNOWN KEY : Key '" + key + "' not found in any bundle.", bundleBaseName, key);
         LOG.warn("UNKNOWN KEY : Key '{}' not found in any bundle. Default value '{}' is returned.", key, defaultText);
         unknownKeys.put(key, defaultText);
       } else {
@@ -151,18 +154,24 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension
 
           String value = bundle.getString(key);
           if ("".equals(value)) {
+            if (result == null)
+              throw new MissingResourceException("VOID KEY : Key '" + key + "' (from bundle '" + bundleBaseName + "') returns a void value.", bundleBaseName, key);
             LOG.warn("VOID KEY : Key '{}' (from bundle '{}') returns a void value. Default value '{}' is returned.", new Object[]{key,
                 bundleBaseName, defaultText});
           } else {
             result = value;
           }
         } catch (MissingResourceException e) {
+          if (result == null)
+            throw e;
           LOG.warn("BUNDLE NOT LOADED : Failed loading bundle {} from classloader {}. Default value '{}' is returned.", new Object[]{
               bundleBaseName, bundleClassLoader, defaultText});
         }
       }
     } catch (Exception e) {
       LOG.error("Exception when retrieving I18n string.", e);
+      if (result == null)
+        throw new SonarException("Exception when retrieving I18n string.", e);
     }
 
     if (objects.length > 0) {
index 9eddc51e56a2be1093ad89527ee1437f220276ce..38000871ab71d2fba1df4b93234df9daba4d0d46 100644 (file)
@@ -56,8 +56,13 @@ module ApplicationHelper
   end
 
   # i18n
-  def message(key, default, *parameters)
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().getI18nMessage(I18n.locale, key, default, parameters.to_java)
+  def message(key, options={})
+    default = options[:default]
+    params = options[:params]
+    if params.nil? 
+      params=[]
+    end
+    Java::OrgSonarServerUi::JRubyFacade.getInstance().getI18nMessage(I18n.locale, key, default, params.to_java)    
   end
 
   # deprecated since 2.5. Use trend_icon() instead
index 5a09ff6a1f36cf82a7ecdc8bbc8f2df3cbe113f8..f9e160f2c3ecae910af0e4d60befbf70c2ae1641 100644 (file)
@@ -14,7 +14,7 @@
       &raquo; <a href="<%= ApplicationController.root_context -%>/sessions/logout">Log out</a>
       </li>
       <% else %>
-      <li><a href="<%= ApplicationController.root_context -%>/sessions/new"><%= message('app.view.layouts.layout.login', 'Log in') -%></a></li>
+      <li><a href="<%= ApplicationController.root_context -%>/sessions/new"><%= message('web.layouts.login', :default => 'Log {0}', :params => ['in']) -%></a></li>
       <% end %>
       <li><a href="<%= ApplicationController.root_context -%>/profiles">Configuration</a></li>
     </ol>