Skip to content

Commit 3daa75a

Browse files
committed
BE Crowdin 支持
1 parent 6c2a263 commit 3daa75a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@
275275
<targetPath>native</targetPath>
276276
<filtering>false</filtering>
277277
</resource>
278+
<resource>
279+
<directory>crowdin</directory>
280+
<targetPath>crowdin</targetPath>
281+
<filtering>false</filtering>
282+
</resource>
278283
</resources>
279284
</build>
280285

src/main/java/com/ghostchu/peerbanhelper/text/TextManager.java

+29
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public void load() {
130130
languageFilesManager.deploy("en_us", loadBuiltInFallback());
131131
// second, load the bundled language files
132132
loadBundled().forEach(languageFilesManager::deploy);
133+
loadBundledCrowdin().forEach(languageFilesManager::deploy);
133134
// then, load the translations from Crowdin
134135
// and don't forget fix missing
135136
languageFilesManager.fillMissing(loadBuiltInFallback());
@@ -230,6 +231,34 @@ private Map<String, YamlConfiguration> loadBundled() {
230231
return availableLang;
231232
}
232233

234+
/**
235+
* Loading translations from bundled resources
236+
*
237+
* @return The bundled translations, empty hash map if nothing can be load.
238+
*/
239+
@NotNull
240+
@SneakyThrows
241+
private Map<String, YamlConfiguration> loadBundledCrowdin() {
242+
Map<String, YamlConfiguration> availableLang = new HashMap<>();
243+
URL url = Main.class.getClassLoader().getResource("");
244+
if (url == null) {
245+
return availableLang;
246+
}
247+
PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(Main.class.getClassLoader());
248+
var res = resourcePatternResolver.getResources("classpath:crowdin/**/*.yml");
249+
for (Resource re : res) {
250+
String langName = URLUtil.getParentName(re.getURI());
251+
try {
252+
YamlConfiguration configuration = new YamlConfiguration();
253+
configuration.loadFromString(new String(re.getContentAsByteArray(), StandardCharsets.UTF_8));
254+
availableLang.put(langName.toLowerCase(Locale.ROOT).replace("-", "_"), configuration);
255+
} catch (IOException | InvalidConfigurationException e) {
256+
log.warn("Failed to load bundled Crowdin translation.", e);
257+
}
258+
}
259+
return availableLang;
260+
}
261+
233262
/**
234263
* Generate the override files storage path
235264
*

0 commit comments

Comments
 (0)