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

add a translate util file #87

Merged
merged 1 commit into from
Jun 17, 2024
Merged

add a translate util file #87

merged 1 commit into from
Jun 17, 2024

Conversation

Chew
Copy link
Owner

@Chew Chew commented Jun 11, 2024

Info

Pull Request

Pull Request Checklist

Please follow the following steps before opening this PR.

PRs that do not complete the checklist will be subject to denial for
missing information.

Pull Request Information

Check and fill in the blanks for all that apply:

  • My PR fixes a bug, error, or other issue with the library's codebase.
  • My PR is for the commons module of the JDA-Utilities library.
  • My PR creates a new module for the JDA-Utilities library: ______.

This PR adds a simple, bare minimum, translation library. It accepts properties files of keys, with inputting a Discord Locale. It has some useful methods that work with the command translation arguments in commands. It supports supplying a locale for ephemeral responses, or a server for not.

Example

Discord Locale set to English

CleanShot 2024-06-10 at 19 22 07
CleanShot 2024-06-10 at 19 22 44

Discord Locale to German:

CleanShot 2024-06-10 at 19 22 56
CleanShot 2024-06-10 at 19 23 00

Code

Initializing

// Load locales
DiscordLocale[] locales = {DiscordLocale.ENGLISH_US, DiscordLocale.SPANISH, DiscordLocale.GERMAN};
for (DiscordLocale locale : locales) {
    Properties locProp = new Properties();
    locProp.load(new FileInputStream("src/main/resources/" + locale.getLocale() + ".properties"));
    TranslateUtil.addLocale(locale, locProp);
}

Referencing

t(event.getUserLocale(), "SCORE")

Properties File

# Score Command

SCORE_COMMAND_DESCRIPTION=Shows the score and match-ups of the current game

# Single Word Strings
SCORE=Score
INNING=Inning
SUMMARY=Summary
PITCHING=Pitching
BATTING=Batting
ON_BASE=On Base

@Chew Chew added enhancement New feature or request module: commons Commons module labels Jun 11, 2024
@Chew
Copy link
Owner Author

Chew commented Jun 17, 2024

@RoryHelper approve

@Chew Chew merged commit 69edb09 into master Jun 17, 2024
4 checks passed
@Chew Chew deleted the feat/translatelib branch June 17, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module: commons Commons module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants