Fixed setting locale: now only language is needed: ru or en

This commit is contained in:
Yuri Torlopov 2023-03-08 12:54:01 +03:00
parent 2025e371e6
commit f9e4b60533
3 changed files with 11 additions and 15 deletions

View file

@ -1,2 +1,2 @@
@ECHO OFF @ECHO OFF
java -jar JDarkroom.jar en-US java -jar JDarkroom.jar en

View file

@ -1,2 +1,2 @@
@ECHO OFF @ECHO OFF
java -jar JDarkroom.jar ru-RU java -jar JDarkroom.jar ru

View file

@ -19,23 +19,19 @@ package me.theentropyshard.jdarkroom;
import javax.swing.*; import javax.swing.*;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
if(args.length > 0) { if(args.length > 0) {
Pattern localePattern = Pattern.compile("([a-z]{2})-([A-Z]{2})$"); String lang = args[0].toLowerCase(Locale.ROOT);
Matcher matcher = localePattern.matcher(args[0]); if(!"ruen".contains(lang)) {
if(matcher.matches()) { lang = "en";
try { }
String[] langAndCountry = args[0].split("-");
Locale.setDefault(new Locale(langAndCountry[0], langAndCountry[1])); try {
} catch (Exception se) { Locale.setDefault(new Locale(lang));
se.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} else {
System.err.println("Incorrect locale supplied: " + args[0]);
} }
} }