This commit is contained in:
@@ -18,7 +18,7 @@ public enum HelpMessage {
|
||||
|
||||
RESULT("result");
|
||||
|
||||
|
||||
private static final String PREFIX = "common.";
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
@@ -27,11 +27,17 @@ public enum HelpMessage {
|
||||
* @param key the message key
|
||||
*/
|
||||
HelpMessage(String key) {
|
||||
this.key = "common." + key;
|
||||
this.key = PREFIX + key;
|
||||
}
|
||||
|
||||
/** @return the message key */
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/** @return the key without the common prefix */
|
||||
public String getEntryKey() {
|
||||
// Note ljacqu 20171008: #getKey is called more often than this method, so we optimize for the former method
|
||||
return key.substring(PREFIX.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class HelpMessagesService implements Reloadable {
|
||||
* @return the localized description
|
||||
*/
|
||||
public CommandDescription buildLocalizedDescription(CommandDescription command) {
|
||||
final String path = getCommandPath(command);
|
||||
final String path = COMMAND_PREFIX + getCommandSubPath(command);
|
||||
if (!messageFileHandler.hasSection(path)) {
|
||||
// Messages file does not have a section for this command - return the provided command
|
||||
return command;
|
||||
@@ -68,7 +68,7 @@ public class HelpMessagesService implements Reloadable {
|
||||
}
|
||||
|
||||
public String getDescription(CommandDescription command) {
|
||||
return getText(getCommandPath(command) + DESCRIPTION_SUFFIX, command::getDescription);
|
||||
return getText(COMMAND_PREFIX + getCommandSubPath(command) + DESCRIPTION_SUFFIX, command::getDescription);
|
||||
}
|
||||
|
||||
public String getMessage(HelpMessage message) {
|
||||
@@ -81,11 +81,14 @@ public class HelpMessagesService implements Reloadable {
|
||||
|
||||
public String getMessage(DefaultPermission defaultPermission) {
|
||||
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
|
||||
String path = DEFAULT_PERMISSIONS_PATH
|
||||
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
String path = DEFAULT_PERMISSIONS_PATH + getDefaultPermissionsSubPath(defaultPermission);
|
||||
return messageFileHandler.getMessage(path);
|
||||
}
|
||||
|
||||
public static String getDefaultPermissionsSubPath(DefaultPermission defaultPermission) {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
messageFileHandler = messageFileHandlerProvider.initializeHandler(
|
||||
@@ -99,8 +102,15 @@ public class HelpMessagesService implements Reloadable {
|
||||
: message;
|
||||
}
|
||||
|
||||
private static String getCommandPath(CommandDescription command) {
|
||||
return COMMAND_PREFIX + CommandUtils.constructParentList(command)
|
||||
/**
|
||||
* Returns the command subpath for the given command (i.e. the path to the translations for the given
|
||||
* command under "commands").
|
||||
*
|
||||
* @param command the command to process
|
||||
* @return the subpath for the command's texts
|
||||
*/
|
||||
public static String getCommandSubPath(CommandDescription command) {
|
||||
return CommandUtils.constructParentList(command)
|
||||
.stream()
|
||||
.map(cmd -> cmd.getLabels().get(0))
|
||||
.collect(Collectors.joining("."));
|
||||
|
||||
@@ -19,7 +19,7 @@ public enum HelpSection {
|
||||
|
||||
CHILDREN("children");
|
||||
|
||||
|
||||
private static final String PREFIX = "section.";
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
@@ -28,11 +28,17 @@ public enum HelpSection {
|
||||
* @param key the message key
|
||||
*/
|
||||
HelpSection(String key) {
|
||||
this.key = "section." + key;
|
||||
this.key = PREFIX + key;
|
||||
}
|
||||
|
||||
/** @return the message key */
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/** @return the key without the common prefix */
|
||||
public String getEntryKey() {
|
||||
// Note ljacqu 20171008: #getKey is called more often than this method, so we optimize for the former method
|
||||
return key.substring(PREFIX.length());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user