001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2014 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    
025    import javax.annotation.Nullable;
026    
027    import java.util.Date;
028    import java.util.Locale;
029    
030    /**
031     * Main component that provides translation facilities.
032     *
033     * @since 2.10
034     */
035    public interface I18n extends ServerComponent, BatchComponent {
036    
037      /**
038       * Searches the message of the <code>key</code> for the <code>locale</code> in the list of available bundles.
039       * <br>
040       * If not found in any bundle, <code>defaultValue</code> is returned.
041       * <p/>
042       * If additional parameters are given (in the objects list), the result is used as a message pattern
043       * to use in a MessageFormat object along with the given parameters.
044       *
045       * @param locale       the locale to translate into
046       * @param key          the key of the pattern to translate
047       * @param defaultValue the default pattern returned when the key is not found in any bundle
048       * @param parameters   the parameters used to format the message from the translated pattern.
049       * @return the message formatted with the translated pattern and the given parameters
050       */
051      String message(final Locale locale, final String key, @Nullable final String defaultValue, final Object... parameters);
052    
053      /**
054       * Return the distance in time for a duration in milliseconds.
055       * <br>
056       * Examples :
057       * <ul>
058       * <li>age(Locale.ENGLISH, 1000) -> less than a minute</li>
059       * <li>age(Locale.ENGLISH, 60000) -> about a minute</li>
060       * <li>age(Locale.ENGLISH, 120000) -> 2 minutes</li>
061       * <li>age(Locale.ENGLISH, 3600000) -> about an hour</li>
062       * <li>age(Locale.ENGLISH, 7200000) -> 2 hours</li>
063       * <li>age(Locale.ENGLISH, 86400000) -> a day</li>
064       * <li>age(Locale.ENGLISH, 172800000) -> 2 days</li>
065       * </ul>
066       *
067       * @since 4.2
068       */
069      String age(Locale locale, long durationInMillis);
070    
071      /**
072       * Return the distance in time between two dates.
073       *
074       * @see I18n#age(java.util.Locale, long durationInMillis)
075       * @since 4.2
076       */
077      String age(Locale locale, Date fromDate, Date toDate);
078    
079      /**
080       * Reports the distance in time a date and now.
081       *
082       * @see I18n#age(java.util.Locale, java.util.Date, java.util.Date)
083       * @since 4.2
084       */
085      String ageFromNow(Locale locale, Date date);
086    
087      /**
088       * Return the formatted datetime.
089       * <br>
090       * Example : formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100")) -> Jan 22, 2014 7:10 PM
091       *
092       * @since 4.2
093       */
094      String formatDateTime(Locale locale, Date date);
095    
096      /**
097       * Return the formatted date.
098       * <br>
099       * Example : formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22")) -> Jan 22, 2014
100       *
101       * @since 4.2
102       */
103      String formatDate(Locale locale, Date date);
104    
105      /**
106       * Return the formatted decimal, with always one fraction digit.
107       * <br>
108       * Example : formatDouble(Locale.FRENCH, 10.56) -> 10,6
109       *
110       * @since 4.4
111       */
112      String formatDouble(Locale locale, Double value);
113    
114      /**
115       * Return the formatted integer.
116       * <br>
117       * Example : formatInteger(Locale.ENGLISH, 100000) -> 100,000
118       *
119       * @since 4.4
120       */
121      String formatInteger(Locale locale, Integer value);
122    
123    }