Skip to content

feature(api): Add locale-specific translation unregistering - #1441

Open
ZapolyarnyDev wants to merge 1 commit into
PaperMC:main/5from
ZapolyarnyDev:feature/translation-store-override
Open

feature(api): Add locale-specific translation unregistering#1441
ZapolyarnyDev wants to merge 1 commit into
PaperMC:main/5from
ZapolyarnyDev:feature/translation-store-override

Conversation

@ZapolyarnyDev

Copy link
Copy Markdown

Adds TranslationStore#unregister(String, Locale) to allow unregistering a translation for a specific locale without affecting the other translations for that key

Includes tests for preserving other locales and removing empty keys

Closes #1361


@Override
public final void unregister(final String key, final Locale locale) {
this.translations.computeIfPresent(requireNonNull(key, "key"), (ignored, translation) -> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why computeIfPresent? I don't know why we need to create one if absent when we are unregistering.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used computeIfPresent specifically to avoid creating a translation entry when unregistering an unknown key. If the key exists, we remove the locale; if no locales remain, returning null removes the key. Otherwise, it’s a no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to override or remove translations from a translation store

2 participants