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");
}
}
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
}
}
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;
}
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();
}
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");
}
}
Aggregations