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