Search in sources :

Example 1 with I18nItem

use of org.olat.core.util.i18n.I18nItem in project OpenOLAT by OpenOLAT.

the class InlineTranslationInterceptHandlerController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == delegatingComponent) {
        String bundle = ureq.getParameter(ARG_BUNDLE);
        String key = ureq.getParameter(ARG_KEY);
        // The argument ARG_IDENT is not used for dispatching right now
        if (isLogDebugEnabled()) {
            logDebug("Got event to launch inline translation tool for bundle::" + bundle + " and key::" + key, null);
        }
        if (StringHelper.containsNonWhitespace(bundle) && StringHelper.containsNonWhitespace(key)) {
            // Get userconfigured reference locale
            Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
            List<String> referenceLangs = i18nModule.getTransToolReferenceLanguages();
            String referencePrefs = (String) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_REFERENCE_LANG, referenceLangs.get(0));
            Locale referenceLocale = i18nMgr.getLocaleOrNull(referencePrefs);
            // Set target local to current user language
            Locale targetLocale = i18nMgr.getLocaleOrNull(ureq.getLocale().toString());
            if (i18nModule.isOverlayEnabled() && !i18nModule.isTransToolEnabled()) {
                // use overlay locale when in customizing mode
                targetLocale = i18nModule.getOverlayLocales().get(targetLocale);
            }
            List<I18nItem> i18nItems = i18nMgr.findExistingAndMissingI18nItems(referenceLocale, targetLocale, bundle, false);
            if (i18nItems.isEmpty()) {
                logError("Can not launch inline translation tool, bundle or key empty! bundle::" + bundle + " key::" + key, null);
            } else {
                // sort with priority
                i18nMgr.sortI18nItems(i18nItems, true, true);
                // Initialize inline translation controller
                if (i18nItemEditCtr != null)
                    removeAsListenerAndDispose(i18nItemEditCtr);
                // Disable inline translation markup while inline translation tool is
                // running -
                // must be done before instantiating the translation controller
                i18nMgr.setMarkLocalizedStringsEnabled(ureq.getUserSession(), false);
                i18nItemEditCtr = new TranslationToolI18nItemEditCrumbController(ureq, getWindowControl(), i18nItems, referenceLocale, !i18nModule.isTransToolEnabled());
                listenTo(i18nItemEditCtr);
                // set current key from the package as current translation item
                for (I18nItem item : i18nItems) {
                    if (item.getKey().equals(key)) {
                        i18nItemEditCtr.initialzeI18nitemAsCurrentItem(ureq, item);
                        break;
                    }
                }
                // Open in modal window
                if (cmc != null)
                    removeAsListenerAndDispose(cmc);
                cmc = new CloseableModalController(getWindowControl(), "close", i18nItemEditCtr.getInitialComponent());
                listenTo(cmc);
                cmc.activate();
            }
        } else {
            logError("Can not launch inline translation tool, bundle or key empty! bundle::" + bundle + " key::" + key, null);
        }
    }
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) Locale(java.util.Locale) I18nItem(org.olat.core.util.i18n.I18nItem) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) Preferences(org.olat.core.util.prefs.Preferences)

Example 2 with I18nItem

use of org.olat.core.util.i18n.I18nItem in project OpenOLAT by OpenOLAT.

