Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/dev/twme/debugstickpro/DebugStickPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class DebugStickPro extends JavaPlugin {
/**
* This is the version of the language file
*/
public static final int LANG_VERSION = 4;
public static final int LANG_VERSION = 5;

/**
* This method is called when the plugin is loaded
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/dev/twme/debugstickpro/localization/I18n.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.twme.debugstickpro.localization;

import dev.twme.debugstickpro.blockdatautil.SubBlockData;
import dev.twme.debugstickpro.config.ConfigFile;
import dev.twme.debugstickpro.hook.PlaceholderAPIUtil;
import org.bukkit.Bukkit;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

public class I18n {
Expand Down Expand Up @@ -58,4 +60,40 @@ public static List<String> list(String key) {

return lang.getList(key);
}

/**
* Translate a SubBlockData value for the player.
*
* @param playerUUID the UUID of the player
* @param subBlockData the SubBlockData whose value should be translated
* @return translated value, or the raw value in lower case when no translation exists
*/
public static String blockDataValue(UUID playerUUID, SubBlockData subBlockData) {
String playerLocale = PlayerLanguageManager.getLocale(playerUUID);
LangFileReader lang = LangFileManager.getLang(playerLocale);
String rawValue = subBlockData.getDataAsString();

String translated = findBlockDataValue(lang, subBlockData.name(), rawValue);
if (translated != null) {
return translated;
}

if (!playerLocale.equals(ConfigFile.Language.DefaultLanguage)) {
translated = findBlockDataValue(LangFileManager.getLang(ConfigFile.Language.DefaultLanguage), subBlockData.name(), rawValue);
if (translated != null) {
return translated;
}
}

return rawValue.toLowerCase(Locale.ROOT);
}

private static String findBlockDataValue(LangFileReader lang, String dataType, String rawValue) {
String translated = lang.getOptionalString(Lang.DataValueName.value(dataType, rawValue));
if (translated != null) {
return translated;
}

return lang.getOptionalString(Lang.DataValueName.common(rawValue));
}
}
13 changes: 13 additions & 0 deletions src/main/java/dev/twme/debugstickpro/localization/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,17 @@ public final static class DataKeyName {
public final static String WaterloggedDataName = "DataKeyName.WaterloggedDataName";

}

public final static class DataValueName {
private final static String Root = "DataValueName";
private final static String Common = Root + ".Common";

public static String value(String dataType, String value) {
return Root + "." + dataType + "." + value;
}

public static String common(String value) {
return Common + "." + value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public String getString(String key) {
return this.langFile.getString(key);
}

/**
* Get a string without falling back to the default language or modifying the file.
*
* @param key the key of the string
* @return the string of the key, or null if it is not configured
*/
public String getOptionalString(String key) {
return this.langFile.getString(key);
}

/**
* Get the list of the key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public static String getDisplay(UUID playerUUID, BlockData blockData) {

for (int i = 0; i < displayList.size(); i++) {
SubBlockData subBlockData = displayList.get((i + sort) % displayList.size());
String value = I18n.blockDataValue(playerUUID, subBlockData);
if (subBlockData.isUsing()) {
stringBuilder.append(Lang.ActionBar.formatSelectedData(I18n.string(playerUUID, Lang.ActionBar.SelectedDataFormat), I18n.string(playerUUID, subBlockData.dataName()), subBlockData.getDataAsString().toLowerCase())).append(" ");
stringBuilder.append(Lang.ActionBar.formatSelectedData(I18n.string(playerUUID, Lang.ActionBar.SelectedDataFormat), I18n.string(playerUUID, subBlockData.dataName()), value)).append(" ");
} else {
stringBuilder.append(Lang.ActionBar.formatNotSelectedData(I18n.string(playerUUID, Lang.ActionBar.NotSelectedDataFormat), I18n.string(playerUUID, subBlockData.dataName()), subBlockData.getDataAsString().toLowerCase())).append(" ");
stringBuilder.append(Lang.ActionBar.formatNotSelectedData(I18n.string(playerUUID, Lang.ActionBar.NotSelectedDataFormat), I18n.string(playerUUID, subBlockData.dataName()), value)).append(" ");
}
}
return stringBuilder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static String getDisplay(UUID playerUUID) {
StringBuilder stringBuilder = new StringBuilder();

for (SubBlockData subBlockData : copiedSubBlockData) {
stringBuilder.append(Lang.ActionBar.formatCopiedBlockData(I18n.string(playerUUID, Lang.ActionBar.CopiedBlockDataFormat), I18n.string(playerUUID, subBlockData.dataName()), subBlockData.getDataAsString().toLowerCase())).append(" ");
stringBuilder.append(Lang.ActionBar.formatCopiedBlockData(I18n.string(playerUUID, Lang.ActionBar.CopiedBlockDataFormat), I18n.string(playerUUID, subBlockData.dataName()), I18n.blockDataValue(playerUUID, subBlockData))).append(" ");
}
return stringBuilder.toString();
}
Expand Down
Loading