TranslationTool: add a 'Test' button to launch Micropolis with translated strings

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@661 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-05-21 13:28:14 +00:00
parent 8f67c73383
commit 30a5b6d53c
2 changed files with 95 additions and 12 deletions

View file

@ -11,6 +11,9 @@ public class TranslationTool extends JFrame
{
JTable stringsTable;
StringsModel stringsModel;
String lastLanguage;
String lastCountry;
String lastVariant;
public TranslationTool()
throws IOException
@ -44,11 +47,45 @@ public class TranslationTool extends JFrame
}});
buttonPane.add(btn);
btn = new JButton("Test");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onTestClicked();
}});
buttonPane.add(btn);
pack();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
}
private void onTestClicked()
{
try
{
String javaPath = "java";
String classPath = "." + System.getProperty("path.separator") + "micropolisj.jar";
ProcessBuilder processBuilder =
new ProcessBuilder(javaPath,
"-Duser.language="+lastLanguage,
"-Duser.country="+lastCountry,
"-Duser.variant="+lastVariant,
"-cp",
classPath,
"micropolisj.Main"
);
processBuilder.start();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this,
e.getMessage(),
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
private void onSaveClicked()
{
try
@ -91,22 +128,22 @@ public class TranslationTool extends JFrame
try
{
String language = langEntry.getText();
String country = countryEntry.getText();
String variant = variantEntry.getText();
lastLanguage = langEntry.getText();
lastCountry = countryEntry.getText();
lastVariant = variantEntry.getText();
if (language.length() == 0) {
if (lastLanguage.length() == 0) {
throw new Exception("Language is required");
}
String code = language;
if (country.length() != 0) {
code += "_" + country;
if (variant.length() != 0) {
code += "_" + variant;
String code = lastLanguage;
if (lastCountry.length() != 0) {
code += "_" + lastCountry;
if (lastVariant.length() != 0) {
code += "_" + lastVariant;
}
}
else if (variant.length() != 0) {
else if (lastVariant.length() != 0) {
throw new Exception("Cannot specify variant without a country code.");
}
@ -231,7 +268,13 @@ public class TranslationTool extends JFrame
@Override
public boolean isCellEditable(int row, int col)
{
return col != 0;
if (col == 0) {
return false;
}
else {
MyLocaleInfo l = locales.get(col-1);
return l.code != null;
}
}
@Override
@ -250,7 +293,7 @@ public class TranslationTool extends JFrame
File getPFile(String file, String localeCode)
{
return new File("strings/"
return new File("micropolisj/"
+file
+(localeCode != null ? "_"+localeCode : "")
+".properties");
@ -263,6 +306,9 @@ public class TranslationTool extends JFrame
for (String file : FILES)
{
Properties p = new Properties();
if (localeCode == null) {
p.load(getClass().getResourceAsStream("/micropolisj/"+file+".properties"));
}
File f = getPFile(file, localeCode);
if (f.exists()) {
p.load(new FileInputStream(f));
@ -274,6 +320,15 @@ public class TranslationTool extends JFrame
fireTableStructureChanged();
}
void makeDirectories(File f)
throws IOException
{
File d = f.getParentFile();
if (d != null) {
d.mkdirs();
}
}
void save()
throws IOException
{
@ -285,8 +340,10 @@ public class TranslationTool extends JFrame
{
Properties p = l.propsMap.get(file);
File f = getPFile(file, l.code);
makeDirectories(f);
p.store(new FileOutputStream(f), l.code);
}
l.dirty = false;
}
}
}