Skip to content

Commit

Permalink
Enhance logging of logger and expose owning plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Aug 16, 2024
1 parent 5924498 commit 7b6b961
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 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.1.3"
publishingVersion = "2.1.4"
}
version = publishData.getVersion()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static ILocalizer getPluginLocalizer(Class<? extends Plugin> plugin) {
return LOCALIZER.getOrDefault(plugin, DEFAULT);
}

Plugin plugin();

static String escape(String propertyKey) {
return String.format("<i18n:%s>", propertyKey);
}
Expand Down Expand Up @@ -120,6 +122,11 @@ default String localize(String message) {
void registerChild(ILocalizer localizer);

public class DummyLocalizer implements ILocalizer {
@Override
public Plugin plugin() {
return null;
}

@Override
public void setLocale(String language) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* <p>
* You can change the currently used locale every time via {@link #setLocale(String)}.
* <p>
* The localizer also allows to use locales which are not included in the ressources folder.
* The localizer also allows to use locales which are not included in the resources folder.
*
* @since 1.0.0
*/
Expand All @@ -64,7 +64,7 @@ public class Localizer implements ILocalizer {
private final Map<String, String> runtimeLocaleCodes = new HashMap<>();
private final Map<String, ResourceBundle> languages = new HashMap<>();
private final Function<Player, String> userLocale;
private final List<ILocalizer> childs = new ArrayList<>();
private final List<ILocalizer> children = new ArrayList<>();
private boolean checked;

/**
Expand Down Expand Up @@ -190,6 +190,11 @@ private void createDefaults() {
runtimeLocaleCodes.put("dialog.rightClickRemove", "Right click to remove");
}

@Override
public Plugin plugin() {
return plugin;
}

/**
* Change the locale to the language. If the locale is not present the fallback locale will be used.
*
Expand Down Expand Up @@ -280,7 +285,7 @@ public String getValue(String key, String language) {
}

if (result == null) {
for (var child : childs) {
for (var child : children) {
result = child.getValue(key, language);
if (result != null) break;
}
Expand Down Expand Up @@ -553,7 +558,8 @@ public void addLocaleCodes(Map<String, String> runtimeLocaleCodes) {

@Override
public void registerChild(ILocalizer localizer) {
childs.add(localizer);
plugin.getLogger().info("Localizer from " + localizer.plugin().getName() + " registered as child.");
children.add(localizer);
}

private static class DummyResourceBundle extends ResourceBundle {
Expand Down

0 comments on commit 7b6b961

Please sign in to comment.