Skip to content

Commit bc48953

Browse files
committed
feat(translations): introduce LegacyTranslationService and ModernTranslationService for improved localization
1 parent 234cdb4 commit bc48953

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.onelitefeather.antiredstoneclockremastered.service.impl;
2+
3+
import net.kyori.adventure.key.Key;
4+
import net.kyori.adventure.translation.GlobalTranslator;
5+
import net.kyori.adventure.translation.TranslationRegistry;
6+
import net.onelitefeather.antiredstoneclockremastered.service.api.TranslationService;
7+
import net.onelitefeather.antiredstoneclockremastered.translations.PluginTranslationRegistry;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.Locale;
11+
import java.util.ResourceBundle;
12+
13+
@Deprecated(since = "2.0.13", forRemoval = true)
14+
public final class LegacyTranslationService implements TranslationService {
15+
16+
private final TranslationRegistry translationRegistry;
17+
18+
public LegacyTranslationService() {
19+
this.translationRegistry = new PluginTranslationRegistry(TranslationRegistry.create(Key.key("antiredstoneclockremastered", "translations")));
20+
this.translationRegistry.defaultLocale(Locale.US);
21+
}
22+
23+
@Override
24+
public void registerAll(@NotNull Locale locale, @NotNull ResourceBundle bundle, boolean escapeSingleQuotes) {
25+
this.translationRegistry.registerAll(locale, bundle, escapeSingleQuotes);
26+
}
27+
28+
@Override
29+
public void registerGlobal() {
30+
GlobalTranslator.translator().addSource(this.translationRegistry);
31+
}
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.onelitefeather.antiredstoneclockremastered.service.impl;
2+
3+
import net.kyori.adventure.key.Key;
4+
import net.kyori.adventure.text.minimessage.translation.MiniMessageTranslationStore;
5+
import net.kyori.adventure.translation.GlobalTranslator;
6+
import net.onelitefeather.antiredstoneclockremastered.service.api.TranslationService;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.Locale;
10+
import java.util.ResourceBundle;
11+
12+
public final class ModernTranslationService implements TranslationService {
13+
14+
private final MiniMessageTranslationStore miniMessageTranslationStore;
15+
16+
public ModernTranslationService() {
17+
this.miniMessageTranslationStore = MiniMessageTranslationStore.create(Key.key("antiredstoneclockremastered", "translations"));
18+
this.miniMessageTranslationStore.defaultLocale(Locale.US);
19+
}
20+
21+
@Override
22+
public void registerAll(@NotNull Locale locale, @NotNull ResourceBundle bundle, boolean escapeSingleQuotes) {
23+
this.miniMessageTranslationStore.registerAll(locale, bundle, escapeSingleQuotes);
24+
}
25+
26+
@Override
27+
public void registerGlobal() {
28+
GlobalTranslator.translator().addSource(this.miniMessageTranslationStore);
29+
}
30+
}

0 commit comments

Comments
 (0)