2727import java .nio .charset .StandardCharsets ;
2828import java .util .*;
2929import java .util .logging .Level ;
30+ import java .util .regex .PatternSyntaxException ;
3031
3132public class TextManager implements Reloadable {
3233 private final QuickShop plugin ;
@@ -35,7 +36,6 @@ public class TextManager implements Reloadable {
3536 private final TextMapper mapper = new TextMapper ();
3637 private final static String CROWDIN_LANGUAGE_FILE = "/master/src/main/resources/lang/%locale%/messages.json" ;
3738 public final List <PostProcessor > postProcessors = new ArrayList <>();
38- private List <String > disabledLanguages = new ArrayList <>();
3939
4040
4141 public TextManager (QuickShop plugin ) {
@@ -66,7 +66,6 @@ private File getOverrideFilesFolder(@NotNull String crowdinPath) {
6666 private void reset () {
6767 mapper .reset ();
6868 postProcessors .clear ();
69- disabledLanguages .clear ();
7069 }
7170
7271 /**
@@ -93,14 +92,14 @@ private JsonConfiguration loadBundled(String file) {
9392 public void load () {
9493 plugin .getLogger ().info ("Checking for translation updates..." );
9594 this .reset ();
96- disabledLanguages = plugin .getConfig ().getStringList ("disabled -languages" );
95+ List < String > enabledLanguagesRegex = plugin .getConfig ().getStringList ("enabled -languages" );
9796 // Multi File and Multi-Language loader
9897 distribution .getAvailableLanguages ().parallelStream ().forEach (crowdinCode -> distribution .getAvailableFiles ().parallelStream ().forEach (crowdinFile -> {
9998 try {
10099 // Minecraft client use lowercase wi
101100 String minecraftCode = crowdinCode .toLowerCase (Locale .ROOT ).replace ("-" , "_" );
102- if (disabledLanguages . contains (minecraftCode ) || disabledLanguages . contains ( crowdinCode )) {
103- Util .debugLog ("Locale " + crowdinCode + "(" + minecraftCode + ") has been disabled, skipping ." );
101+ if (! localeEnabled (minecraftCode , enabledLanguagesRegex )) {
102+ Util .debugLog ("Locale: " + minecraftCode + " not enabled in configuration ." );
104103 return ;
105104 }
106105 Util .debugLog ("Loading translation for locale: " + crowdinCode + " (" + minecraftCode + ")" );
@@ -128,6 +127,19 @@ public void load() {
128127 postProcessors .add (new ColorProcessor ());
129128 }
130129
130+ private boolean localeEnabled (String locale , List <String > regex ){
131+ for (String languagesRegex : regex ) {
132+ try {
133+ if (locale .matches (languagesRegex )) {
134+ return true ;
135+ }
136+ } catch (PatternSyntaxException exception ) {
137+ Util .debugLog ("Pattern " + languagesRegex + " invalid, skipping..." );
138+ }
139+ }
140+ return false ;
141+ }
142+
131143 private void applyOverrideConfiguration (JsonConfiguration distributionConfiguration , JsonConfiguration overrideConfiguration ) {
132144 for (String key : overrideConfiguration .getKeys (true )) {
133145 if ("language-version" .equals (key ) || "config-version" .equals (key ) || "version" .equals (key )) {
0 commit comments