Skip to content

Commit

Permalink
Add a way to query a key/locale pair and add final to some missing pl…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
kezz committed Mar 7, 2025
1 parent 31399ba commit 99aeeed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public final boolean contains(final @NotNull String key) {
return this.translations.containsKey(key);
}

@Override
public final boolean contains(final @NotNull String key, final @NotNull Locale locale) {
final Translation translation = this.translations.get(requireNonNull(key, "key"));
if (translation == null) return false;
return translation.translations.get(requireNonNull(locale, "locale")) != null;
}

@Override
public final void defaultLocale(final @NotNull Locale locale) {
this.defaultLocale = requireNonNull(locale, "locale");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,25 @@ public interface TranslationStore<T> extends Translator {
* @return whether the registry contains a value for the translation key
* @since 4.20.0
*/
boolean contains(@NotNull String key);
boolean contains(final @NotNull String key);

/**
* Checks if any translations are explicitly registered for the specified key and locale.
*
* @param key a translation key
* @param locale the locale
* @return whether the registry contains a value for the translation key and locale
* @since 4.20.0
*/
boolean contains(final @NotNull String key, final @NotNull Locale locale);

/**
* Sets the default locale used by this registry.
*
* @param locale the locale to use a default
* @since 4.20.0
*/
void defaultLocale(@NotNull Locale locale);
void defaultLocale(final @NotNull Locale locale);

/**
* Registers a translation.
Expand All @@ -98,7 +108,7 @@ public interface TranslationStore<T> extends Translator {
* @throws IllegalArgumentException if the translation key already exists
* @since 4.20.0
*/
void register(@NotNull String key, @NotNull Locale locale, T translation);
void register(final @NotNull String key, final @NotNull Locale locale, final T translation);

/**
* Registers a map of translations.
Expand All @@ -109,7 +119,7 @@ public interface TranslationStore<T> extends Translator {
* @see #register(String, Locale, T)
* @since 4.20.0
*/
void registerAll(@NotNull Locale locale, @NotNull Map<String, T> translations);
void registerAll(final @NotNull Locale locale, final @NotNull Map<String, T> translations);

/**
* Registers translations with a set of keys and a mapping function to produce the translation from the key.
Expand All @@ -120,15 +130,15 @@ public interface TranslationStore<T> extends Translator {
* @throws IllegalArgumentException if a translation key already exists
* @since 4.20.0
*/
void registerAll(@NotNull Locale locale, @NotNull Set<String> keys, Function<String, T> function);
void registerAll(final @NotNull Locale locale, final @NotNull Set<String> keys, Function<String, T> function);

/**
* Unregisters a translation key.
*
* @param key a translation key
* @since 4.0.0
*/
void unregister(@NotNull String key);
void unregister(final @NotNull String key);

/**
* An abstract, string-based translation store.
Expand Down

0 comments on commit 99aeeed

Please sign in to comment.