import org.sonar.batch.ServerMetadata;
import org.sonar.batch.config.BatchDatabaseSettingsLoader;
import org.sonar.batch.config.BatchSettings;
+import org.sonar.core.i18n.I18nManager;
+import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.persistence.DaoUtils;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.MyBatis;
addCoreSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(JdbcDriverHolder.class);
addCoreSingleton(EmailSettings.class);
+ addCoreSingleton(I18nManager.class);
+ addCoreSingleton(RuleI18nManager.class);
URLClassLoader bootstrapClassLoader = getComponentByType(JdbcDriverHolder.class).getClassLoader();
// set as the current context classloader for hibernate, else it does not find the JDBC driver.
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.i18n.I18n;
import org.sonar.api.platform.PluginMetadata;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
-import java.util.*;
-
-public class I18nManager implements I18n, ServerExtension {
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+public class I18nManager implements I18n, ServerExtension, BatchExtension {
private static final Logger LOG = LoggerFactory.getLogger(I18nManager.class);
public static final String ENGLISH_PACK_PLUGIN_KEY = "l10nen";
return null;
}
-
ClassLoader getClassLoaderForProperty(String propertyKey) {
String bundleKey = propertyToBundles.get(propertyKey);
return (bundleKey != null ? bundleToClassloaders.get(bundleKey) : null);
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.ServerComponent;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.i18n.RuleI18n;
import java.util.List;
import java.util.Locale;
-public class RuleI18nManager implements ServerComponent {
+public class RuleI18nManager implements RuleI18n, ServerExtension, BatchExtension {
private static final String NAME_SUFFIX = ".name";
private static final String RULE_PREFIX = "rule.";
*/
package org.sonar.api.i18n;
+import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import java.util.Locale;
/**
+ * Main component that provides translation facilities.
+ *
* @since 2.10
*/
-public interface I18n extends ServerComponent {
+public interface I18n extends ServerComponent, BatchComponent {
/**
* Searches the message of the <code>key</code> for the <code>locale</code> in the list of available bundles.
* If additional parameters are given (in the objects list), the result is used as a message pattern
* to use in a MessageFormat object along with the given parameters.
*
- * @param locale the locale to translate into
- * @param key the key of the pattern to translate
+ * @param locale the locale to translate into
+ * @param key the key of the pattern to translate
* @param defaultValue the default pattern returned when the key is not found in any bundle
- * @param parameters the parameters used to format the message from the translated pattern.
+ * @param parameters the parameters used to format the message from the translated pattern.
* @return the message formatted with the translated pattern and the given parameters
*/
String message(final Locale locale, final String key, final String defaultValue, final Object... parameters);
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.i18n;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+
+import java.util.Locale;
+
+/**
+ * {@link I18n}-companion component that provides translation facilities for rule names, descriptions and parameter names.
+ *
+ * @since 3.2
+ */
+public interface RuleI18n extends ServerComponent, BatchComponent {
+
+ /**
+ * Returns the localized name of the rule identified by its repository key and rule key.
+ * <br>
+ * If the name is not found in the given locale, then the default name is returned (the English one).
+ * As a rule must have a name (this is a constraint in Sonar), this method never returns null.
+ *
+ * @param repositoryKey the repository key
+ * @param ruleKey the rule key
+ * @param locale the locale to translate into
+ * @return the translated name of the rule, or the default English one if the given locale is not supported
+ */
+ String getName(String repositoryKey, String ruleKey, Locale locale);
+
+ /**
+ * Returns the localized description of the rule identified by its repository key and rule key.
+ * <br>
+ * If the description is not found in the given locale, then the default description is returned (the English one).
+ * As a rule must have a description (this is a constraint in Sonar), this method never returns null.
+ *
+ * @param repositoryKey the repository key
+ * @param ruleKey the rule key
+ * @param locale the locale to translate into
+ * @return the translated description of the rule, or the default English one if the given locale is not supported
+ */
+ String getDescription(String repositoryKey, String ruleKey, Locale locale);
+
+ /**
+ * Returns the localized name of the rule parameter identified by the rules's key and repository key, and by the parameter key.
+ * <br>
+ * If the name is not found in the given locale, then the English translation is searched and return if found. Otherwise,
+ * this method returns null (= if no translation can be found).
+ *
+ * @param repositoryKey the repository key
+ * @param ruleKey the rule key
+ * @param paramKey the parameter key
+ * @param locale the locale to translate into
+ * @return the translated name of the rule parameter, or the default English one if the given locale is not supported, or null if
+ * no translation can be found.
+ */
+ String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale);
+
+}