Skip to content

Commit 4058c46

Browse files
committed
Fix TextManager
1 parent 2016011 commit 4058c46

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,13 @@
975975
<version>4.9.1</version>
976976
<scope>compile</scope>
977977
</dependency>
978+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
979+
<dependency>
980+
<groupId>commons-io</groupId>
981+
<artifactId>commons-io</artifactId>
982+
<version>2.11.0</version>
983+
<scope>compile</scope>
984+
</dependency>
978985

979986
</dependencies>
980987
</project>

src/main/java/org/maxgamer/quickshop/util/language/text/TextManager.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.maxgamer.quickshop.util.language.text;
22

33
import com.dumptruckman.bukkit.configuration.json.JsonConfiguration;
4+
import org.apache.commons.io.IOUtils;
45
import org.apache.commons.lang.StringUtils;
56
import org.bukkit.Bukkit;
67
import org.bukkit.command.CommandSender;
@@ -20,7 +21,7 @@
2021

2122
import java.io.File;
2223
import java.io.IOException;
23-
import java.io.InputStream;
24+
import java.io.InputStreamReader;
2425
import java.nio.charset.StandardCharsets;
2526
import java.util.*;
2627
import java.util.logging.Level;
@@ -49,9 +50,8 @@ public void load() {
4950
postProcessors.clear();
5051
// Load mapping
5152
//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)));
5555
} catch (IOException | InvalidConfigurationException ex) {
5656
bundledLang = new JsonConfiguration();
5757
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) {
169169
@NotNull
170170
public List<String> forLocale(@NotNull String locale) {
171171
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+
}
176188
}
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+
183190
}
184191

185192
@NotNull
@@ -246,25 +253,29 @@ private String postProcess(@NotNull String text) {
246253
@NotNull
247254
public String forLocale(@NotNull String locale) {
248255
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);
251267
if (str == null)
252-
return "Fallback Missing Language Key: " + path + ", report to QuickShop!";
268+
return "Missing Language Key: " + path;
269+
return postProcess(str);
253270
}
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);
260271
}
261272

262273
@NotNull
263274
public String forLocale() {
264275
if (sender instanceof Player) {
265276
return forLocale(((Player) sender).getLocale());
266277
} else {
267-
return forLocale("en");
278+
return forLocale("en-US");
268279
}
269280
}
270281

0 commit comments

Comments
 (0)