the class TranslationToolI18nItemEditCrumbController method initForm.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm
	 * (org.olat.core.gui.components.form.flexible.FormItemContainer,
	 * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
	 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    flc.contextPut("referenceLanguageKey", referenceLocale.toString());
    flc.contextPut("referenceLanguage", i18nMgr.getLanguageTranslated(referenceLocale.toString(), false));
    // Add bundles and keys selection
    List<String> bundlesList = new ArrayList<String>();
    List<String> keysList = new ArrayList<String>();
    for (I18nItem item : i18nItems) {
        if (!bundlesList.contains(item.getBundleName())) {
            bundlesList.add(item.getBundleName());
        }
        if (currentItem.getBundleName().equals(item.getBundleName())) {
            keysList.add(item.getKey());
        }
    }
    String[] bundlesListArray = ArrayHelper.toArray(bundlesList);
    String[] keysListArray = ArrayHelper.toArray(keysList);
    bundlesSelection = uifactory.addDropdownSingleselect("bundlesSelection", this.flc, bundlesListArray, bundlesListArray, null);
    bundlesSelection.setDomReplacementWrapperRequired(false);
    bundlesSelection.addActionListener(FormEvent.ONCHANGE);
    bundlesSelection.select(currentItem.getBundleName(), true);
    keysSelection = uifactory.addDropdownSingleselect("keysSelection", this.flc, keysListArray, keysListArray, null);
    keysSelection.setDomReplacementWrapperRequired(false);
    keysSelection.addActionListener(FormEvent.ONCHANGE);
    keysSelection.select(currentItem.getKey(), true);
    // Add reference box
    referenceArea = uifactory.addTextAreaElement("referenceArea", "edit.referenceArea", -1, 1, -1, true, null, this.flc);
    // read only
    referenceArea.setEnabled(false);
    // Add compare box
    Boolean compareEnabledPrefs = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.FALSE);
    compareArea = uifactory.addTextAreaElement("compareArea", "edit.compareArea", -1, 1, -1, true, null, this.flc);
    // read only
    compareArea.setEnabled(false);
    compareArea.setVisible(compareEnabledPrefs.booleanValue());
    String[] compareSwitchValues = new String[] { translate("generic.enable") };
    compareSwitch = uifactory.addCheckboxesVertical("compareSwitch", null, flc, KEYS_ENABLED, compareSwitchValues, 1);
    compareSwitch.setDomReplacementWrapperRequired(false);
    compareSwitch.select(KEYS_ENABLED[0], compareEnabledPrefs.booleanValue());
    compareSwitch.addActionListener(FormEvent.ONCLICK);
    formLayout.add(compareSwitch);
    flc.contextPut("compareSwitchEnabled", compareEnabledPrefs);
    // Add compare language selection
    Set<String> availableLangKeys = i18nModule.getAvailableLanguageKeys();
    String[] comparelangKeys = ArrayHelper.toArray(availableLangKeys);
    String[] compareLangValues = new String[comparelangKeys.length];
    for (int i = 0; i < comparelangKeys.length; i++) {
        String key = comparelangKeys[i];
        String explLang = i18nMgr.getLanguageInEnglish(key, customizingMode);
        String all = explLang;
        if (explLang != null && !explLang.equals(key))
            all += " (" + key + ")";
        compareLangValues[i] = all;
    }
    ArrayHelper.sort(comparelangKeys, compareLangValues, false, true, false);
    // Build css classes for comparison languages
    String comparePrefs = (String) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_COMPARE_LANG, I18nModule.getDefaultLocale().toString());
    compareLocale = i18nMgr.getLocaleOrNull(comparePrefs);
    if (compareLocale == null)
        compareLocale = I18nModule.getDefaultLocale();
    compareLangSelection = uifactory.addDropdownSingleselect("compareLangSelection", flc, comparelangKeys, compareLangValues, null);
    compareLangSelection.setDomReplacementWrapperRequired(false);
    compareLangSelection.select(i18nModule.getLocaleKey(compareLocale), true);
    flc.contextPut("compareLanguageKey", i18nModule.getLocaleKey(compareLocale));
    compareLangSelection.addActionListener(FormEvent.ONCHANGE);
    compareLangSelection.setEnabled(compareEnabledPrefs.booleanValue());
    // Add target box
    flc.contextPut("targetLanguageKey", i18nModule.getLocaleKey(currentItem.getLocale()));
    flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nModule.getLocaleKey(currentItem.getLocale()), false));
    targetArea = uifactory.addTextAreaElement("targetArea", "edit.targetArea", -1, 5, -1, true, null, flc);
    // Add annotation box
    annotationArea = uifactory.addTextAreaElement("annotationArea", "edit.annotationArea", -1, 1, -1, true, null, flc);
    // Add progress bar
    // init with values
    progressBarBundle = new ProgressBar("progressBarBundle", 300, 1, bundlesList.size(), translate("generic.bundles"));
    progressBarBundle.setPercentagesEnabled(false);
    flc.put("progressBarBundle", progressBarBundle);
    progressBarKey = new ProgressBar("progressBarKey", 300, 1, keysList.size(), translate("generic.keys"));
    progressBarKey.setPercentagesEnabled(false);
    flc.put("progressBarKey", progressBarKey);
    // Add navigation buttons
    previousLink = uifactory.addFormLink("previousLink", "edit.button.previous", null, formLayout, Link.BUTTON);
    previousLink.setIconLeftCSS("o_icon o_icon_previous_page");
    saveLink = uifactory.addFormLink("saveLink", "edit.button.save", null, formLayout, Link.BUTTON);
    saveNextLink = uifactory.addFormLink("saveNextLink", "edit.button.saveNext", null, formLayout, Link.BUTTON);
    formLayout.add(saveNextLink);
    nextLink = uifactory.addFormLink("nextLink", "edit.button.next", null, formLayout, Link.BUTTON);
    nextLink.setIconRightCSS("o_icon o_icon_next_page");
    formLayout.add(nextLink);
    // init values from item
    initOrUpdateCurrentItem(ureq);
    // Override text labels for customizing mode
    if (customizingMode) {
        // don't edit annotations in customizing mode
        annotationArea.setEnabled(false);
        // target lang flags and lang name
        Locale origLocale = i18nModule.getAllLocales().get(i18nMgr.createOrigianlLocaleKeyForOverlay(currentItem.getLocale()));
        if (origLocale == null) {
            origLocale = currentItem.getLocale();
        }
        String localeKey = i18nModule.getLocaleKey(origLocale);
        flc.contextPut("targetLanguageKey", localeKey);
        flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(localeKey, true));
    }
    flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
    flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) Locale(java.util.Locale) I18nItem(org.olat.core.util.i18n.I18nItem) ArrayList(java.util.ArrayList) Preferences(org.olat.core.util.prefs.Preferences) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar)

