use of org.javarosa.core.services.locale.TableLocaleSource 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");
}
}
use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.
the class XFormParser method parseTranslation.
private void parseTranslation(Localizer l, Element trans) {
// ///for warning message
List<String> usedAtts = new ArrayList<>();
usedAtts.add("lang");
usedAtts.add("default");
// ///////////////////////
String lang = trans.getAttributeValue("", "lang");
if (lang == null || lang.length() == 0) {
throw new XFormParseException("no language specified for <translation>", trans);
}
String isDefault = trans.getAttributeValue("", "default");
if (!l.addAvailableLocale(lang)) {
throw new XFormParseException("duplicate <translation> for language '" + lang + "'", trans);
}
if (isDefault != null) {
if (l.getDefaultLocale() != null)
throw new XFormParseException("more than one <translation> set as default", trans);
l.setDefaultLocale(lang);
}
TableLocaleSource source = new TableLocaleSource();
Collection<Integer> removeIndexes = new HashSet<>();
for (int j = 0; j < trans.getChildCount(); j++) {
Element text = trans.getElement(j);
if (text == null || !text.getName().equals("text")) {
continue;
}
parseTextHandle(source, text);
// Clayton Sims - Jun 17, 2009 - This code is used when the stinginess flag
// is set for the build. It dynamically wipes out old model nodes once they're
// used. This is sketchy if anything else plans on touching the nodes.
// This code can be removed once we're pull-parsing
// #if org.javarosa.xform.stingy
removeIndexes.add(j);
}
ElementChildDeleter.delete(trans, removeIndexes);
// print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(trans, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(trans, usedAtts), getVagueLocation(trans));
}
l.registerLocaleResource(lang, source);
}
use of org.javarosa.core.services.locale.TableLocaleSource 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");
}
}
use of org.javarosa.core.services.locale.TableLocaleSource 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;
}
use of org.javarosa.core.services.locale.TableLocaleSource in project javarosa by opendatakit.
the class LocalizerTest method testSerialization.
public void testSerialization() {
Localizer l = new Localizer(true, true);
TableLocaleSource firstLocale = new TableLocaleSource();
TableLocaleSource secondLocale = new TableLocaleSource();
TableLocaleSource finalLocale = new TableLocaleSource();
testSerialize(l, "empty 1");
testSerialize(new Localizer(false, false), "empty 2");
testSerialize(new Localizer(true, false), "empty 3");
testSerialize(new Localizer(false, true), "empty 4");
l.addAvailableLocale("locale1");
testSerialize(l, "one empty locale");
l.addAvailableLocale("locale2");
testSerialize(l, "two empty locales");
l.setDefaultLocale("locale2");
testSerialize(l, "two empty locales + default");
l.setToDefault();
testSerialize(l, "two empty locales + default/current");
l.setLocale("locale1");
testSerialize(l, "two empty locales + default/current 2");
l.setDefaultLocale(null);
testSerialize(l, "two empty locales + current");
l.registerLocaleResource("locale1", firstLocale);
l.registerLocaleResource("locale2", secondLocale);
firstLocale.setLocaleMapping("id1", "text1");
testSerialize(l, "locales with data 1");
firstLocale.setLocaleMapping("id2", "text2");
testSerialize(l, "locales with data 2");
secondLocale.setLocaleMapping("id1", "text1");
secondLocale.setLocaleMapping("id2", "text2");
secondLocale.setLocaleMapping("id3", "text3");
testSerialize(l, "locales with data 3");
secondLocale.setLocaleMapping("id2", null);
testSerialize(l, "locales with data 4");
finalLocale.setLocaleMapping("id1", "text1");
finalLocale.setLocaleMapping("id4", "text4");
l.registerLocaleResource("locale3", finalLocale);
testSerialize(l, "locales with data 5");
l.destroyLocale("locale2");
testSerialize(l, "locales with data 6");
}
Aggregations