Search in sources :

Example 16 with Localizer

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

the class LocalizerTest method testSetDefaultLocaleNotExists.

public void testSetDefaultLocaleNotExists() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    try {
        l.setDefaultLocale(TEST_LOCALE);
        fail("Set current locale to a non-existent locale");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 17 with Localizer

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

the class LocalizerTest method testDestroyLocale.

public void testDestroyLocale() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    boolean result = l.destroyLocale(TEST_LOCALE);
    if (!result || l.hasLocale(TEST_LOCALE)) {
        fail("Locale not destroyed");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 18 with Localizer

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

the class LocalizerTest method testGetNextLocale.

public void testGetNextLocale() {
    Localizer l = new Localizer();
    l.addAvailableLocale("test1");
    l.addAvailableLocale("test2");
    l.addAvailableLocale("test3");
    if (l.getNextLocale() != null) {
        fail("Unexpected next locale");
    }
    l.setDefaultLocale("test3");
    if (!"test3".equals(l.getNextLocale())) {
        fail("Unexpected next locale");
    }
    l.setDefaultLocale(null);
    l.setLocale("test1");
    if (!"test2".equals(l.getNextLocale())) {
        fail("Unexpected next locale");
    }
    l.setLocale("test2");
    if (!"test3".equals(l.getNextLocale())) {
        fail("Unexpected next locale");
    }
    l.setLocale("test3");
    if (!"test1".equals(l.getNextLocale())) {
        fail("Unexpected next locale");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 19 with Localizer

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

the class LocalizerTest method buildLocalizer.

private Localizer buildLocalizer(int i, int j, int k, String ourLocale, String otherLocale) {
    Localizer l = new Localizer(i / 2 == 0, i % 2 == 0);
    TableLocaleSource firstLocale = new TableLocaleSource();
    TableLocaleSource secondLocale = new TableLocaleSource();
    if (j / 2 == 0 || "default".equals(ourLocale))
        firstLocale.setLocaleMapping("textID", "text:" + ourLocale + ":base");
    if (j % 2 == 0 || "default".equals(ourLocale))
        firstLocale.setLocaleMapping("textID;form", "text:" + ourLocale + ":form");
    if (otherLocale != null) {
        if (k / 2 == 0 || "default".equals(otherLocale))
            secondLocale.setLocaleMapping("textID", "text:" + otherLocale + ":base");
        if (k % 2 == 0 || "default".equals(otherLocale))
            secondLocale.setLocaleMapping("textID;form", "text:" + otherLocale + ":form");
    }
    l.addAvailableLocale(ourLocale);
    l.registerLocaleResource(ourLocale, firstLocale);
    if (otherLocale != null) {
        l.addAvailableLocale(otherLocale);
        l.registerLocaleResource(otherLocale, secondLocale);
    }
    if (l.hasLocale("default")) {
        l.setDefaultLocale("default");
    }
    l.setLocale(ourLocale);
    return l;
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 20 with Localizer

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

the class LocalizerTest method testSetToDefault.

public void testSetToDefault() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    l.setDefaultLocale(TEST_LOCALE);
    l.setToDefault();
    if (!TEST_LOCALE.equals(l.getLocale())) {
        fail("Could not set current locale to default");
    }
}
Also used : 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