Skip to content

Commit 19e3048

Browse files
Update locale and fix wrong localization (#413)
2 parents 951a562 + 68ef642 commit 19e3048

16 files changed

Lines changed: 211 additions & 217 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "de.eldoria"
12-
version = "2.7.3"
12+
version = "2.7.4"
1313

1414
var publishModules = setOf(
1515
"schematicbrushreborn-api",

schematicbrushreborn-api/src/main/java/de/eldoria/schematicbrush/brush/config/builder/BuildUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import de.eldoria.schematicbrush.brush.config.provider.Mutator;
1111
import de.eldoria.schematicbrush.brush.config.provider.SettingProvider;
1212
import de.eldoria.schematicbrush.brush.config.util.ComponentProvider;
13-
import de.eldoria.schematicbrush.util.Colors;
1413
import org.bukkit.permissions.Permissible;
1514

1615
import java.util.List;

schematicbrushreborn-api/src/main/java/de/eldoria/schematicbrush/storage/brush/Brush.java

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import de.eldoria.schematicbrush.brush.config.builder.BrushBuilder;
1515
import de.eldoria.schematicbrush.brush.config.builder.BrushBuilderSnapshot;
1616
import de.eldoria.schematicbrush.brush.config.builder.BuildUtil;
17-
import de.eldoria.schematicbrush.util.Colors;
1817
import org.bukkit.configuration.serialization.ConfigurationSerializable;
1918
import org.bukkit.configuration.serialization.SerializableAs;
2019
import org.jetbrains.annotations.NotNull;
@@ -91,9 +90,9 @@ public static Brush deserialize(Map<String, Object> objectMap) {
9190
@NotNull
9291
public Map<String, Object> serialize() {
9392
return SerializationUtil.newBuilder()
94-
.add("name", name)
95-
.add("snapshot", snapshot)
96-
.build();
93+
.add("name", name)
94+
.add("snapshot", snapshot)
95+
.build();
9796
}
9897

9998
/**
@@ -145,61 +144,75 @@ public int compareTo(@NotNull Brush o) {
145144

146145
public String simpleComponent(BrushSettingsRegistry registry) {
147146
var sets = snapshot.schematicSets().stream()
148-
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
149-
.toList();
147+
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
148+
.toList();
150149
return MessageComposer.create()
151-
.text("<%s>%s", Colors.VALUE, description())
152-
.newLine()
153-
.text("<%s>Schematic Sets:", Colors.NAME)
154-
.newLine()
155-
.text(sets)
156-
.newLine()
157-
.text(simpleModifier(registry))
158-
.build();
150+
.text("<value>%s", description())
151+
.newLine()
152+
.text("<name>")
153+
.localeCode("words.schematicSets")
154+
.text(":")
155+
.newLine()
156+
.text(sets)
157+
.newLine()
158+
.text(simpleModifier(registry))
159+
.build();
159160
}
160161

161162
public String infoComponent(boolean global, boolean canDelete, BrushSettingsRegistry registry) {
162163
var text = MessageComposer.create()
163-
.text("<%s><hover:show_text:'%s'>%s</hover>", Colors.NAME, simpleComponent(registry), name())
164-
.space()
165-
.text("<%s><click:run_command:'/sbrbp info %s'>[Info]</click>", Colors.ADD, (global ? "g:" : "") + name())
166-
.space()
167-
.text("<%s><click:run_command:'/sbr loadbrush %s'>[Load]</click>", Colors.ADD, (global ? "g:" : "") + name());
164+
.text("<name><hover:show_text:'%s'>%s</hover>", simpleComponent(registry), name())
165+
.space()
166+
.text("<add><click:run_command:'/sbrbp info %s'>[Info]</click>", (global ? "g:" : "") + name())
167+
.space()
168+
.text("<add><click:run_command:'/sbr loadbrush %s'>[Load]</click>", (global ? "g:" : "") + name());
168169
if (canDelete) {
169-
text.space().text("<%s><click:run_command:'/sbrbp remove %s %s'>[Remove]</click>", Colors.REMOVE, name(), global ? "-g" : "");
170+
text.space().text("<remove><click:run_command:'/sbrbp remove %s %s'>[Remove]</click>", name(), global ? "-g" : "");
170171
}
171172

172173
return text.build();
173174
}
174175

175176
private List<String> simpleModifier(BrushSettingsRegistry registry) {
176177
return snapshot.placementModifier().entrySet().stream()
177-
.map(e -> registry.getPlacementModifier(e.getKey())
178-
.map(mod -> String.format("<%s>%s: <%s>%s",
179-
Colors.NAME, mod.modifier().name(), Colors.VALUE, e.getValue().descriptor()))
180-
.orElse(null))
181-
.filter(Objects::nonNull)
182-
.toList();
178+
.map(e -> registry.getPlacementModifier(e.getKey())
179+
.map(mod -> String.format("<name>%s: <value>%s",
180+
mod.modifier().name(), e.getValue().descriptor()))
181+
.orElse(null))
182+
.filter(Objects::nonNull)
183+
.toList();
183184
}
184185

185186
public String detailComponent(boolean global, BrushSettingsRegistry registry) {
186187
var sets = snapshot.schematicSets().stream()
187-
.map(set -> String.format(" <hover:show_text:'%s'>%s</hover>", set.infoComponent(), BuildUtil.renderProvider(set.selector())))
188-
.collect(Collectors.toList());
188+
.map(set -> String.format(" <hover:show_text:'%s'>%s</hover>", set.infoComponent(), BuildUtil.renderProvider(set.selector())))
189+
.collect(Collectors.toList());
189190

190191
var modifier = simpleModifier(registry);
191192

192193
return MessageComposer.create()
193-
.text("<%s>Information about brush <%s>%s", Colors.HEADING, Colors.NAME, name())
194-
.newLine()
195-
.text("<%s>Description: <%s>%s <click:suggest_command:'/sbrbp descr %s '><%s>[Change]</click>",
196-
Colors.NAME, Colors.VALUE, description(), (global ? "g:" : "") + name(), Colors.CHANGE)
197-
.newLine()
198-
.text("<%s>Schematic Sets:", Colors.NAME)
199-
.newLine()
200-
.text(sets)
201-
.newLine()
202-
.text(modifier)
203-
.build();
194+
.text("<heading>").localeCode("components.brush.information")
195+
.space()
196+
.text(name())
197+
.newLine()
198+
.text("<name>")
199+
.localeCode("words.description")
200+
.text(": <value>")
201+
.text(description())
202+
.space()
203+
.text("<click:suggest_command:'/sbrbp descr ")
204+
.text((global ? "g:" : "") + name())
205+
.text(" '><change>[")
206+
.localeCode("words.change")
207+
.text("]</click>")
208+
.newLine()
209+
.text("<name>")
210+
.localeCode("words.schematicSets")
211+
.text(":")
212+
.newLine()
213+
.text(sets)
214+
.newLine()
215+
.text(modifier)
216+
.build();
204217
}
205218
}

schematicbrushreborn-api/src/main/java/de/eldoria/schematicbrush/storage/preset/Preset.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import de.eldoria.eldoutilities.serialization.SerializationUtil;
1313
import de.eldoria.schematicbrush.brush.config.builder.BuildUtil;
1414
import de.eldoria.schematicbrush.brush.config.builder.SchematicSetBuilder;
15-
import de.eldoria.schematicbrush.util.Colors;
1615
import org.bukkit.configuration.serialization.ConfigurationSerializable;
1716
import org.bukkit.configuration.serialization.SerializableAs;
1817
import org.jetbrains.annotations.NotNull;
@@ -73,12 +72,12 @@ public String name() {
7372

7473
public String infoComponent(boolean global, boolean canDelete) {
7574
var text = MessageComposer.create()
76-
.text("<%s><hover:show_text:'%s'>%s</hover>", Colors.NAME, simpleComponent(), name())
75+
.text("<name><hover:show_text:'%s'>%s</hover>", simpleComponent(), name())
7776
.space()
78-
.text("<%s><click:run_command:'/sbrp info %s'>[Info]</click>", Colors.ADD, (global ? "g:" : "") + name());
77+
.text("<add><click:run_command:'/sbrp info %s'>[Info]</click>", (global ? "g:" : "") + name());
7978
if (canDelete) {
8079
text.space()
81-
.text("<%s><click:run_command:'/sbrp remove %s %s'>[Remove]</click>", Colors.REMOVE, name(), (global ? "-g" : ""));
80+
.text("<remove><click:run_command:'/sbrp remove %s %s'>[Remove]</click>", name(), (global ? "-g" : ""));
8281
}
8382

8483
return text.build();
@@ -90,12 +89,21 @@ public String detailComponent(boolean global) {
9089
.collect(Collectors.toList());
9190

9291
return MessageComposer.create()
93-
.text("<%s>Information about preset <%s>%s", Colors.HEADING, Colors.NAME, name())
92+
.text("<heading>")
93+
.localeCode("components.preset.information")
94+
.text(" <name>%s", name())
9495
.newLine()
95-
.text("<%s>Description: <%s>%s <click:suggest_command:'/sbrp descr %s '><%s>[Change]</click>",
96-
Colors.NAME, Colors.VALUE, description(), (global ? "g:" : "") + name(), Colors.CHANGE)
96+
.text("<name>")
97+
.localeCode("words.description")
98+
.text(": <value>%s", description())
99+
.space()
100+
.text("<click:suggest_command:'/sbrp descr %s '><change>[", (global ? "g:" : "") + name())
101+
.localeCode("words.change")
102+
.text("]</click>")
97103
.newLine()
98-
.text("<%s>Schematic Sets:", Colors.NAME)
104+
.text("<name>")
105+
.localeCode("words.schematicSets")
106+
.text(":")
99107
.newLine()
100108
.text(sets)
101109
.build();
@@ -106,8 +114,8 @@ public String simpleComponent() {
106114
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
107115
.collect(Collectors.joining("\n"));
108116

109-
var message = String.format("<%s>%s%n", Colors.VALUE, description());
110-
message += String.format("<%s>Schematic Sets:%n%s", Colors.NAME, sets);
117+
var message = String.format("<value>%s%n", description());
118+
message += String.format("<name>Schematic Sets:%n%s", sets);
111119
return message;
112120
}
113121

schematicbrushreborn-api/src/main/java/de/eldoria/schematicbrush/util/Colors.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

schematicbrushreborn-core/src/main/java/de/eldoria/schematicbrush/SchematicBrushRebornImpl.java

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
import org.jetbrains.annotations.NotNull;
8888

8989
import java.io.File;
90+
import java.nio.file.Files;
91+
import java.nio.file.Path;
92+
import java.nio.file.StandardCopyOption;
9093
import java.util.Arrays;
9194
import java.util.List;
9295
import java.util.Locale;
@@ -97,6 +100,7 @@
97100
@SuppressWarnings("unused")
98101
public class SchematicBrushRebornImpl extends SchematicBrushReborn {
99102

103+
private static final String[] LANGUAGES = new String[]{"de_DE", "en_US", "zh_TW"};
100104
private BrushSettingsRegistryImpl settingsRegistry;
101105
private SchematicRegistryImpl schematics;
102106
private JacksonConfiguration configuration;
@@ -141,6 +145,18 @@ public void onPluginLoad() throws Throwable {
141145
configuration.save();
142146
}
143147

148+
if (base.version() == 1) {
149+
// Required changes were made to language formats. reset files.
150+
Path path = getDataFolder().toPath().resolve("messages");
151+
for (String language : LANGUAGES) {
152+
var file = path.resolve("messages_%s.properties".formatted(language));
153+
Files.copy(file, path.resolve("messages_%s_old.properties".formatted(language)), StandardCopyOption.REPLACE_EXISTING);
154+
Files.deleteIfExists(file);
155+
}
156+
base.version(2);
157+
configuration.save();
158+
}
159+
144160
var yamlStorage = new YamlStorage(configuration);
145161
storageRegistry = new StorageRegistryImpl(yamlStorage, configuration);
146162
storageRegistry.register(StorageRegistry.YAML, yamlStorage);
@@ -149,26 +165,26 @@ public void onPluginLoad() throws Throwable {
149165
@Override
150166
public void onPluginEnable() {
151167
var localizer = Localizer.builder(this, configuration.general().language())
152-
.setIncludedLocales("de_DE", "en_US", "zh_TW")
153-
.build();
168+
.setIncludedLocales(LANGUAGES)
169+
.build();
154170
MessageSender.builder(this)
155-
.prefix("<gold>[SB]")
156-
.messageColor(NamedTextColor.AQUA)
157-
.addTag(tags -> tags
158-
.tag("heading", Tag.styling(NamedTextColor.GOLD))
159-
.tag("name", Tag.styling(NamedTextColor.AQUA))
160-
.tag("value", Tag.styling(NamedTextColor.DARK_GREEN))
161-
.tag("change", Tag.styling(NamedTextColor.YELLOW))
162-
.tag("remove", Tag.styling(NamedTextColor.RED))
163-
.tag("add", Tag.styling(NamedTextColor.GREEN))
164-
.tag("warn", Tag.styling(NamedTextColor.RED))
165-
.tag("neutral", Tag.styling(NamedTextColor.AQUA))
166-
.tag("confirm", Tag.styling(NamedTextColor.GREEN))
167-
.tag("delete", Tag.styling(NamedTextColor.RED))
168-
.tag("inactive", Tag.styling(NamedTextColor.GRAY))
169-
)
170-
.localizer(localizer)
171-
.register();
171+
.prefix("<gold>[SB]")
172+
.messageColor(NamedTextColor.AQUA)
173+
.addTag(tags -> tags
174+
.tag("heading", Tag.styling(NamedTextColor.GOLD))
175+
.tag("name", Tag.styling(NamedTextColor.DARK_AQUA))
176+
.tag("value", Tag.styling(NamedTextColor.DARK_GREEN))
177+
.tag("change", Tag.styling(NamedTextColor.YELLOW))
178+
.tag("remove", Tag.styling(NamedTextColor.RED))
179+
.tag("add", Tag.styling(NamedTextColor.GREEN))
180+
.tag("warn", Tag.styling(NamedTextColor.RED))
181+
.tag("neutral", Tag.styling(NamedTextColor.AQUA))
182+
.tag("confirm", Tag.styling(NamedTextColor.GREEN))
183+
.tag("delete", Tag.styling(NamedTextColor.RED))
184+
.tag("inactive", Tag.styling(NamedTextColor.GRAY))
185+
)
186+
.localizer(localizer)
187+
.register();
172188

173189
schematics.register(SchematicCache.STORAGE, new SchematicBrushCache(this, configuration));
174190

@@ -217,12 +233,12 @@ public void onPluginEnable() {
217233
public Module platformModule() {
218234
if (!getServer().getName().toLowerCase(Locale.ROOT).contains("spigot")) {
219235
return JacksonPaper.builder()
220-
.colorAsHex()
221-
.build();
236+
.colorAsHex()
237+
.build();
222238
}
223239
return JacksonBukkit.builder()
224-
.colorAsHex()
225-
.build();
240+
.colorAsHex()
241+
.build();
226242
}
227243

228244
/**
@@ -255,14 +271,14 @@ public SimpleModule schematicBrushModule() {
255271
@Override
256272
public ObjectMapper configureMapper(MapperBuilder<?, ?> builder) {
257273
builder.addModule(platformModule())
258-
.typeFactory(TypeFactory.defaultInstance().withClassLoader(getClassLoader()))
259-
.addModule(schematicBrushModule())
260-
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
261-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
262-
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
274+
.typeFactory(TypeFactory.defaultInstance().withClassLoader(getClassLoader()))
275+
.addModule(schematicBrushModule())
276+
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
277+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
278+
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
263279
if (builder instanceof YAMLMapper.Builder b) {
264280
b.disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)
265-
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
281+
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
266282
}
267283
return builder
268284
.build()
@@ -274,11 +290,11 @@ public ObjectMapper configureMapper(MapperBuilder<?, ?> builder) {
274290
public void onPostStart() throws Throwable {
275291
if (configuration.general().isCheckUpdates() && UserData.get(this).isPremium()) {
276292
Updater.lyna(LynaUpdateData.builder(this, 1)
277-
.updateUrl("https://discord.gg/zRW9Vpu")
278-
.notifyPermission(Permissions.Admin.RELOAD)
279-
.notifyUpdate(true)
280-
.build())
281-
.start();
293+
.updateUrl("https://discord.gg/zRW9Vpu")
294+
.notifyPermission(Permissions.Admin.RELOAD)
295+
.notifyUpdate(true)
296+
.build())
297+
.start();
282298
}
283299
}
284300

@@ -327,11 +343,11 @@ private void enableMetrics() {
327343

328344
metrics.addCustomChart(new AdvancedPie("installed_add_ons",
329345
() -> Arrays.stream(getServer().getPluginManager().getPlugins())
330-
.filter(plugin -> {
331-
var descr = plugin.getDescription();
332-
return descr.getSoftDepend().contains("SchematicBrushReborn") || descr.getDepend()
333-
.contains("SchematicBrushReborn");
334-
}).collect(Collectors.toMap(e -> e.getDescription().getName(), e -> 1))));
346+
.filter(plugin -> {
347+
var descr = plugin.getDescription();
348+
return descr.getSoftDepend().contains("SchematicBrushReborn") || descr.getDepend()
349+
.contains("SchematicBrushReborn");
350+
}).collect(Collectors.toMap(e -> e.getDescription().getName(), e -> 1))));
335351

336352
metrics.addCustomChart(new SimplePie("used_storage_type",
337353
() -> configuration.general().storageType().name()));

0 commit comments

Comments
 (0)