diff --git a/api/net/sf/briar/api/i18n/I18n.java b/api/net/sf/briar/api/i18n/I18n.java index c1930e5678d31c299c16eb9d02315d2e9d3c29c6..ef8290c42753648b95be33982ebf343ea5860165 100644 --- a/api/net/sf/briar/api/i18n/I18n.java +++ b/api/net/sf/briar/api/i18n/I18n.java @@ -23,8 +23,11 @@ public interface I18n { /** Saves the i18n locale to Briar/Data/locale.cfg. */ void saveLocale() throws IOException; + /** Loads the i18n locale from the given file. */ + void loadLocale(File f) throws IOException; + /** Saves the i18n locale to the given file. */ - void saveLocale(File dir) throws IOException; + void saveLocale(File f) throws IOException; /** Returns the ComponentOrientation of the current i18n locale. */ ComponentOrientation getComponentOrientation(); diff --git a/components/net/sf/briar/i18n/I18nImpl.java b/components/net/sf/briar/i18n/I18nImpl.java index c1c9aafcedd176560450d19aee3e5142d216f343..106b3032fb792e0045666da449def991e4c2b32c 100644 --- a/components/net/sf/briar/i18n/I18nImpl.java +++ b/components/net/sf/briar/i18n/I18nImpl.java @@ -122,22 +122,21 @@ public class I18nImpl implements I18n { } public void loadLocale() throws IOException { - loadLocale(FileUtils.getBriarDirectory()); + loadLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg")); } - public void loadLocale(File dir) throws IOException { - Scanner s = new Scanner(new File(dir, "Data/locale.cfg")); + public void loadLocale(File f) throws IOException { + Scanner s = new Scanner(f); if(s.hasNextLine()) setLocale(new Locale(s.nextLine())); s.close(); } public void saveLocale() throws IOException { - saveLocale(FileUtils.getBriarDirectory()); + saveLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg")); } - public void saveLocale(File dir) throws IOException { - File localeCfg = new File(dir, "Data/locale.cfg"); - FileOutputStream out = new FileOutputStream(localeCfg); + public void saveLocale(File f) throws IOException { + FileOutputStream out = new FileOutputStream(f); PrintStream print = new PrintStream(out); print.println(locale); print.flush(); diff --git a/test/net/sf/briar/i18n/I18nTest.java b/test/net/sf/briar/i18n/I18nTest.java index 1b0cd5e18f42126dc476da280dd964e6ee2a4720..f6be63182e75af23c8363cc988cd85d8f2628937 100644 --- a/test/net/sf/briar/i18n/I18nTest.java +++ b/test/net/sf/briar/i18n/I18nTest.java @@ -46,7 +46,7 @@ public class I18nTest extends TestCase { assertEquals("foo", i18n.tr("FOO")); i18n.setLocale(Locale.FRANCE); assertEquals("le foo", i18n.tr("FOO")); - i18n.setLocale(Locale.CHINA); // No translation - use defaul + i18n.setLocale(Locale.CHINA); // No translation - use default assertEquals("foo", i18n.tr("FOO")); } @@ -83,13 +83,13 @@ public class I18nTest extends TestCase { @Test public void testSaveAndLoadLocale() throws IOException { testDir.mkdirs(); - new File(testDir, "Data").mkdir(); + File f = new File(testDir, "locale.cfg"); i18n.setLocale(new Locale("fr")); assertEquals("le foo", i18n.tr("FOO")); - i18n.saveLocale(); + i18n.saveLocale(f); i18n.setLocale(new Locale("zh")); // No translation - use default assertEquals("foo", i18n.tr("FOO")); - i18n.loadLocale(); + i18n.loadLocale(f); assertEquals("le foo", i18n.tr("FOO")); }