So you can do this using a language file. It would be something like:
1- Method to recover language file selected based on language option selected in Jmenuitem (files . lang would be in the lang folder of the project):
class Language {
private Properties language;
public void loadLanguage(int lang) throws FileNotFoundException,
IOException {
if (lang == 0)
language = getLanguageProperties("lang/english.lang");
else if (lang == 1)
language = getLanguageProperties("lang/portuguese.lang");
}
protected Properties getLanguageProperties(String languageFile)
throws FileNotFoundException, IOException {
File file = new File(languageFile);
Properties props = new Properties();
props.load(new FileInputStream(file));
return props;
}
}
2-Retrieve text from a component via its key:
class LanguageController {
public static String getProperty(String key) {
return language.getProperty(key);
}
}
3-Loading text from application swing components:
JButton componente = new JButton();
componente.setText(
LanguageController.getProperty(
"BOTAO_KEY")
4- The language file would contain the content with the key and value ("English.lang"):
BOTAO_KEY=Texto do meu button
If you’re curious, take a look at the project where I did this internationalization treatment: https://sourceforge.net/projects/j-syncker/. There is a language menu that allows the user to change the language at runtime. I hope to have helped ^^
To downvoters: it is good to comment on alternatives to improve the issue.
– vinibrsl
What kind of application? Is it made in swing? If yes, you need to change all the texts manually in a method to part.
– user28595
And a desktop application and it is made with swing, I will change and put here as was my code.
– MarcosLeme
Please post a code that is [mcve], so that it is possible to reproduce and test it.
– user28595