diff --git a/src/main/java/org/olat/core/util/i18n/ui/SingleKeyTranslatorController.java b/src/main/java/org/olat/core/util/i18n/ui/SingleKeyTranslatorController.java index 6fc7e7a408e56a13ecedb924978e72d7167d3324..ddee744d569728282dbf0db4eb8e718048e81b4f 100644 --- a/src/main/java/org/olat/core/util/i18n/ui/SingleKeyTranslatorController.java +++ b/src/main/java/org/olat/core/util/i18n/ui/SingleKeyTranslatorController.java @@ -62,14 +62,34 @@ public class SingleKeyTranslatorController extends FormBasicController { private static final String LBL_NAME_PREFIX = "lbl."; private Map<String, TextElement> textElements; private Object uobject; + private boolean textArea; @Autowired private I18nManager i18nMng; @Autowired private I18nModule i18nModule; + /** + * + * @param ureq The user request + * @param wControl The window control + * @param keyToTranslate The key to translate + * @param translatorBaseClass The package to translate + */ public SingleKeyTranslatorController(UserRequest ureq, WindowControl wControl, String keyToTranslate, Class<?> translatorBaseClass) { - this(ureq,wControl,new String[]{keyToTranslate},translatorBaseClass); + this(ureq, wControl, new String[]{keyToTranslate}, translatorBaseClass, false); + } + + /** + * + * @param ureq The user request + * @param wControl The window control + * @param keyToTranslate The key to translate + * @param translatorBaseClass The package to translate + * @param textArea true if the edit field is a text area, false for a simple text field + */ + public SingleKeyTranslatorController(UserRequest ureq, WindowControl wControl, String keyToTranslate, Class<?> translatorBaseClass, boolean textArea) { + this(ureq, wControl, new String[]{keyToTranslate}, translatorBaseClass, textArea); } /** @@ -84,14 +104,17 @@ public class SingleKeyTranslatorController extends FormBasicController { /** * - * @param ureq - * @param wControl + * @param ureq The user request + * @param wControl The window control * @param keysToTranslate array of keys to translate (each key will have the * same value, translation is only done once (for each language) !) - * @param translatorBaseClass + * @param translatorBaseClass The package to translate + * @param textArea true if the edit field is a text area, false for a simple text field */ - public SingleKeyTranslatorController(UserRequest ureq, WindowControl wControl, String[] keysToTranslate, Class<?> translatorBaseClass) { + public SingleKeyTranslatorController(UserRequest ureq, WindowControl wControl, String[] keysToTranslate, + Class<?> translatorBaseClass, boolean textArea) { super(ureq, wControl, FormBasicController.LAYOUT_VERTICAL); + this.textArea = textArea; i18nItemKeys = keysToTranslate; this.translatorBaseClass = translatorBaseClass; initForm(ureq); @@ -119,18 +142,24 @@ public class SingleKeyTranslatorController extends FormBasicController { // build the form textElements = new HashMap<>(); for (I18nRowBundle i18nRowBundle : bundles) { - uifactory.addStaticTextElement(LBL_NAME_PREFIX + i18nRowBundle.getLanguageKey(), null, i18nRowBundle.getKeyTranslator().getLocale() - .getDisplayLanguage(getLocale()), formLayout); + String labelId = LBL_NAME_PREFIX + i18nRowBundle.getLanguageKey(); + String label = i18nRowBundle.getKeyTranslator().getLocale().getDisplayLanguage(getLocale()); + uifactory.addStaticTextElement(labelId, null, label, formLayout); String value = ""; if (i18nRowBundle.hasTranslationForValue(i18nItemKeys[0])) { value = i18nRowBundle.getKeyTranslator().translate(i18nItemKeys[0]); } - TextElement te = uifactory.addTextElement(TXT_NAME_PREFIX + i18nRowBundle.getLanguageKey(), null, 255, value, formLayout); + String textId = TXT_NAME_PREFIX + i18nRowBundle.getLanguageKey(); + TextElement te; + if(textArea) { + te = uifactory.addTextAreaElement(textId, null, -1, 8, 60, false, false, value, formLayout); + } else { + te = uifactory.addTextElement(textId, null, null, 255, value, formLayout); + te.setDisplaySize(60); + } te.setMandatory(true); - te.setDisplaySize(60); textElements.put(i18nRowBundle.getLanguageKey(), te); - } FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("ok_cancel", getTranslator()); @@ -190,11 +219,11 @@ public class SingleKeyTranslatorController extends FormBasicController { * * @author strentini */ - class I18nRowBundle { - private Locale overlayLocale; - private Locale locale; - private String languageKey; - private Translator keyTranslator; + private class I18nRowBundle { + private final Locale overlayLocale; + private final Locale locale; + private final String languageKey; + private final Translator keyTranslator; /** * @@ -217,10 +246,6 @@ public class SingleKeyTranslatorController extends FormBasicController { return overlayLocale; } - public Locale getLocale() { - return locale; - } - public String getLanguageKey() { return languageKey; } @@ -228,7 +253,5 @@ public class SingleKeyTranslatorController extends FormBasicController { public Translator getKeyTranslator() { return keyTranslator; } - } - } diff --git a/src/main/java/org/olat/modules/grading/ui/GradingAdminTemplatesController.java b/src/main/java/org/olat/modules/grading/ui/GradingAdminTemplatesController.java index 2e099272351750dab0eabba318e93d6b6f1b6c74..d4f95b8f9529c36eadd9bcb90fbdf256b7312312 100644 --- a/src/main/java/org/olat/modules/grading/ui/GradingAdminTemplatesController.java +++ b/src/main/java/org/olat/modules/grading/ui/GradingAdminTemplatesController.java @@ -31,6 +31,7 @@ import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController; +import org.olat.core.util.Formatter; import org.olat.core.util.i18n.ui.SingleKeyTranslatorController; /** @@ -55,30 +56,34 @@ public class GradingAdminTemplatesController extends FormBasicController { @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { // new grader - initForm("mail.to.grader.subject", "mail.grader.to.entry.subject", formLayout); - initForm("mail.to.grader.body", "mail.grader.to.entry.body", formLayout); + initForm("mail.to.grader.subject", "mail.grader.to.entry.subject", false, formLayout); + initForm("mail.to.grader.body", "mail.grader.to.entry.body", true, formLayout); uifactory.addSpacerElement("spacer-new-grader", formLayout, false); // notifications - initForm("notification.subject", "mail.notification.subject", formLayout); - initForm("notification.body", "mail.notification.body", formLayout); + initForm("notification.subject", "mail.notification.subject", false, formLayout); + initForm("notification.body", "mail.notification.body", true, formLayout); uifactory.addSpacerElement("spacer-notification", formLayout, false); // reminder 1 - initForm("reminder.1.subject", "mail.reminder1.subject", formLayout); - initForm("reminder.1.body", "mail.reminder1.body", formLayout); + initForm("reminder.1.subject", "mail.reminder1.subject", false, formLayout); + initForm("reminder.1.body", "mail.reminder1.body", true, formLayout); uifactory.addSpacerElement("spacer-1-reminder", formLayout, false); // reminder 2 - initForm("reminder.2.subject", "mail.reminder2.subject", formLayout); - initForm("reminder.2.body", "mail.reminder2.body", formLayout); + initForm("reminder.2.subject", "mail.reminder2.subject", false, formLayout); + initForm("reminder.2.body", "mail.reminder2.body", true, formLayout); } - private void initForm(String labelI18nKey, String textI18nKey, FormItemContainer formLayout) { + private void initForm(String labelI18nKey, String textI18nKey, boolean multiLines, FormItemContainer formLayout) { String text = translate(textI18nKey); + if(multiLines) { + text = Formatter.escWithBR(text).toString(); + } + StaticTextElement viewEl = uifactory.addStaticTextElement("view." + counter++, labelI18nKey, text, formLayout); FormLink translationLink = uifactory.addFormLink("translate." + counter++, "translate", null, formLayout, Link.LINK); - translationLink.setUserObject(new TranslationBundle(textI18nKey, labelI18nKey, viewEl)); + translationLink.setUserObject(new TranslationBundle(textI18nKey, labelI18nKey, multiLines, viewEl)); } @Override @@ -124,7 +129,7 @@ public class GradingAdminTemplatesController extends FormBasicController { if(guardModalController(translatorCtrl)) return; translatorCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), bundle.getI18nKey(), - GradingAdminTemplatesController.class); + GradingAdminTemplatesController.class, bundle.isMultiLines()); translatorCtrl.setUserObject(bundle); listenTo(translatorCtrl); @@ -135,18 +140,24 @@ public class GradingAdminTemplatesController extends FormBasicController { } private void doUpdate(TranslationBundle bundle) { - bundle.getViewEl().setValue(translate(bundle.getI18nKey())); + String text = translate(bundle.getI18nKey()); + if(bundle.isMultiLines()) { + text = Formatter.escWithBR(text).toString(); + } + bundle.getViewEl().setValue(text); } private static class TranslationBundle { private final String i18nKey; + private final boolean multiLines; private final String labelI18nKey; private final StaticTextElement viewEl; - public TranslationBundle(String i18nKey, String labelI18nKey, StaticTextElement viewEl) { + public TranslationBundle(String i18nKey, String labelI18nKey, boolean multiLines, StaticTextElement viewEl) { this.i18nKey = i18nKey; this.viewEl = viewEl; + this.multiLines = multiLines; this.labelI18nKey = labelI18nKey; } @@ -161,5 +172,9 @@ public class GradingAdminTemplatesController extends FormBasicController { public String getLabelI18nKey() { return labelI18nKey; } + + public boolean isMultiLines() { + return multiLines; + } } } diff --git a/src/main/java/org/olat/user/propertyhandlers/ui/UsrPropCfgTableController.java b/src/main/java/org/olat/user/propertyhandlers/ui/UsrPropCfgTableController.java index a64e4f74bd3877c82a8962678b60811473130dd6..6471ddda91b8dd7e62c12a5d167576176097c46a 100644 --- a/src/main/java/org/olat/user/propertyhandlers/ui/UsrPropCfgTableController.java +++ b/src/main/java/org/olat/user/propertyhandlers/ui/UsrPropCfgTableController.java @@ -216,7 +216,7 @@ public class UsrPropCfgTableController extends FormBasicController { String key2Translate2 = handler.i18nColumnDescriptorLabelKey(); String[] keys2Translate = { key2Translate1, key2Translate2 }; - singleKeyTrnsCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), keys2Translate, UserPropertyHandler.class); + singleKeyTrnsCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), keys2Translate, UserPropertyHandler.class, false); listenTo(singleKeyTrnsCtrl); removeAsListenerAndDispose(translatorCallout); translatorCallout = new CloseableCalloutWindowController(ureq, getWindowControl(), singleKeyTrnsCtrl.getInitialComponent(),