mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Don't use the real Briar directory for unit tests.
This commit is contained in:
@@ -23,8 +23,11 @@ public interface I18n {
|
|||||||
/** Saves the i18n locale to Briar/Data/locale.cfg. */
|
/** Saves the i18n locale to Briar/Data/locale.cfg. */
|
||||||
void saveLocale() throws IOException;
|
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. */
|
/** 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. */
|
/** Returns the ComponentOrientation of the current i18n locale. */
|
||||||
ComponentOrientation getComponentOrientation();
|
ComponentOrientation getComponentOrientation();
|
||||||
|
|||||||
@@ -122,22 +122,21 @@ public class I18nImpl implements I18n {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadLocale() throws IOException {
|
public void loadLocale() throws IOException {
|
||||||
loadLocale(FileUtils.getBriarDirectory());
|
loadLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadLocale(File dir) throws IOException {
|
public void loadLocale(File f) throws IOException {
|
||||||
Scanner s = new Scanner(new File(dir, "Data/locale.cfg"));
|
Scanner s = new Scanner(f);
|
||||||
if(s.hasNextLine()) setLocale(new Locale(s.nextLine()));
|
if(s.hasNextLine()) setLocale(new Locale(s.nextLine()));
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLocale() throws IOException {
|
public void saveLocale() throws IOException {
|
||||||
saveLocale(FileUtils.getBriarDirectory());
|
saveLocale(new File(FileUtils.getBriarDirectory(), "Data/locale.cfg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLocale(File dir) throws IOException {
|
public void saveLocale(File f) throws IOException {
|
||||||
File localeCfg = new File(dir, "Data/locale.cfg");
|
FileOutputStream out = new FileOutputStream(f);
|
||||||
FileOutputStream out = new FileOutputStream(localeCfg);
|
|
||||||
PrintStream print = new PrintStream(out);
|
PrintStream print = new PrintStream(out);
|
||||||
print.println(locale);
|
print.println(locale);
|
||||||
print.flush();
|
print.flush();
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class I18nTest extends TestCase {
|
|||||||
assertEquals("foo", i18n.tr("FOO"));
|
assertEquals("foo", i18n.tr("FOO"));
|
||||||
i18n.setLocale(Locale.FRANCE);
|
i18n.setLocale(Locale.FRANCE);
|
||||||
assertEquals("le foo", i18n.tr("FOO"));
|
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"));
|
assertEquals("foo", i18n.tr("FOO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,13 +83,13 @@ public class I18nTest extends TestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSaveAndLoadLocale() throws IOException {
|
public void testSaveAndLoadLocale() throws IOException {
|
||||||
testDir.mkdirs();
|
testDir.mkdirs();
|
||||||
new File(testDir, "Data").mkdir();
|
File f = new File(testDir, "locale.cfg");
|
||||||
i18n.setLocale(new Locale("fr"));
|
i18n.setLocale(new Locale("fr"));
|
||||||
assertEquals("le foo", i18n.tr("FOO"));
|
assertEquals("le foo", i18n.tr("FOO"));
|
||||||
i18n.saveLocale();
|
i18n.saveLocale(f);
|
||||||
i18n.setLocale(new Locale("zh")); // No translation - use default
|
i18n.setLocale(new Locale("zh")); // No translation - use default
|
||||||
assertEquals("foo", i18n.tr("FOO"));
|
assertEquals("foo", i18n.tr("FOO"));
|
||||||
i18n.loadLocale();
|
i18n.loadLocale(f);
|
||||||
assertEquals("le foo", i18n.tr("FOO"));
|
assertEquals("le foo", i18n.tr("FOO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user