Search in sources :

Example 1 with Translation

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());
}
Also used : Locale(java.util.Locale) Translation(org.hisp.dhis.translation.Translation) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with Translation

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());
}
Also used : Locale(java.util.Locale) Translation(org.hisp.dhis.translation.Translation) User(org.hisp.dhis.user.User) Expression(org.hisp.dhis.expression.Expression) HashSet(java.util.HashSet) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 3 with Translation

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);
}
Also used : Translation(org.hisp.dhis.translation.Translation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Translation

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);
}
Also used : Translation(org.hisp.dhis.translation.Translation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Translation

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Translation(org.hisp.dhis.translation.Translation) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) HashSet(java.util.HashSet)

Aggregations

Translation (org.hisp.dhis.translation.Translation)11 HashSet (java.util.HashSet)5 Test (org.junit.jupiter.api.Test)4 Locale (java.util.Locale)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DhisTest (org.hisp.dhis.DhisTest)1 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)1 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)1 Expression (org.hisp.dhis.expression.Expression)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 ObjectReport (org.hisp.dhis.feedback.ObjectReport)1