Search in sources :

Example 1 with Localizer

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

the class QuestionDefTest method testReferences.

@Test
public void testReferences() {
    QuestionDef q = fpi.getFirstQuestionDef();
    FormEntryPrompt fep = fpi.getFormEntryModel().getQuestionPrompt();
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    String audioURI = fep.getAudioText();
    String ref;
    ReferenceManager.instance().addReferenceFactory(new ResourceReferenceFactory());
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://audio/", "jr://resource/"));
    try {
        Reference r = ReferenceManager.instance().DeriveReference(audioURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/hah.mp3")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://images/", "jr://resource/"));
    q = fpi.getNextQuestion();
    fep = fpi.getFormEntryModel().getQuestionPrompt();
    String imURI = fep.getImageText();
    try {
        Reference r = ReferenceManager.instance().DeriveReference(imURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/four.gif")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
}
Also used : ResourceReferenceFactory(org.javarosa.core.reference.ResourceReferenceFactory) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Reference(org.javarosa.core.reference.Reference) IDataReference(org.javarosa.core.model.IDataReference) QuestionDef(org.javarosa.core.model.QuestionDef) Localizer(org.javarosa.core.services.locale.Localizer) RootTranslator(org.javarosa.core.reference.RootTranslator) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Test(org.junit.Test)

Example 2 with Localizer

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

the class TextFormTests method testNonLocalizedText.

public void testNonLocalizedText() {
    FormEntryController fec = fpi.getFormEntryController();
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    boolean testFlag = false;
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    do {
        if (fpi.getCurrentQuestion() == null)
            continue;
        QuestionDef q = fpi.getCurrentQuestion();
        fep = fpi.getFormEntryModel().getQuestionPrompt();
        String t = fep.getQuestionText();
        if (t == null)
            continue;
        if (t.equals("Non-Localized label inner text!"))
            testFlag = true;
    } while (fec.stepToNextEvent() != FormEntryController.EVENT_END_OF_FORM);
    if (!testFlag)
        fail("Failed to fallback to labelInnerText in testNonLocalizedText()");
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) Localizer(org.javarosa.core.services.locale.Localizer) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 3 with Localizer

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

the class LocalizerTest method testAddLocaleWithData.

public void testAddLocaleWithData() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    TableLocaleSource localeData = new TableLocaleSource();
    localeData.setLocaleMapping("textID", "text");
    if (l.hasLocale(TEST_LOCALE)) {
        fail("Localizer reports it contains non-existent locale");
    }
    l.addAvailableLocale(TEST_LOCALE);
    l.registerLocaleResource(TEST_LOCALE, localeData);
    if (!l.hasLocale(TEST_LOCALE)) {
        fail("Localizer reports it does not contain newly added locale");
    }
    if (!localeData.getLocalizedText().get("textID").equals(l.getRawText(TEST_LOCALE, "textID"))) {
        fail("Newly stored locale does not match source");
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 4 with Localizer

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

the class LocalizerTest method testGetLocaleMapNotExist.

public void testGetLocaleMapNotExist() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    try {
        l.getLocaleMap(TEST_LOCALE);
        fail("Did not throw exception when getting locale mapping for non-existent locale");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 5 with Localizer

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

the class LocalizerTest method testSetDefaultLocaleExists.

public void testSetDefaultLocaleExists() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    l.setDefaultLocale(TEST_LOCALE);
    if (!TEST_LOCALE.equals(l.getDefaultLocale())) {
        fail("Did not properly set default 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