Skip to content

Commit

Permalink
Added configuration option to allow disabling client side translations;
Browse files Browse the repository at this point in the history
Fix key to chat_message_formatter messages in language files.
  • Loading branch information
oddlama committed Jun 29, 2021
1 parent 7960b0a commit ad95fcb
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion vane-admin/src/main/java/org/oddlama/vane/admin/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.oddlama.vane.core.module.Module;
import org.oddlama.vane.util.LazyLocation;

@VaneModule(name = "admin", bstats = 8638, config_version = 2, lang_version = 1, storage_version = 1)
@VaneModule(name = "admin", bstats = 8638, config_version = 2, lang_version = 2, storage_version = 1)
public class Admin extends Module<Admin> {
// Persistent storage
@Persistent
Expand Down
11 changes: 6 additions & 5 deletions vane-admin/src/main/resources/lang-de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

# DO NOT CHANGE! The version of this language file. Used to determine
# if the file needs to be updated.
version: 1
version: 2
# The corresponding language code used in resource packs. Used for
# resource pack generation. Typically this is a combination of the
# language code (ISO 639) and the country code (ISO 3166).
resource_pack_lang_code: 'de_de'

player_chat_format: "%1$s§7: %2$s"
player_join: "%1$s§e hat den Server betreten"
player_kick: "%1$s§e wurde vom Server geworfen"
player_quit: "%1$s§e hat den Server verlassen"
chat_message_formatter:
player_chat_format: "%1$s§7: %2$s"
player_join: "%1$s§e hat den Server betreten"
player_kick: "%1$s§e wurde vom Server geworfen"
player_quit: "%1$s§e hat den Server verlassen"

autostop:
aborted: "§7Autostop §dabgebrochen"
Expand Down
29 changes: 15 additions & 14 deletions vane-admin/src/main/resources/lang-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@

# DO NOT CHANGE! The version of this language file. Used to determine
# if the file needs to be updated.
version: 1
version: 2
# The corresponding language code used in resource packs. Used for
# resource pack generation. Typically this is a combination of the
# language code (ISO 639) and the country code (ISO 3166).
resource_pack_lang_code: 'en_us'

# This is the format for player chat messages
# %1$s: player name
# %2$s: message
player_chat_format: "%1$s§7: %2$s"
chat_message_formatter:
# This is the format for player chat messages
# %1$s: player name
# %2$s: message
player_chat_format: "%1$s§7: %2$s"

# This message is sent when a player joins the server
# %1$s: player name
player_join: "%1$s§e has joined the server"
# This message is sent when a player joins the server
# %1$s: player name
player_join: "%1$s§e has joined the server"

# This message is sent when a player is kicked from the server
# %1$s: player name
player_kick: "%1$s§e was kicked from the server"
# This message is sent when a player is kicked from the server
# %1$s: player name
player_kick: "%1$s§e was kicked from the server"

# This message is sent when a player leaves the server
# %1$s: player name
player_quit: "%1$s§e has left the server"
# This message is sent when a player leaves the server
# %1$s: player name
player_quit: "%1$s§e has left the server"

autostop:
# This message is sent when autostop is aborted, due to an administrative command
Expand Down
12 changes: 6 additions & 6 deletions vane-admin/src/main/resources/lang-fr-fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

# DO NOT CHANGE! The version of this language file. Used to determine
# if the file needs to be updated.
version: 1
version: 2
# The corresponding language code used in resource packs. Used for
# resource pack generation. Typically this is a combination of the
# language code (ISO 639) and the country code (ISO 3166).
resource_pack_lang_code: 'fr_fr'

player_chat_format: "%1$s§7: %2$s"

player_join: "%1$s§e a rejoint le serveur"
player_kick: "%1$s§e a été éjecté·e du serveur"
player_quit: "%1$s§e a quitté le serveur"
chat_message_formatter:
player_chat_format: "%1$s§7: %2$s"
player_join: "%1$s§e a rejoint le serveur"
player_kick: "%1$s§e a été éjecté·e du serveur"
player_quit: "%1$s§e a quitté le serveur"

autostop:
aborted: "§dArrêt automatique annulé"
Expand Down
7 changes: 6 additions & 1 deletion vane-core/src/main/java/org/oddlama/vane/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.oddlama.vane.annotation.VaneModule;
import org.oddlama.vane.annotation.config.ConfigBoolean;
import org.oddlama.vane.annotation.lang.LangMessage;
import org.oddlama.vane.annotation.persistent.Persistent;
import org.oddlama.vane.core.functional.Consumer1;
Expand All @@ -52,7 +53,7 @@
import org.oddlama.vane.core.module.Module;
import org.oddlama.vane.core.module.ModuleComponent;

@VaneModule(name = "core", bstats = 8637, config_version = 3, lang_version = 2, storage_version = 1)
@VaneModule(name = "core", bstats = 8637, config_version = 4, lang_version = 2, storage_version = 1)
public class Core extends Module<Core> implements PluginMessageListener {
/** The base offset for any model data used by vane plugins. */
// "vane" = 0x76616e65, but the value will be saved as float (json...), so only -2^24 - 2^24 can accurately be represented.
Expand Down Expand Up @@ -95,6 +96,10 @@ public static int model_data(int section, int item_id, int variant_id) {
@Persistent
public Map<UUID, Integer> storage_auth_multiplexer_id = new HashMap<>();

// core-config
@ConfigBoolean(def = true, desc = "Let the client translate messages using the generated resource pack. This allows every player to select their preferred language, and all plugin messages will also be translated. Disabling this won't allow you to skip generating the resource pack, as it will be needed for custom item textures.")
public boolean config_client_side_translations;

public Core() {
// Create global command catch-all permission
register_permission(permission_command_catchall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

public class TranslatedMessage {
Expand Down Expand Up @@ -43,11 +41,15 @@ public String str(Object... args) {
}
}

public @NotNull TextComponent str_component(Object... args) {
public @NotNull Component str_component(Object... args) {
return LegacyComponentSerializer.legacySection().deserialize(str(args));
}

public TranslatableComponent format(Object... args) {
public Component format(Object... args) {
if (!module.core.config_client_side_translations) {
return str_component(args);
}

final var list = new ArrayList<ComponentLike>();
for (final var o : args) {
if (o instanceof ComponentLike) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import java.util.stream.Collectors;
import org.oddlama.vane.core.module.Module;

import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -35,6 +36,12 @@ public List<String> str(Object... args) {
}

public List<Component> format(Object... args) {
if (!module.core.config_client_side_translations) {
return str(args).stream()
.map(s -> LegacyComponentSerializer.legacySection().deserialize(s))
.collect(Collectors.toList());
}

final var arr = new ArrayList<Component>();
for (int i = 0; i < default_translation.size(); ++i) {
final var list = new ArrayList<ComponentLike>();
Expand Down

0 comments on commit ad95fcb

Please sign in to comment.