mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-12-01 15:04:09 +01:00
Added args for String.format()
( cherry-picked by @main-- )
This commit is contained in:
parent
451955f858
commit
3e4b042de8
@ -17,18 +17,20 @@ public interface MessageProvider {
|
||||
* Returns a message (as {@link String}) for the specified key (as {@link MultiverseMessage}).
|
||||
*
|
||||
* @param key The key
|
||||
* @param args Args for String.format()
|
||||
* @return The message
|
||||
*/
|
||||
public String getMessage(MultiverseMessage key);
|
||||
public String getMessage(MultiverseMessage key, Object... args);
|
||||
|
||||
/**
|
||||
* Returns a message (as {@link String}) in a specified {@link Locale} for the specified key (as {@link MultiverseMessage}).
|
||||
*
|
||||
* @param key The Key
|
||||
* @param locale The {@link Locale}
|
||||
* @param args Args for String.format()
|
||||
* @return The message
|
||||
*/
|
||||
public String getMessage(MultiverseMessage key, Locale locale);
|
||||
public String getMessage(MultiverseMessage key, Locale locale, Object... args);
|
||||
|
||||
/**
|
||||
* Returns the Locale this MessageProvider is currently using.
|
||||
|
@ -46,6 +46,13 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
||||
+ locale.toString(), locale);
|
||||
}
|
||||
|
||||
public String format(String string, Object... args) {
|
||||
// Replaces & with the Section character
|
||||
string = string.replaceAll("&", Character.toString((char) 167));
|
||||
|
||||
return String.format(string, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -106,26 +113,26 @@ public class SimpleMessageProvider implements LazyLocaleMessageProvider {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getMessage(MultiverseMessage key) {
|
||||
public String getMessage(MultiverseMessage key, Object... args) {
|
||||
if (!isLocaleLoaded(locale)) {
|
||||
return key.getDefault();
|
||||
return format(key.getDefault(), args);
|
||||
}
|
||||
else
|
||||
return messages.get(locale).get(key);
|
||||
return format(messages.get(locale).get(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getMessage(MultiverseMessage key, Locale locale) {
|
||||
public String getMessage(MultiverseMessage key, Locale locale, Object... args) {
|
||||
try {
|
||||
maybeLoadLocale(locale);
|
||||
} catch (LocalizationLoadingException e) {
|
||||
e.printStackTrace();
|
||||
return getMessage(key);
|
||||
}
|
||||
return messages.get(locale).get(key);
|
||||
return format(messages.get(locale).get(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user