Example 3 with I18nItem

use of org.olat.core.util.i18n.I18nItem in project OpenOLAT by OpenOLAT.

the class TranslationToolI18nItemEditCrumbController method updateKeysSelectionAndProgress.

private void updateKeysSelectionAndProgress() {
    List<String> keysList = new ArrayList<String>();
    for (I18nItem item : i18nItems) {
        if (currentItem.getBundleName().equals(item.getBundleName())) {
            keysList.add(item.getKey());
        }
    }
    String[] keysListArray = ArrayHelper.toArray(keysList);
    keysSelection.setKeysAndValues(keysListArray, keysListArray, null);
    keysSelection.select(currentItem.getKey(), true);
    // Update key progress bar
    progressBarKey.setMax(keysListArray.length);
    progressBarKey.setActual(keysSelection.getSelected() + 1);
    // Set currentItemPosition bundle
    bundlesSelection.select(currentItem.getBundleName(), true);
    // Update bundle progress bar
    progressBarBundle.setActual(bundlesSelection.getSelected() + 1);
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem) ArrayList(java.util.ArrayList)

Example 4 with I18nItem

use of org.olat.core.util.i18n.I18nItem in project OpenOLAT by OpenOLAT.

the class TranslationToolI18nItemEditCrumbController method formInnerEvent.

