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

Application command localization #2090

Merged
Merged
Changes from 1 commit
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
16c11ae
WIP
freya022 Mar 26, 2022
f3c8a2d
Add CommandData#addTranslation
freya022 Apr 15, 2022
bcd3bbb
Expose name/description localizations for Command
freya022 Apr 15, 2022
e3e1bbf
Use key components
freya022 Apr 15, 2022
2a60ad1
Only use manual translation setters
freya022 Apr 15, 2022
fed5851
Typo
freya022 Apr 15, 2022
d8a0523
Add localization for subcommands & groups
freya022 Apr 15, 2022
d6d47ba
CommandImpl#parseLocalization should be Nonnull
freya022 Apr 15, 2022
8c38fc2
Merge branch 'master' into feature/command-localization
freya022 Apr 15, 2022
c2bc416
Add missing accessors
freya022 Apr 15, 2022
7d15388
Use LocalizationMap instead of Map<String, String>
freya022 Apr 15, 2022
7cf2880
Make `Choice` serializable, enable localization on choices
freya022 Apr 15, 2022
94b610a
Rearrange constructor setters
freya022 Apr 15, 2022
54a35e6
Add JDA#retrieveCommands(boolean)
freya022 Apr 15, 2022
1513e44
Fix NUMBER choices not being rounded
freya022 Apr 15, 2022
2076b5b
Fix spaces
freya022 Apr 15, 2022
cac3664
Split declarations of LocalizationMap fields
freya022 Apr 15, 2022
f83f694
Use `List<Choice>` instead of `DataArray` in `OptionData`
freya022 Apr 15, 2022
40a4f09
Add autocomplete choices using `Choice#toData`
freya022 Apr 15, 2022
61ac108
Add localization getters in the form of `Map<Locale, String>`
freya022 Apr 15, 2022
319f250
Parse localization data when reconstituting command data objects
freya022 Apr 15, 2022
8336615
Move LocalizationMap to api
freya022 Apr 16, 2022
5f371de
Attempt at making a localization mapper, using ResourceBundle
freya022 Apr 16, 2022
cd668d8
Fix spaces
freya022 Apr 16, 2022
827f732
Separate the translation value retrieval into a `LocalizationFunction`
freya022 Apr 17, 2022
61fdff6
Add some docs
freya022 Apr 17, 2022
ed99cbc
Add docs & checks
freya022 Apr 17, 2022
573af14
Remove unneeded checks in CommandCreateActionImpl
freya022 Apr 17, 2022
70b27f1
Refactor name/description checks
freya022 Apr 17, 2022
047200b
Move CommandImpl#parseLocalization
freya022 Apr 18, 2022
414f77f
Add docs
freya022 Apr 18, 2022
e90e9bf
Move LocalizationMap to `commands` package
freya022 Apr 18, 2022
0f396d4
Docs & minor refactoring
freya022 Apr 18, 2022
45a9e95
Docs
freya022 Apr 18, 2022
e43b5dd
Put checks on LocalizationMap
freya022 Apr 18, 2022
82f004e
Inline LocalizationMap#setTranslation in constructor as to avoid unmo…
freya022 Apr 27, 2022
a7a6269
Merge branch 'master' into feature/command-localization
freya022 Apr 27, 2022
dfcdf0a
Transfer localization data when transforming `Command` -> `(Slash)Com…
freya022 Apr 27, 2022
014f4e1
LocalizationMap docs fixes
freya022 Apr 27, 2022
ca46752
Merge branch 'master' into feature/command-localization
freya022 May 1, 2022
48af02a
Merge branch 'master' into feature/command-localization
freya022 Jun 10, 2022
b984682
Remove vararg locales, replace with unique DiscordLocale as 1st arg
freya022 Jun 17, 2022
fdcfad1
Add bulk setters
freya022 Jun 18, 2022
9c24ab8
Remove remaining Locale usage
freya022 Jun 18, 2022
79934a3
Put licence
freya022 Jun 18, 2022
0ad077c
Reorganize DataObject setters
freya022 Jun 18, 2022
ebe092a
Add null checks
freya022 Jun 18, 2022
ea8e88c
Rename put to set
freya022 Jun 18, 2022
fafa022
Add docs for mapper
freya022 Jun 18, 2022
af50f6a
Add langs
freya022 Jun 18, 2022
9f68608
Add DiscordLocale docs
freya022 Jun 18, 2022
4c6c543
Check unknown locales and log unknown locales when deserializing
freya022 Jun 18, 2022
9a00bdb
Change setX(DiscordLocale) to setXLocalization(DiscordLocale)
freya022 Jun 18, 2022
96fd4cd
Reformat
freya022 Jun 18, 2022
21e3653
Renaming
freya022 Jun 18, 2022
d0c8ab1
Format & sort locales
freya022 Jun 18, 2022
312fd4f
Add `@Nonnull`
freya022 Jun 18, 2022
8dd51e5
Remove comment
freya022 Jun 18, 2022
36750cf
Move files to package
freya022 Jun 18, 2022
0dcb33b
Reference DDocs
freya022 Jun 18, 2022
01038ce
Typo
freya022 Jun 18, 2022
e41db62
Add null checks
freya022 Jun 18, 2022
fc6b241
Partial revert of 9a00bdb82037e631b2dba8e24cf6c377806701be
freya022 Jun 18, 2022
29086e6
Add `@throws`
freya022 Jun 18, 2022
88a0a81
Apply suggestions from code review
freya022 Jun 18, 2022
1264ab0
Merge remote-tracking branch 'freya022/feature/command-localization' …
freya022 Jun 18, 2022
f400485
Reword rest of LocalizationMap getters
freya022 Jun 18, 2022
e196bd6
Apply suggestion
freya022 Jun 18, 2022
4b9aa5d
Expose and rename logger
freya022 Jun 18, 2022
e01d454
Reformat
freya022 Jun 18, 2022
51842a3
Add more throws
freya022 Jun 18, 2022
d8d3bbc
Add null check and docs to setLocalizationMapper
freya022 Jun 18, 2022
e0f2e0f
Who doesn't like exceptions
freya022 Jun 18, 2022
081f78d
Update src/main/java/net/dv8tion/jda/api/interactions/commands/Comman…
freya022 Jun 25, 2022
2a7a3e2
Update src/main/java/net/dv8tion/jda/api/interactions/commands/build/…
freya022 Jun 25, 2022
9c071a7
Update src/main/java/net/dv8tion/jda/api/interactions/commands/build/…
freya022 Jun 25, 2022
86d0f41
Apply suggestions from code review
freya022 Jun 25, 2022
643e34b
Update src/main/java/net/dv8tion/jda/api/interactions/commands/build/…
freya022 Jun 25, 2022
e43bce1
Apply suggestions from code review
freya022 Jun 25, 2022
3738db5
Add description to reconstructed objects
freya022 Jun 25, 2022
f28202e
Put name checks, expose setName
freya022 Jun 25, 2022
456342d
Fix returns & magic constants
freya022 Jun 25, 2022
a3a332e
Docs
freya022 Jun 25, 2022
d606535
Reformat docs
freya022 Jun 25, 2022
fa11136
Wrap exceptions
freya022 Jun 25, 2022
dc9ac2b
Rearrange code, checks
freya022 Jun 25, 2022
a8eece9
Rearrange code
freya022 Jun 26, 2022
e60b6b4
Move LocalizationMapper to internals, use LocalizationFunction for users
freya022 Jun 26, 2022
8927c4f
Reintroduce locale vararg in ResourceBundleLocalizationFunction
freya022 Jun 26, 2022
1dcd6cf
Rework reconstructing localization maps
freya022 Jun 26, 2022
950c1ff
Docs
freya022 Jun 26, 2022
a7f84b5
Use DiscordLocale in ResourceBundleLocalizationFunction
freya022 Jun 26, 2022
b4dd825
Fix unmodifiable localization map
freya022 Jun 26, 2022
8e9da62
Add localization example
freya022 Jun 26, 2022
0727bd2
Add links to example
freya022 Jun 26, 2022
466a26d
Update translations
freya022 Jun 26, 2022
f2253ff
Merge branch 'master' into feature/command-localization
freya022 Jun 26, 2022
d56548d
Fix javadoc
freya022 Jun 26, 2022
9176980
Fix javadoc
freya022 Jun 26, 2022
03676db
Document constants, add throws
freya022 Jun 28, 2022
07108d7
Move constants from impl
freya022 Jun 28, 2022
7bc028b
Add `@see`
freya022 Jun 28, 2022
abaf00d
more ResourceBundleLocalizationFunction docs
freya022 Jun 28, 2022
af478a2
Change example
freya022 Jun 28, 2022
91b85d9
Rearrange code
freya022 Jun 28, 2022
e2f396c
Merge branch 'master' into feature/command-localization
freya022 Jun 28, 2022
4848dda
Fix merge
freya022 Jun 28, 2022
95081ea
Add missing `@CheckReturnValue`
freya022 Jun 28, 2022
b434ad0
Add `@see`
freya022 Jul 3, 2022
e40cfce
Remove comment
freya022 Jul 3, 2022
d46d7d6
Clarify string value length
freya022 Jul 3, 2022
e54acb5
Perhaps
freya022 Jul 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ public Map<DiscordLocale, String> apply(@Nonnull String localizationKey)
}

/**
* Provides a {@link ResourceBundleLocalizationFunction} builder with the provided bundle having the specified name and locale.
* Creates an empty {@link ResourceBundleLocalizationFunction} builder and adds the provided bundle and locale.
* <br>This is the same as using {@code ResourceBundleLocalizationFunction.empty().addBundle(resourceBundle, locale)}
*
* <p><b>Example usage:</b>
* <br>This creates a LocalizationFunction from a French ResourceBundle (MyCommands_fr.properties)
*
* <pre><code>
* final LocalizationFunction localizationFunction = ResourceBundleLocalizationFunction
* .fromBundle(ResourceBundle.getBundle("MyCommands", Locale.FRENCH), DiscordLocale.FRENCH)
* .build();
* </code></pre>
*
* @param resourceBundle
* The resource bundle to get the localized strings from
Expand All @@ -80,8 +90,18 @@ public static Builder fromBundle(@Nonnull ResourceBundle resourceBundle, @Nonnul
}

/**
* Provides a {@link ResourceBundleLocalizationFunction} builder with the provided bundles.
* Creates a {@link ResourceBundleLocalizationFunction} builder with the provided bundles.
* <br>This will insert the resource bundles with the specified name, with each specified locale.
* <br>This is the same as using {@code ResourceBundleLocalizationFunction.empty().addBundles(baseName, locales)}
*
* <p><b>Example usage:</b>
* <br>This creates a LocalizationFunction from 2 resource bundles, one in Spanish (MyCommands_es_ES.properties) and one in French (MyCommands_fr.properties)
*
* <pre><code>
* final LocalizationFunction localizationFunction = ResourceBundleLocalizationFunction
* .fromBundles("MyCommands", DiscordLocale.SPANISH, DiscordLocale.FRENCH)
* .build();
* </code></pre>
*
* @param baseName
* The base name of the resource bundle, for example, the base name of {@code "MyBundle_fr_FR.properties"} would be {@code "MyBundle"}
Expand All @@ -105,7 +125,7 @@ public static Builder fromBundles(@Nonnull String baseName, @Nonnull DiscordLoca
}

/**
* Provides an empty {@link ResourceBundleLocalizationFunction} builder.
* Creates an empty {@link ResourceBundleLocalizationFunction} builder.
*
* @return The empty builder
*/
Expand All @@ -115,13 +135,21 @@ public static Builder empty()
return new Builder();
}

/**
* Builder for {@link ResourceBundleLocalizationFunction}
* <br>Use the factory methods in {@link ResourceBundleLocalizationFunction} to create instances of this builder
*/
freya022 marked this conversation as resolved.
Show resolved Hide resolved
public static class Builder
{
private final Set<Bundle> bundles = new HashSet<>();

protected Builder() {}

/**
* Adds a resource bundle to this builder
*
* <p>You can see {@link #fromBundle(ResourceBundle, DiscordLocale)} for an example
*
* @param resourceBundle
* The {@link ResourceBundle} to get the localized strings from
*
Expand All @@ -136,6 +164,8 @@ public static class Builder
* </ul>
*
* @return This builder for chaining convenience
*
* @see #fromBundle(ResourceBundle, DiscordLocale)
*/
@Nonnull
public Builder addBundle(@Nonnull ResourceBundle resourceBundle, @Nonnull DiscordLocale locale)
Expand All @@ -152,6 +182,8 @@ public Builder addBundle(@Nonnull ResourceBundle resourceBundle, @Nonnull Discor
* Adds a resource bundle to this builder
* <br>This will insert the resource bundles with the specified name, with each specified locale.
*
* <p>You can see {@link #fromBundles(String, DiscordLocale...)} for an example
*
* @param baseName
* The base name of the resource bundle, for example, the base name of {@code "MyBundle_fr_FR.properties"} would be {@code "MyBundle"}
*
Expand All @@ -166,6 +198,7 @@ public Builder addBundle(@Nonnull ResourceBundle resourceBundle, @Nonnull Discor
* </ul>
*
* @return This builder for chaining convenience
* @see #fromBundles(String, DiscordLocale...)
*/
@Nonnull
public Builder addBundles(@Nonnull String baseName, @Nonnull DiscordLocale... locales)
Expand Down