-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow translating items inside hover actions (fixes #202)
- Loading branch information
1 parent
2b4535e
commit df14b63
Showing
10 changed files
with
148 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/src/main/java/com/rexcantor64/triton/api/language/Localized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.rexcantor64.triton.api.language; | ||
|
||
/** | ||
* Represents something that has a language. | ||
* It can be a player or even a language itself. | ||
* | ||
* @since 3.8.0 | ||
*/ | ||
public interface Localized { | ||
|
||
/** | ||
* Get the string identifier of the language of this object. | ||
* Depending on the underlying implementation, it can get it from a | ||
* player's current language, a language object or even a string itself. | ||
* | ||
* @return The string identifier of the language of this object. | ||
* @since 3.8.0 | ||
*/ | ||
default String getLanguageId() { | ||
final Language language = this.getLanguage(); | ||
if (language == null) { | ||
return null; | ||
} | ||
return this.getLanguage().getName(); | ||
} | ||
|
||
/** | ||
* Get the language of this object. | ||
* Depending on the underlying implementation, it can get it from a | ||
* player's current language, a language object or derive it from its string id. | ||
* | ||
* @return The language of this object. | ||
* @since 3.8.0 | ||
*/ | ||
Language getLanguage(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
core/src/main/java/com/rexcantor64/triton/language/localized/StringLocale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.rexcantor64.triton.language.localized; | ||
|
||
import com.rexcantor64.triton.Triton; | ||
import com.rexcantor64.triton.api.language.Language; | ||
import com.rexcantor64.triton.api.language.Localized; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Data | ||
@RequiredArgsConstructor | ||
public class StringLocale implements Localized { | ||
|
||
private final String languageId; | ||
private Language cachedLanguage; | ||
|
||
@Override | ||
public Language getLanguage() { | ||
if (cachedLanguage == null) { | ||
cachedLanguage = Triton.get().getLanguageManager().getLanguageByName(languageId, true); | ||
} | ||
return cachedLanguage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.