001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2013 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * SonarQube is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * SonarQube is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public License
017     * along with this program; if not, write to the Free Software Foundation,
018     * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019     */
020    package org.sonar.api.i18n;
021    
022    import org.sonar.api.BatchComponent;
023    import org.sonar.api.ServerComponent;
024    import org.sonar.api.rules.Rule;
025    
026    import javax.annotation.CheckForNull;
027    
028    import java.util.Locale;
029    
030    /**
031     * {@link I18n}-companion component that provides translation facilities for rule names, descriptions and parameter names.
032     * 
033     * @since 3.2
034     */
035    public interface RuleI18n extends ServerComponent, BatchComponent {
036    
037      /**
038       * Returns the localized name of the rule identified by its repository key and rule key.
039       * <br>
040       * If the name is not found in the given locale, then the default name is returned (the English one).
041       * This method could return null if no default name found. This is the cause for instance the copies rules.
042       *
043       * @param repositoryKey the repository key
044       * @param ruleKey the rule key
045       * @param locale the locale to translate into
046       * @return the translated name of the rule, or the default English one if the given locale is not supported, or null
047       */
048      @CheckForNull
049      String getName(String repositoryKey, String ruleKey, Locale locale);
050    
051      /**
052       * Returns the localized name or the name of the rule.
053       * <br>
054       * If the name is not found in the given locale, then the default name is returned (the English one).
055       * It the default name is not found, then the rule name is returned.
056       *
057       * @param rule the rule
058       * @param locale the locale to translate into
059       * @return the translated name of the rule, or the default English one if the given locale is not supported, or the rule name.
060       */
061      @CheckForNull
062      String getName(Rule rule, Locale locale);
063    
064      /**
065       * Returns the localized description of the rule identified by its repository key and rule key.
066       * <br>
067       * If the description is not found in the given locale, then the default description is returned (the English one).
068       * As a rule must have a description (this is a constraint in Sonar), this method never returns null.
069       *
070       * @param repositoryKey the repository key
071       * @param ruleKey the rule key
072       * @param locale  the locale to translate into
073       * @return the translated description of the rule, or the default English one if the given locale is not supported
074       */
075      String getDescription(String repositoryKey, String ruleKey, Locale locale);
076    
077      /**
078       * Returns the localized name of the rule parameter identified by the rules's key and repository key, and by the parameter key.
079       * <br>
080       * If the name is not found in the given locale, then the English translation is searched and return if found. Otherwise,
081       * this method returns null (= if no translation can be found).
082       *
083       * @param repositoryKey the repository key
084       * @param ruleKey the rule key
085       * @param paramKey the parameter key
086       * @param locale the locale to translate into
087       * @return the translated name of the rule parameter, or the default English one if the given locale is not supported, or null if
088       *         no translation can be found.
089       */
090      @CheckForNull
091      String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale);
092    
093    }