Permalink
Browse files

[breaking] i18n - Introduced Messages.keys(Locale) allowing to list a…

…vailable Messages keys for a given Locale.

If you implemented your own Messages implementation, it will break your code : simply provide same implementation for keys(), without fixing the Locale.
  • Loading branch information...
fcamblor committed Nov 21, 2016
1 parent f46e2ff commit 2afa00bf3c219a4ef8daafca6573682f5eec1dda
@@ -55,11 +55,16 @@ public String getMessage(String key, MessageParams params, Locale locale) {
}
@Override
public Iterable<String> keys() {
Optional<ResourceBundle> bundle = getBundle(Locale.ROOT);
public Iterable<String> keys(Locale locale) {
Optional<ResourceBundle> bundle = getBundle(locale);
return bundle.isPresent() ? Ordering.natural().sortedCopy(bundle.get().keySet()) : Collections.<String>emptySet();
}
@Override
public Iterable<String> keys() {
return keys(Locale.ROOT);
}
@Override
public Iterable<Entry<String, String>> entries(Locale locale) {
Optional<ResourceBundle> rootBundle = getBundle(Locale.ROOT);
@@ -8,6 +8,14 @@
* an interpolation mechanism using a mustache like format, making it easier to use in Javascript client too.
*/
public interface Messages {
/**
* Return the list of message keys available in this Messages instance, for given Locale
*
* @param locale the locale in which the keys should be resolved.
* @return the list of keys, as an Iterable
*/
Iterable<String> keys(Locale locale);
/**
* Return the list of message keys available in this Messages instance.
*

0 comments on commit 2afa00b

Please sign in to comment.