Search in sources :

Example 6 with TableLocaleSource

use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.

the class LocalizerTest method testAddExistingLocale.

public void testAddExistingLocale() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    TableLocaleSource table = new TableLocaleSource();
    table.setLocaleMapping("textID", "text");
    l.registerLocaleResource(TEST_LOCALE, table);
    OrderedMap<String, String> localeData = l.getLocaleData(TEST_LOCALE);
    boolean result = l.addAvailableLocale(TEST_LOCALE);
    if (result) {
        fail("Localizer overwrote existing locale");
    }
    OrderedMap<String, String> newLocaleData = l.getLocaleData(TEST_LOCALE);
    if (!localeData.equals(newLocaleData)) {
        fail("Localizer overwrote existing locale");
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 7 with TableLocaleSource

use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.

the class LocalizerTest method testTextMappingOverwrite.

public void testTextMappingOverwrite() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    TableLocaleSource table = new TableLocaleSource();
    table.setLocaleMapping("textID", "oldText");
    table.setLocaleMapping("textID", "newText");
    l.registerLocaleResource(TEST_LOCALE, table);
    if (!l.hasMapping(TEST_LOCALE, "textID")) {
        fail("Localizer does not contain overwritten text mapping");
    }
    if (!"newText".equals(l.getLocaleData(TEST_LOCALE).get("textID"))) {
        fail("Newly overwritten text mapping does not match source");
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 8 with TableLocaleSource

use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.

the class LocalizerTest method testNullArgs.

public void testNullArgs() {
    Localizer l = new Localizer();
    l.addAvailableLocale("test");
    TableLocaleSource table = new TableLocaleSource();
    try {
        l.addAvailableLocale(null);
        fail("addAvailableLocale: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    if (l.hasLocale(null)) {
        fail("Localizer reports it contains null locale");
    }
    try {
        l.registerLocaleResource(null, new TableLocaleSource());
        fail("setLocaleData: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.registerLocaleResource("test", null);
        fail("setLocaleData: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    if (l.getLocaleData(null) != null) {
        fail("getLocaleData: Localizer returns mappings for null locale");
    }
    try {
        l.getLocaleMap(null);
        fail("getLocaleMap: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    try {
        table.setLocaleMapping(null, "text");
        fail("setLocaleMapping: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        table.setLocaleMapping(null, null);
        fail("setLocaleMapping: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.hasMapping(null, "textID");
        fail("hasMapping: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    if (l.hasMapping("test", null)) {
        fail("Localization reports it contains null mapping");
    }
    try {
        l.destroyLocale(null);
        fail("destroyLocale: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.getText("textID", (String) null);
        fail("getText: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    try {
        l.getText(null, "test");
        fail("getText: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 9 with TableLocaleSource

use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.

the class LocalizerTest method testFallbacks.

public void testFallbacks() {
    Localizer localizer = new Localizer(true, true);
    localizer.addAvailableLocale("one");
    localizer.addAvailableLocale("two");
    TableLocaleSource firstLocale = new TableLocaleSource();
    firstLocale.setLocaleMapping("data", "val");
    firstLocale.setLocaleMapping("data2", "vald2");
    localizer.registerLocaleResource("one", firstLocale);
    TableLocaleSource secondLocale = new TableLocaleSource();
    firstLocale.setLocaleMapping("data", "val2");
    localizer.registerLocaleResource("two", secondLocale);
    localizer.setDefaultLocale("one");
    localizer.setLocale("two");
    String text = localizer.getText("data2");
    assertEquals("fallback", text, "vald2");
    String shouldBeNull = localizer.getText("noexist");
    assertNull("Localizer didn't return null value", shouldBeNull);
    localizer.setToDefault();
    shouldBeNull = localizer.getText("noexist");
    assertNull("Localizer didn't return null value", shouldBeNull);
    assertNull("Localizer didn't return null value", shouldBeNull);
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 10 with TableLocaleSource

use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.

the class LocalizerTest method testGetTextNoCurrentLocale.

public void testGetTextNoCurrentLocale() {
    Localizer l = new Localizer();
    TableLocaleSource table = new TableLocaleSource();
    l.addAvailableLocale("test");
    l.setDefaultLocale("test");
    table.setLocaleMapping("textID", "text");
    l.registerLocaleResource("test", table);
    try {
        l.getText("textID");
        fail("Retrieved current locale text when current locale not set");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Aggregations

TableLocaleSource (org.javarosa.core.services.locale.TableLocaleSource)11 Localizer (org.javarosa.core.services.locale.Localizer)10 UnregisteredLocaleException (org.javarosa.core.util.UnregisteredLocaleException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IFormElement (org.javarosa.core.model.IFormElement)1 QuestionDef (org.javarosa.core.model.QuestionDef)1 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 DummyFormEntryPrompt (org.javarosa.core.model.test.DummyFormEntryPrompt)1 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)1 Element (org.kxml2.kdom.Element)1