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
java -jar JDarkroom.jar en-US
java -jar JDarkroom.jar en

View file

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