-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support of DynamicLocaleReader
- Loading branch information
Showing
6 changed files
with
137 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/src/main/java/revxrsal/commands/locales/DynamicLocaleReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package revxrsal.commands.locales; | ||
|
||
import revxrsal.commands.command.CommandActor; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* A locale reader is a source in which custom typed messages for a specific locale | ||
* are fetched. This can be a file, a resource bundle, or even a remote | ||
* source. | ||
*/ | ||
public interface DynamicLocaleReader<T> extends LocaleMessageTransmitter<T> { | ||
|
||
/** | ||
* Returns whether this reader contains a mapping for the | ||
* given key. | ||
* | ||
* @param key Key to check for | ||
* @return {@code true} if this reader has a mapping for the key | ||
*/ | ||
boolean containsKey(String key); | ||
|
||
/** | ||
* Returns the mapping value for this key. It is recommended that | ||
* this only return values if {@link #containsKey(String)} is true, | ||
* otherwise throwing an exception to avoid confusion. | ||
* | ||
* @param key Key to fetch for | ||
* @return The string value | ||
*/ | ||
|
||
T get(String key); | ||
|
||
/** | ||
* Returns the locale of by this reader | ||
* | ||
* @return The reader's locale | ||
*/ | ||
Locale getLocale(); | ||
|
||
default void reply(CommandActor actor, String key, Object... args) { | ||
reply(actor, format(get(key), args)); | ||
} | ||
|
||
default void error(CommandActor actor, String key, Object... args) { | ||
error(actor, format(get(key), args)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
common/src/main/java/revxrsal/commands/locales/LocaleMessageTransmitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package revxrsal.commands.locales; | ||
|
||
import revxrsal.commands.command.CommandActor; | ||
|
||
public interface LocaleMessageTransmitter<T> { | ||
void reply(CommandActor actor, T message); | ||
|
||
default void error(CommandActor actor, T message) { | ||
reply(actor, message); | ||
} | ||
|
||
T format(T message, Object... args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters