Search in sources :

Example 26 with Localizer

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

the class LocalizerTest method testLocalizationObservers.

public void testLocalizationObservers() {
    Localizer l = new Localizer();
    l.addAvailableLocale("test1");
    l.addAvailableLocale("test2");
    LocalizationObserver lo = new LocalizationObserver();
    l.registerLocalizable(lo);
    if (lo.flag || lo.locale != null || lo.l != null) {
        fail("Improper state in localization observer");
    }
    l.setLocale("test1");
    if (!lo.flag || !"test1".equals(lo.locale) || l != lo.l) {
        fail("Improper state in localization observer, or not updated properly");
    }
    lo.flag = false;
    l.setLocale("test2");
    if (!lo.flag || !"test2".equals(lo.locale) || l != lo.l) {
        fail("Improper state in localization observer, or not updated properly");
    }
    lo.flag = false;
    l.setLocale("test2");
    if (lo.flag || !"test2".equals(lo.locale) || l != lo.l) {
        fail("Localization observer improperly updated");
    }
    l.unregisterLocalizable(lo);
    l.setLocale("test1");
    if (lo.flag || !"test2".equals(lo.locale) || l != lo.l) {
        fail("Localization observer updated after unregistered");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 27 with Localizer

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

the class LocalizerTest method testUnsetDefaultLocale.

public void testUnsetDefaultLocale() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    l.setDefaultLocale(TEST_LOCALE);
    try {
        l.setDefaultLocale(null);
        if (l.getDefaultLocale() != null) {
            fail("Could not unset default locale");
        }
    } catch (UnregisteredLocaleException nsee) {
        fail("Exception unsetting default locale");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 28 with Localizer

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

the class LocalizerTest method testDestroyLocaleNotExist.

public void testDestroyLocaleNotExist() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    boolean result = l.destroyLocale(TEST_LOCALE);
    if (result) {
        fail("Destroyed non-existent locale");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 29 with Localizer

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

the class LocalizerTest method testGetText.

public void testGetText(int i, int j, int k, String ourLocale, String otherLocale, String textID, int localeCase, int formCase) {
    // System.out.println("testing getText: "+localeCase+","+formCase+","+i+","+j+","+k);
    Localizer l = buildLocalizer(i, j, k, ourLocale, otherLocale);
    String expected = expectedText(textID, l);
    String text, text2;
    text = l.getText(textID, ourLocale);
    if (expected == null ? text != null : !expected.equals(text)) {
        fail("Did not retrieve expected text from localizer [" + localeCase + "," + formCase + "," + i + "," + j + "," + k + "]");
    }
    try {
        text2 = l.getLocalizedText(textID);
        if (expected == null) {
            fail("Should have gotten exception");
        } else if (!expected.equals(text2)) {
            fail("Did not retrieve expected text");
        }
    } catch (NoLocalizedTextException nsee) {
        if (expected != null) {
            fail("Got unexpected exception");
        }
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer) NoLocalizedTextException(org.javarosa.core.util.NoLocalizedTextException)

Example 30 with Localizer

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

the class LocalizerTest method testDestroyDefaultLocale.

public void testDestroyDefaultLocale() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    l.setDefaultLocale(TEST_LOCALE);
    l.destroyLocale(TEST_LOCALE);
    if (l.getDefaultLocale() != null) {
        fail("Default locale still set to destroyed locale");
    }
}
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