BrightSide Workbench Full Report + Source Code
I18nCompatibilityWrapper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.i18n;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Locale;
24 
30 
31  public String get(String msg) {
32  if(msg == null) return null;
33  return i18nApiWrapper.get(I18nCompatibilityKey.instance().getOrDefault(msg, msg));
34  }
35 
36  public String get(String msg, int count) {
37  if(msg == null) return null;
38  return i18nApiWrapper.get(I18nCompatibilityKey.instance().getOrDefault(msg, msg), count);
39  }
40 
41  public String format(String msg, Object... arguments) {
42  if(msg == null) return null;
43  return i18nApiWrapper.format(I18nCompatibilityKey.instance().getOrDefault(msg, msg), arguments);
44  }
45 
46  public String get(Locale locale, String msg) {
47  if(msg == null) return null;
48  return i18nApiWrapper.get(locale, I18nCompatibilityKey.instance().getOrDefault(msg, msg));
49  }
50 
51  public String get(Locale locale, String msg, int count) {
52  if(msg == null) return null;
53  return i18nApiWrapper.get(locale, I18nCompatibilityKey.instance().getOrDefault(msg, msg), count);
54  }
55 
56  public String format(Locale locale, String msg, Object... arguments) {
57  if(msg == null) return null;
58  return i18nApiWrapper.get(locale, I18nCompatibilityKey.instance().getOrDefault(msg, msg));
59  }
60 
61  public List<String> getInLocales(String msg) {
62  if(msg == null) return Collections.EMPTY_LIST;
63  return i18nApiWrapper.getInLocales(I18nCompatibilityKey.instance().getOrDefault(msg, msg), I18nContext.getSiteLocales());
64  }
65 
66  /* Factory */
67 
68  private final I18nApiWrapper i18nApiWrapper;
69 
70  public static I18nCompatibilityWrapper from(I18nApiWrapper i18nApiWrapper) {
71  return new I18nCompatibilityWrapper(i18nApiWrapper);
72  }
73 
74  private I18nCompatibilityWrapper(I18nApiWrapper i18nApiWrapper) {
75  this.i18nApiWrapper = i18nApiWrapper;
76  }
77 
78 }
static I18nCompatibilityKey instance()
static I18nCompatibilityWrapper from(I18nApiWrapper i18nApiWrapper)
String format(String msg, Object... arguments)
String format(Locale locale, String msg, Object... arguments)
static List< Locale > getSiteLocales()