Skip to content

Commit

Permalink
Add per user locale
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Jul 27, 2024
1 parent 4b49b08 commit 66130b2
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 77 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
publishData {
addRepo(Repo.main("", "", false))
addRepo(Repo.snapshot("SNAPSHOT", "", false))
publishingVersion = "2.0.11"
publishingVersion = "2.1.0"
}
version = publishData.getVersion()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

package de.eldoria.eldoutilities.localization;

import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -78,9 +78,23 @@ static boolean isLocaleCode(String message) {
*/
void addLocaleCodes(Map<String, String> runtimeLocaleCodes);

String getMessage(String key, CommandSender sender);

@Nullable
String getValue(String key);

String getMessage(String key, String language);

@Nullable
String getValue(String key, CommandSender sender);

@Nullable
String getValue(String key, String language);

ResourceBundle localeBundle(String language);

ResourceBundle defaultBundle();

/**
* Translates a String with Placeholders. Can handle multiple messages with replacements. Add replacements in the
* right order.
Expand All @@ -89,7 +103,19 @@ static boolean isLocaleCode(String message) {
* @return Replaced Messages
* @since 1.2.3
*/
String localize(String message);
default String localize(String message) {
return localize(null, message);
}

/**
* Translates a String with Placeholders. Can handle multiple messages with replacements. Add replacements in the
* right order.
*
* @param message Message to translate
* @return Replaced Messages
* @since 1.2.3
*/
String localize(CommandSender sender, String message);

void registerChild(ILocalizer localizer);

Expand All @@ -112,13 +138,43 @@ public String[] getIncludedLocales() {
public void addLocaleCodes(Map<String, String> runtimeLocaleCodes) {
}

@Override
public String getMessage(String key, CommandSender sender) {
return key;
}

@Override
public @Nullable String getValue(String key) {
return key;
}

@Override
public String getMessage(String key, String language) {
return key;
}

@Override
public @Nullable String getValue(String key, CommandSender sender) {
return key;
}

@Override
public @Nullable String getValue(String key, String language) {
return key;
}

@Override
public ResourceBundle localeBundle(String language) {
return null;
}

@Override
public ResourceBundle defaultBundle() {
return null;
}

@Override
public String localize(String message) {
public String localize(CommandSender sender, String message) {
return message;
}

Expand Down
Loading

0 comments on commit 66130b2

Please sign in to comment.