use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class IndicatorServiceTest method testNumeratorTranslation.
@Test
void testNumeratorTranslation() {
Locale locale = Locale.FRENCH;
UserContext.setUser(user);
UserContext.setUserSetting(UserSettingKey.DB_LOCALE, locale);
IndicatorType type = new IndicatorType("IndicatorType", 100, false);
indicatorService.addIndicatorType(type);
Indicator indicatorA = createIndicator('A', type);
indicatorA.setNumeratorDescription("Numerator description");
indicatorA.setDenominatorDescription("Denominator description");
long idA = indicatorService.addIndicator(indicatorA);
indicatorA = indicatorService.getIndicator(idA);
String numeratorTranslated = "Numerator description translated";
String denominatorTranslated = "Denominator description translated";
Set<Translation> listObjectTranslation = new HashSet<>(indicatorA.getTranslations());
listObjectTranslation.add(new Translation(locale.getLanguage(), "NUMERATOR_DESCRIPTION", numeratorTranslated));
listObjectTranslation.add(new Translation(locale.getLanguage(), "DENOMINATOR_DESCRIPTION", denominatorTranslated));
identifiableObjectManager.updateTranslations(indicatorA, listObjectTranslation);
assertEquals(numeratorTranslated, indicatorA.getDisplayNumeratorDescription());
assertEquals(denominatorTranslated, indicatorA.getDisplayDenominatorDescription());
}
use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class ValidationServiceTest method testInstructionTranslation.
@Test
void testInstructionTranslation() {
User user = createUserAndInjectSecurityContext(true);
Locale locale = Locale.FRENCH;
UserContext.setUser(user);
UserContext.setUserSetting(UserSettingKey.DB_LOCALE, locale);
useDataValue(dataElementA, periodA, sourceA, "10");
useDataValue(dataElementB, periodA, sourceA, "20");
Expression expressionLeft = new Expression("greatest( #{" + dataElementA.getUid() + "}, #{" + dataElementB.getUid() + "} )", "exprLeft");
Expression expressionRight = new Expression("least( #{" + dataElementA.getUid() + "}, #{" + dataElementB.getUid() + "} )", "exprRight");
ValidationRule rule = createValidationRule("R", equal_to, expressionLeft, expressionRight, ptMonthly);
rule.setInstruction("Validation rule instruction");
validationRuleService.saveValidationRule(rule);
String instructionTranslated = "Validation rule instruction translated";
Set<Translation> listObjectTranslation = new HashSet<>(rule.getTranslations());
listObjectTranslation.add(new Translation(locale.getLanguage(), "INSTRUCTION", instructionTranslated));
identifiableObjectManager.updateTranslations(rule, listObjectTranslation);
Assertions.assertEquals(instructionTranslated, rule.getDisplayInstruction());
}
use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class JsonBinaryTypeTest method setUp.
@BeforeEach
void setUp() {
translation1 = new Translation();
translation1.setLocale("en");
translation1.setValue("English Test 1");
jsonBinaryType = new JsonBinaryType();
jsonBinaryType.init(Translation.class);
}
use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class JsonSetBinaryTypeTest method setUp.
@BeforeEach
void setUp() {
translation1 = new Translation();
translation1.setLocale("en");
translation1.setValue("English Test 1");
translation2 = new Translation();
translation2.setLocale("no");
translation2.setValue("Norwegian Test 1");
translations = new HashSet<>();
translations.add(translation1);
translations.add(translation2);
jsonBinaryType = new JsonSetBinaryType();
jsonBinaryType.init(Translation.class);
}
use of org.hisp.dhis.translation.Translation in project dhis2-core by dhis2.
the class TranslateAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
className = className != null && CLASS_ALIAS.containsKey(className) ? CLASS_ALIAS.get(className) : className;
log.info("Classname: " + className + ", uid: " + uid + ", loc: " + loc);
IdentifiableObject object = identifiableObjectManager.getObject(uid, className);
HttpServletRequest request = ServletActionContext.getRequest();
Set<Translation> listObjectTranslation = new HashSet<>(object.getTranslations());
for (Translation p : listObjectTranslation) {
Enumeration<String> paramNames = request.getParameterNames();
Collections.list(paramNames).forEach(paramName -> {
if (paramName.equalsIgnoreCase(p.getProperty().toString())) {
String[] paramValues = request.getParameterValues(paramName);
if (!ArrayUtils.isEmpty(paramValues) && StringUtils.isNotEmpty(paramValues[0])) {
listObjectTranslation.removeIf(o -> o.getProperty().equals(p) && o.getLocale().equalsIgnoreCase(loc));
listObjectTranslation.add(new Translation(loc, p.getProperty(), paramValues[0]));
}
}
});
}
identifiableObjectManager.updateTranslations(object, listObjectTranslation);
return SUCCESS;
}
Aggregations