Search in sources :

Example 16 with I18nItem

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

the class TranslationToolI18nItemEditCrumbController method initialzeI18nitemAsCurrentItem.

/**
 * Initializes the view of the controller for the given i18n item. The item
 * must exist in the i18nItems list that has been used when constructing this
 * object
 *
 * @param ureq
 * @param toBeActivatedItem
 */
public void initialzeI18nitemAsCurrentItem(UserRequest ureq, I18nItem toBeActivatedItem) {
    // find item in list
    for (int i = 0; i < i18nItems.size(); i++) {
        I18nItem item = i18nItems.get(i);
        if (item.equals(toBeActivatedItem)) {
            currentItemPosition = i;
            currentItem = i18nItems.get(currentItemPosition);
            initOrUpdateCurrentItem(ureq);
            return;
        }
    }
    // ups, could not find item, log error and continue
    logError("Could not init view for item with key::" + toBeActivatedItem.getKey() + " in bundle::" + toBeActivatedItem.getBundleName() + " in language::" + toBeActivatedItem.getLocale().toString(), null);
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

Example 17 with I18nItem

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

the class SingleKeyTranslatorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // save new values
    for (I18nRowBundle bundle : bundles) {
        String newValue = textElements.get(bundle.getLanguageKey()).getValue();
        // bundle.getLanguageKey() + ":: " + newValue);
        for (String itemKey : this.i18nItemKeys) {
            I18nItem item = i18nMng.getI18nItem(translatorBaseClass.getPackage().getName(), itemKey, bundle.getOverlayLocale());
            i18nMng.saveOrUpdateI18nItem(item, newValue);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

Example 18 with I18nItem

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

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 19 with I18nItem

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

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 20 with I18nItem

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

the class TranslationToolI18nItemEditCrumbController method initialzeI18nitemAsCurrentItem.

/**
 * Initializes the view of the controller for the given i18n item. The item
 * must exist in the i18nItems list that has been used when constructing this
 * object
 *
 * @param ureq
 * @param toBeActivatedItem
 */
public void initialzeI18nitemAsCurrentItem(UserRequest ureq, I18nItem toBeActivatedItem) {
    // find item in list
    for (int i = 0; i < i18nItems.size(); i++) {
        I18nItem item = i18nItems.get(i);
        if (item.equals(toBeActivatedItem)) {
            currentItemPosition = i;
            currentItem = i18nItems.get(currentItemPosition);
            initOrUpdateCurrentItem(ureq);
            return;
        }
    }
    // ups, could not find item, log error and continue
    logError("Could not init view for item with key::" + toBeActivatedItem.getKey() + " in bundle::" + toBeActivatedItem.getBundleName() + " in language::" + toBeActivatedItem.getLocale().toString(), null);
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

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