Search in sources :

Example 21 with Localizer

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

the class LocalizerTest method testAvailableLocales.

public void testAvailableLocales() {
    Localizer l = new Localizer();
    String[] locales;
    l.addAvailableLocale("test1");
    locales = l.getAvailableLocales();
    if (locales.length != 1 || !locales[0].equals("test1")) {
        fail("Available locales not as expected");
    }
    l.addAvailableLocale("test2");
    locales = l.getAvailableLocales();
    if (locales.length != 2 || !locales[0].equals("test1") || !locales[1].equals("test2")) {
        fail("Available locales not as expected");
    }
    l.addAvailableLocale("test3");
    locales = l.getAvailableLocales();
    if (locales.length != 3 || !locales[0].equals("test1") || !locales[1].equals("test2") || !locales[2].equals("test3")) {
        fail("Available locales not as expected");
    }
    l.destroyLocale("test2");
    locales = l.getAvailableLocales();
    if (locales.length != 2 || !locales[0].equals("test1") || !locales[1].equals("test3")) {
        fail("Available locales not as expected");
    }
    l.destroyLocale("test1");
    locales = l.getAvailableLocales();
    if (locales.length != 1 || !locales[0].equals("test3")) {
        fail("Available locales not as expected");
    }
    l.destroyLocale("test3");
    locales = l.getAvailableLocales();
    if (locales == null || locales.length != 0) {
        fail("Available locales not as expected");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 22 with Localizer

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

the class LocalizerTest method testSerialization.

public void testSerialization() {
    Localizer l = new Localizer(true, true);
    TableLocaleSource firstLocale = new TableLocaleSource();
    TableLocaleSource secondLocale = new TableLocaleSource();
    TableLocaleSource finalLocale = new TableLocaleSource();
    testSerialize(l, "empty 1");
    testSerialize(new Localizer(false, false), "empty 2");
    testSerialize(new Localizer(true, false), "empty 3");
    testSerialize(new Localizer(false, true), "empty 4");
    l.addAvailableLocale("locale1");
    testSerialize(l, "one empty locale");
    l.addAvailableLocale("locale2");
    testSerialize(l, "two empty locales");
    l.setDefaultLocale("locale2");
    testSerialize(l, "two empty locales + default");
    l.setToDefault();
    testSerialize(l, "two empty locales + default/current");
    l.setLocale("locale1");
    testSerialize(l, "two empty locales + default/current 2");
    l.setDefaultLocale(null);
    testSerialize(l, "two empty locales + current");
    l.registerLocaleResource("locale1", firstLocale);
    l.registerLocaleResource("locale2", secondLocale);
    firstLocale.setLocaleMapping("id1", "text1");
    testSerialize(l, "locales with data 1");
    firstLocale.setLocaleMapping("id2", "text2");
    testSerialize(l, "locales with data 2");
    secondLocale.setLocaleMapping("id1", "text1");
    secondLocale.setLocaleMapping("id2", "text2");
    secondLocale.setLocaleMapping("id3", "text3");
    testSerialize(l, "locales with data 3");
    secondLocale.setLocaleMapping("id2", null);
    testSerialize(l, "locales with data 4");
    finalLocale.setLocaleMapping("id1", "text1");
    finalLocale.setLocaleMapping("id4", "text4");
    l.registerLocaleResource("locale3", finalLocale);
    testSerialize(l, "locales with data 5");
    l.destroyLocale("locale2");
    testSerialize(l, "locales with data 6");
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 23 with Localizer

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

the class LocalizerTest method testDestroyCurrentLocale.

public void testDestroyCurrentLocale() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    l.setLocale(TEST_LOCALE);
    try {
        l.destroyLocale(TEST_LOCALE);
        fail("Destroyed current locale");
    } catch (IllegalArgumentException iae) {
    // expected
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 24 with Localizer

use of org.javarosa.core.services.locale.Localizer 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 25 with Localizer

use of org.javarosa.core.services.locale.Localizer 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)

Aggregations

Localizer (org.javarosa.core.services.locale.Localizer)37 TableLocaleSource (org.javarosa.core.services.locale.TableLocaleSource)10 UnregisteredLocaleException (org.javarosa.core.util.UnregisteredLocaleException)7 ArrayList (java.util.ArrayList)3 QuestionDef (org.javarosa.core.model.QuestionDef)3 FormEntryController (org.javarosa.form.api.FormEntryController)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 List (java.util.List)1 IDataReference (org.javarosa.core.model.IDataReference)1 IFormElement (org.javarosa.core.model.IFormElement)1 Condition (org.javarosa.core.model.condition.Condition)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 Recalculate (org.javarosa.core.model.condition.Recalculate)1 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)1 DataInstance (org.javarosa.core.model.instance.DataInstance)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 DummyFormEntryPrompt (org.javarosa.core.model.test.DummyFormEntryPrompt)1 InvalidReferenceException (org.javarosa.core.reference.InvalidReferenceException)1 Reference (org.javarosa.core.reference.Reference)1 ResourceReferenceFactory (org.javarosa.core.reference.ResourceReferenceFactory)1