001/* 002 * SonarQube 003 * Copyright (C) 2009-2017 SonarSource SA 004 * mailto:info AT sonarsource DOT com 005 * 006 * This program 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 * This program 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 java.util.Date; 023import java.util.Locale; 024import javax.annotation.Nullable; 025import org.sonar.api.batch.ScannerSide; 026import org.sonar.api.ce.ComputeEngineSide; 027import org.sonar.api.server.ServerSide; 028 029/** 030 * Main component that provides translation facilities. 031 * 032 * @since 2.10 033 */ 034@ScannerSide 035@ServerSide 036@ComputeEngineSide 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 * <br> 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 * <p> 092 * Example: {@code formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))} 093 * returns {@code "Jan 22, 2014 7:10 PM"}. 094 * </p> 095 * 096 * @since 4.2 097 */ 098 String formatDateTime(Locale locale, Date date); 099 100 /** 101 * Return the formatted date. 102 * <br> 103 * Example: {@code formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22"))} 104 * returns {@code "Jan 22, 2014"}. 105 * 106 * @since 4.2 107 */ 108 String formatDate(Locale locale, Date date); 109 110 /** 111 * Return the formatted decimal, with always one fraction digit. 112 * <br> 113 * Example: {@code formatDouble(Locale.FRENCH, 10.56)} returns {@code "10,6"}. 114 * 115 * @since 4.4 116 */ 117 String formatDouble(Locale locale, Double value); 118 119 /** 120 * Return the formatted integer. 121 * <br> 122 * Example: {@code formatInteger(Locale.ENGLISH, 100000)} returns {@code "100,000"}. 123 * 124 * @since 4.4 125 */ 126 String formatInteger(Locale locale, Integer value); 127 128}