forked from Revxrsal/Lamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator.java
130 lines (117 loc) · 4.29 KB
/
Translator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* This file is part of lamp, licensed under the MIT License.
*
* Copyright (c) Revxrsal <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package revxrsal.commands.locales;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* Represents a translator. A translator allows localizing messages, adding
* bundles, registering custom locales, and changing the default locale.
*/
public interface Translator {
/**
* Creates a new {@link Translator}
*
* @return The newly created translator
*/
static @NotNull Translator create() {
return new SimpleTranslator();
}
/**
* Returns the message that corresponds to the given key, using
* the current {@link #getLocale()}. If no such message is found,
* the key will be returned.
*
* @param key Message key to fetch with
* @return The translated message, or the key if not found.
*/
@NotNull String get(@NotNull String key);
/**
* Returns the message that corresponds to the given key, using
* the given locale. If no such message is found, the key will
* be returned.
*
* @param key Message key to fetch with
* @param locale Locale to get with
* @return The translated message, or the key if not found.
*/
@NotNull String get(@NotNull String key, @NotNull Locale locale);
/**
* Adds the given locale reader to this translator.
*
* @param reader The locale reader to add
*/
void add(@NotNull LocaleReader reader);
/**
* Registers the given resource bundle
*
* @param resourceBundle Resource bundle to register
*/
void add(@NotNull ResourceBundle resourceBundle);
/**
* Adds the given resource bundle. This will only register for the
* given {@link Locale}s.
* <p>
* For example, if you have the following files:
* <ul>
* <li>foo_en_US.properties</li>
* <li>foo_fr.properties</li>
* <li>foo_de.properties</li>
* </ul>
* The resource bundle will be "foo", and locales will be
* each {@link Locales#ENGLISH}, {@link Locales#FRENCH} and {@link Locales#GERMAN}.
*
* @param resourceBundle Resource bundle to register
* @param locales Locales to register for
*/
void addResourceBundle(@NotNull String resourceBundle, @NotNull Locale... locales);
/**
* Adds the given resource bundle. This will automatically check for all
* locales in {@link Locales}.
* <p>
* For example, if you have the following files:
* <ul>
* <li>foo_en_US.properties</li>
* <li>foo_fr.properties</li>
* <li>foo_de.properties</li>
* </ul>
* The resource bundle will be "foo", and all bundles will
* be parsed automatically.
*
* @param resourceBundle Resource bundle to register
*/
void addResourceBundle(@NotNull String resourceBundle);
/**
* Gets the current, default locale used by this translator
*
* @return The default locale
*/
@NotNull Locale getLocale();
/**
* Sets the locale of this translator.
*
* @param locale The locale of this translator
*/
void setLocale(@NotNull Locale locale);
}