Search in sources :

Example 11 with Localizer

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

the class LocalizerTest method testLocalizationObserverUpdateOnRegister.

public void testLocalizationObserverUpdateOnRegister() {
    Localizer l = new Localizer();
    l.addAvailableLocale("test1");
    l.setLocale("test1");
    LocalizationObserver lo = new LocalizationObserver();
    l.registerLocalizable(lo);
    if (!lo.flag || !"test1".equals(lo.locale) || l != lo.l) {
        fail("Localization observer did not update properly on registration");
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 12 with Localizer

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

the class LocalizerTest method testSetCurrentLocaleNotExists.

public void testSetCurrentLocaleNotExists() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    try {
        l.setLocale(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 13 with Localizer

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

the class XFormParser method parseIText.

private void parseIText(Element itext) {
    Localizer l = new Localizer(true, true);
    // used for warning message
    ArrayList<String> usedAtts = new ArrayList<>();
    for (int i = 0; i < itext.getChildCount(); i++) {
        Element trans = itext.getElement(i);
        if (trans == null || !trans.getName().equals("translation"))
            continue;
        parseTranslation(l, trans);
    }
    if (l.getAvailableLocales().length == 0)
        throw new XFormParseException("no <translation>s defined", itext);
    if (l.getDefaultLocale() == null)
        l.setDefaultLocale(l.getAvailableLocales()[0]);
    // print unused attribute warning message for parent element
    if (XFormUtils.showUnusedAttributeWarning(itext, usedAtts)) {
        reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
    }
    localizer = l;
}
Also used : TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement) Element(org.kxml2.kdom.Element) IFormElement(org.javarosa.core.model.IFormElement) ArrayList(java.util.ArrayList) Localizer(org.javarosa.core.services.locale.Localizer)

Example 14 with Localizer

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

the class FormDef method readExternal.

/**
 * Reads the form definition object from the supplied stream.
 * <p/>
 * Requires that the instance has been set to a prototype of the instance
 * that should be used for deserialization.
 *
 * @param dis - the stream to read from.
 * @throws IOException
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
@Override
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException {
    setID(ExtUtil.readInt(dis));
    setName(ExtUtil.nullIfEmpty(ExtUtil.readString(dis)));
    setTitle((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
    setChildren((List<IFormElement>) ExtUtil.read(dis, new ExtWrapListPoly(), pf));
    setInstance((FormInstance) ExtUtil.read(dis, FormInstance.class, pf));
    setLocalizer((Localizer) ExtUtil.read(dis, new ExtWrapNullable(Localizer.class), pf));
    List<Condition> vcond = (List<Condition>) ExtUtil.read(dis, new ExtWrapList(Condition.class), pf);
    for (Condition condition : vcond) {
        addTriggerable(condition);
    }
    List<Recalculate> vcalc = (List<Recalculate>) ExtUtil.read(dis, new ExtWrapList(Recalculate.class), pf);
    for (Recalculate recalculate : vcalc) {
        addTriggerable(recalculate);
    }
    finalizeTriggerables();
    outputFragments = (List<IConditionExpr>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
    submissionProfiles = (HashMap<String, SubmissionProfile>) ExtUtil.read(dis, new ExtWrapMap(String.class, SubmissionProfile.class));
    formInstances = (HashMap<String, DataInstance>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapTagged()), pf);
    eventListeners = (HashMap<String, List<Action>>) ExtUtil.read(dis, new ExtWrapMap(String.class, new ExtWrapListPoly()), pf);
    extensions = (List<XFormExtension>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
    resetEvaluationContext();
}
Also used : Condition(org.javarosa.core.model.condition.Condition) IConditionExpr(org.javarosa.core.model.condition.IConditionExpr) DataInstance(org.javarosa.core.model.instance.DataInstance) Recalculate(org.javarosa.core.model.condition.Recalculate) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) Localizer(org.javarosa.core.services.locale.Localizer) ExtWrapListPoly(org.javarosa.core.util.externalizable.ExtWrapListPoly) List(java.util.List) ArrayList(java.util.ArrayList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 15 with Localizer

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

the class LocalizerTest method testTextMapping.

public void testTextMapping() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    if (l.hasMapping(TEST_LOCALE, "textID")) {
        fail("Localizer contains text mapping that was not defined");
    }
    TableLocaleSource table = new TableLocaleSource();
    table.setLocaleMapping("textID", "text");
    l.registerLocaleResource(TEST_LOCALE, table);
    if (!l.hasMapping(TEST_LOCALE, "textID")) {
        fail("Localizer does not contain newly added text mapping");
    }
    if (!"text".equals(l.getLocaleData(TEST_LOCALE).get("textID"))) {
        fail("Newly added 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