I'm writing a multilingual application. Created a demo:
public class SwingLang {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(230,500);
JPanel panel = new JPanel();
String[] x = new String[7];
//текст "Checking your configuration and account"
x[0] = "ব্যবস্থা এবং একাউন্ট দেখা"; //Bengal
x[1] = "తయారీ మరియు ఖాతా తనిఖీ"; //Telugu
x[2] = "तयारी र खाता जाँच"; //Nepali
x[3] = "සූදානම් වීම සහ ගිණුම පරීක්\u200Dෂාව"; //Sinhalese
x[4] = "तैयारी और खाता जांच"; //Hindi
x[5] = "தயாரிப்பு மற்றும் கணக்கு சரிபார்ப்பு"; //Tamil
x[6] = "การเตรียมและตรวจสอบบัญชี"; //Thai
for (int i = 0; i < x.length; i++) {
JLabel label = new JLabel(x[i]);
System.out.println(x[i]);
panel.add(label);
}
frame.add(panel);
frame.setVisible(true);
}
}
These languages in the swing application on Windows 10 are displayed as squares and this is the main problem.
All these languages are displayed correctly on Linux Ubuntu. On Windows, the console output is also correct.
Tried to pass a string in unicode - the result is the same. It outputs to the console as expected, swing outputs squares.
Most of all, I am interested in what I, as a developer, can do with the code or its launch parameters, so as not to write instructions on what the user should do with his OS
I tried to substitute fonts through the Font class, but this did not help either. Although the idea of using fonts is not very good, considering that Linux reads without them.
And also I tried to change the versions of Java Open JDK 17 to 21. Newer than 21 are not compatible with Lombok for me, so I remove this option too
(Based on this answer and comments mentioned by user85421 & Ivar https://stackoverflow.com/a/31515771/16037941)
Try using a logical font such as SANS_SERIF which should pull from one or more physical font sources to generate the correct output initially.
Next check to see which of those texts can be displayed on the user computer using a function run on startup based the code provided in user85421's comment. IF there are languages which can't be used as there is no available font for them, then I would also mention to the user in some type of aside/settings: "We can't display language X because your PC does not have the font installed" that or attempt to sub fonts in the case where the OS is windows or attempt to install a font or font(s) yourself on first startup you know would work, but that for me is a touch dicey and can by annoying (I have had to do this for programs run through WINE, its a pet-peeve)
To add some additional context: To my knowledge there is not alot you can do, some non-latin characters require a bit of config on to OS side. Best of luck