Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds API to enable translations to be set and specific API for flags #2109

Merged
merged 1 commit into from
Mar 26, 2023

Conversation

tastybento
Copy link
Member

This was a request on Discord so that plugins can set flags and set the name and lore for them too.

The translations can be set after building the flag. I did not add the option to set translations to the flag builder (yet) because setting translations may require some logic to discover what locales are supported on the server, and then iterate through them assigning the appropriate translation.

Example to set the name and description for a flag:

if (Flag.MY_CUSTOM_FLAG.setTranslatedName(Locale.US, "Custom Flag")
    && Flag.MY_CUSTOM_FLAG.setTranslatedDescription(Locale.US, "A Custom Flag")) {
    // Success
} else {
   /// Failure - because the locale is not supported on the server
}

Example to set a reference via API generically:

BentoBox.getInstance().getLocalesManager().setTranslation(Locale.US, "a.reference.here", "A translation");

Setting translations via API is not permanent, i.e., translations are not stored in the locale files and the files are not changed. So, they can be temporarily overwritten, but not fundamentally changed.

The fallback locale for any reference is Locale.US so that should be set at a minimum.

This was a request on Discord so that plugins can set flags and set the
name and lore for them too.
@tastybento tastybento added Type: Enhancement Improvement or modification which is usually a new feature. Type: API relating to the BentoBox API labels Mar 18, 2023
@tastybento tastybento requested a review from BONNe March 18, 2023 22:39
@sonarcloud
Copy link

sonarcloud bot commented Mar 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@tastybento tastybento merged commit 073f3a4 into develop Mar 26, 2023
@tastybento tastybento deleted the translation_setting_api_for_flags branch March 26, 2023 17:06
@tastybento tastybento mentioned this pull request Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: API relating to the BentoBox API Type: Enhancement Improvement or modification which is usually a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant