|
1 | 1 | package org.maxgamer.quickshop.util.language.text; |
2 | 2 |
|
3 | 3 | import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; |
| 4 | +import org.apache.commons.io.IOUtils; |
4 | 5 | import org.apache.commons.lang.StringUtils; |
5 | 6 | import org.bukkit.Bukkit; |
6 | 7 | import org.bukkit.command.CommandSender; |
|
20 | 21 |
|
21 | 22 | import java.io.File; |
22 | 23 | import java.io.IOException; |
23 | | -import java.io.InputStream; |
| 24 | +import java.io.InputStreamReader; |
24 | 25 | import java.nio.charset.StandardCharsets; |
25 | 26 | import java.util.*; |
26 | 27 | import java.util.logging.Level; |
@@ -49,9 +50,8 @@ public void load() { |
49 | 50 | postProcessors.clear(); |
50 | 51 | // Load mapping |
51 | 52 | //for (String availableFile : distribution.getAvailableFiles()) { |
52 | | - try (InputStream stream = plugin.getResource("lang-original/messages.json")) { |
53 | | - if (stream != null) |
54 | | - bundledLang.loadFromString(new String(Util.inputStream2ByteArray(stream), StandardCharsets.UTF_8)); |
| 53 | + try { |
| 54 | + bundledLang.loadFromString(new String(IOUtils.toByteArray(new InputStreamReader(plugin.getResource("lang-original/messages.json")), StandardCharsets.UTF_8))); |
55 | 55 | } catch (IOException | InvalidConfigurationException ex) { |
56 | 56 | bundledLang = new JsonConfiguration(); |
57 | 57 | plugin.getLogger().log(Level.SEVERE,"Cannot load bundled language file from Jar, some strings may missing!",ex); |
@@ -169,17 +169,24 @@ private List<String> postProcess(@NotNull List<String> text) { |
169 | 169 | @NotNull |
170 | 170 | public List<String> forLocale(@NotNull String locale) { |
171 | 171 | JsonConfiguration index = mapping.get(locale); |
172 | | - if (index == null && locale.equals("en")) { |
173 | | - List<String> str = fallbackLocal(); |
174 | | - if (str.isEmpty()) |
175 | | - return Collections.singletonList("Fallback Missing Language Key: " + path + ", report to QuickShop!"); |
| 172 | + if(index == null){ |
| 173 | + if(locale.equals("en-US")){ |
| 174 | + List<String> str = fallbackLocal(); |
| 175 | + if (str.isEmpty()) |
| 176 | + return Collections.singletonList("Fallback Missing Language Key: " + path + ", report to QuickShop!"); |
| 177 | + return postProcess(str); |
| 178 | + }else{ |
| 179 | + return forLocale("en-US"); |
| 180 | + } |
| 181 | + }else{ |
| 182 | + List<String> str = index.getStringList(locale); |
| 183 | + if(str.isEmpty()) { |
| 184 | + return Collections.singletonList("Missing Language Key: " + path); |
| 185 | + }else { |
| 186 | + return postProcess(str); |
| 187 | + } |
176 | 188 | } |
177 | | - if (index == null) |
178 | | - return forLocale("en"); |
179 | | - List<String> str = index.getStringList(locale); |
180 | | - if (str.isEmpty()) |
181 | | - return Collections.singletonList("Missing Language Key: " + path); |
182 | | - return postProcess(str); |
| 189 | + |
183 | 190 | } |
184 | 191 |
|
185 | 192 | @NotNull |
@@ -246,25 +253,29 @@ private String postProcess(@NotNull String text) { |
246 | 253 | @NotNull |
247 | 254 | public String forLocale(@NotNull String locale) { |
248 | 255 | JsonConfiguration index = mapping.get(locale); |
249 | | - if (index == null && locale.equals("en")) { |
250 | | - String str = fallbackLocal(); |
| 256 | + if(index == null){ |
| 257 | + if(locale.equals("en-US")){ |
| 258 | + String str = fallbackLocal(); |
| 259 | + if (str == null) |
| 260 | + return "Fallback Missing Language Key: " + path + ", report to QuickShop!"; |
| 261 | + return postProcess(str); |
| 262 | + }else{ |
| 263 | + return forLocale("en-US"); |
| 264 | + } |
| 265 | + }else{ |
| 266 | + String str = index.getString(locale); |
251 | 267 | if (str == null) |
252 | | - return "Fallback Missing Language Key: " + path + ", report to QuickShop!"; |
| 268 | + return "Missing Language Key: " + path; |
| 269 | + return postProcess(str); |
253 | 270 | } |
254 | | - if (index == null) |
255 | | - return forLocale("en"); |
256 | | - String str = index.getString(locale); |
257 | | - if (str == null) |
258 | | - return "Missing Language Key: " + path; |
259 | | - return postProcess(str); |
260 | 271 | } |
261 | 272 |
|
262 | 273 | @NotNull |
263 | 274 | public String forLocale() { |
264 | 275 | if (sender instanceof Player) { |
265 | 276 | return forLocale(((Player) sender).getLocale()); |
266 | 277 | } else { |
267 | | - return forLocale("en"); |
| 278 | + return forLocale("en-US"); |
268 | 279 | } |
269 | 280 | } |
270 | 281 |
|
|
0 commit comments