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