/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.olat.core.gui.components.form.flexible.impl.FormBasicController#
	 * formInnerEvent(org.olat.core.gui.UserRequest,
	 * org.olat.core.gui.components.form.flexible.FormItem,
	 * org.olat.core.gui.components.form.flexible.impl.FormEvent)
	 */
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == bundlesSelection) {
        for (int i = 0; i < i18nItems.size(); i++) {
            I18nItem item = i18nItems.get(i);
            if (item.getBundleName().equals(bundlesSelection.getSelectedKey())) {
                currentItemPosition = i;
                currentItem = item;
                break;
            }
        }
        // in new bundle, load new keys to prevent problem in update method
        updateKeysSelectionAndProgress();
        // update everything
        initOrUpdateCurrentItem(ureq);
    } else if (source == keysSelection) {
        for (int i = 0; i < i18nItems.size(); i++) {
            I18nItem item = i18nItems.get(i);
            if (item.getBundleName().equals(bundlesSelection.getSelectedKey()) && item.getKey().equals(keysSelection.getSelectedKey())) {
                currentItemPosition = i;
                currentItem = item;
                break;
            }
        }
        initOrUpdateCurrentItem(ureq);
    } else if (source == compareSwitch) {
        if (compareSwitch.isSelected(0)) {
            compareLangSelection.setEnabled(true);
            compareArea.setVisible(true);
            updateCompareArea(ureq);
        } else {
            compareLangSelection.setEnabled(false);
            compareArea.setVisible(false);
            updateCompareArea(ureq);
        }
    } else if (source == compareLangSelection) {
        String selectedLangKey = compareLangSelection.getSelectedKey();
        compareLocale = I18nManager.getInstance().getLocaleOrNull(selectedLangKey);
        updateCompareArea(ureq);
    } else if (source == previousLink) {
        // don't save
        doPrevious(ureq);
    } else if (source == saveLink) {
        if (validateFormLogic(ureq)) {
            // only save
            doSaveCurrentItem(ureq);
        }
    } else if (source == saveNextLink) {
        if (validateFormLogic(ureq)) {
            // first save
            doSaveCurrentItem(ureq);
            // second update
            doNext(ureq);
        }
    } else if (source == nextLink) {
        // don't save
        doNext(ureq);
    } else if (source == annotationAddLink) {
        annotationArea.setValue("");
        annotationArea.setVisible(true);
        if (annotationAddLink != null) {
            this.flc.remove(annotationAddLink);
            annotationAddLink = null;
        }
    }
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

Example 5 with I18nItem

use of org.olat.core.util.i18n.I18nItem in project OpenOLAT by OpenOLAT.

the class TranslationDevManager method renameLanguageTask.

public void renameLanguageTask(Locale sourceLocale, Locale targetLocale) {
    // check if targetLocale exists already
    Set<String> allLangKeys = i18nModule.getAvailableLanguageKeys();
    if (allLangKeys.contains(targetLocale.getLanguage())) {
        log.error("Target Language " + targetLocale.getLanguage() + " already exists! ");
    } else {
        // get All items from sourceLocale, copy to targetLocale and delete sourceLocale
        List<I18nItem> items = i18nMgr.findExistingI18nItems(sourceLocale, null, true);
        for (I18nItem item : items) {
            String bundleName = item.getBundleName();
            String itemKey = item.getKey();
            I18nItem targetTempItem = new I18nItem(bundleName, itemKey, targetLocale, item.getBundlePriority(), item.getKeyPriority());
            Properties prop = i18nMgr.getPropertiesWithoutResolvingRecursively(sourceLocale, bundleName);
            String value = prop.getProperty(itemKey);
            i18nMgr.saveOrUpdateI18nItem(targetTempItem, value);
            deleteKey(sourceLocale, bundleName, itemKey);
        }
    }
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem) Properties(java.util.Properties)

Aggregations

I18nItem (org.olat.core.util.i18n.I18nItem)24 ArrayList (java.util.ArrayList)8 Locale (java.util.Locale)8 Properties (java.util.Properties)6 HashMap (java.util.HashMap)4 Entry (java.util.Map.Entry)4 I18nModule (org.olat.core.util.i18n.I18nModule)4 Preferences (org.olat.core.util.prefs.Preferences)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)2 ProgressBar (org.olat.core.gui.components.progressbar.ProgressBar)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2