Search in sources :

Example 21 with I18nItem

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

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

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

the class TranslationToolI18nItemListCrumbController 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) {
    // Add the translate all button
    allTranslateButtonTop = new FormLinkImpl("allTranslateButtonTop", "allTranslateButtonTop", "generic.translateAllButton", Link.BUTTON);
    formLayout.add(allTranslateButtonTop);
    allTranslateButtonBottom = new FormLinkImpl("allTranslateButtonBottom", "allTranslateButtonBottom", "generic.translateAllButton", Link.BUTTON);
    formLayout.add(allTranslateButtonBottom);
    // Add a translate button for each package
    String currentBundleName = null;
    int bundlesCount = 0;
    for (I18nItem item : i18nItems) {
        if (!item.getBundleName().equals(currentBundleName)) {
            currentBundleName = item.getBundleName();
            String linkName = "translateBundle_" + currentBundleName;
            String label = (customizingMode ? "generic.customize.translateButton" : "generic.translateButton");
            FormLink bundleTranslateButton = new FormLinkImpl(linkName, linkName, label, Link.BUTTON_SMALL);
            // use first item of bundle
            bundleTranslateButton.setUserObject(item);
            formLayout.add(bundleTranslateButton);
            bundlesCount++;
        }
    }
    // Add all the items to velocity
    this.flc.contextPut("i18nItems", i18nItems);
    this.flc.contextPut("bundlesCount", bundlesCount);
    this.flc.contextPut("keysCount", i18nItems.size());
    // Override text labels for customizing mode
    if (customizingMode) {
        allTranslateButtonTop.setI18nKey("generic.customize.translateAllButton");
        allTranslateButtonBottom.setI18nKey("generic.customize.translateAllButton");
    }
    this.flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
    this.flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 23 with I18nItem

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

the class TranslationDevManager method getDouplicateKeys.

// do this only for reference language!
public List<I18nItem> getDouplicateKeys() {
    Locale refLocale = i18nModule.getDefaultLocale();
    List<I18nItem> doupList = new ArrayList<I18nItem>();
    List<String> allBundles = i18nModule.getBundleNamesContainingI18nFiles();
    Map<String, String> tempKeyMap = new HashMap<String, String>();
    for (String bundleName : allBundles) {
        Properties properties = i18nMgr.getPropertiesWithoutResolvingRecursively(refLocale, bundleName);
        for (Iterator<Entry<Object, Object>> keyIter = properties.entrySet().iterator(); keyIter.hasNext(); ) {
            Entry<Object, Object> keyEntry = keyIter.next();
            String keyName = (String) keyEntry.getKey();
            String keyValue = (String) keyEntry.getValue();
            if (tempKeyMap.containsKey(keyName)) {
                List<I18nItem> tmpItem = i18nMgr.findI18nItemsByKeySearch(keyName, refLocale, refLocale, bundleName, false);
                doupList.addAll(tmpItem);
            } else {
                tempKeyMap.put(keyName, keyValue);
            }
        }
    }
    log.info("found " + doupList.size() + " douplicated keys");
    return doupList;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Entry(java.util.Map.Entry) I18nItem(org.olat.core.util.i18n.I18nItem)

Example 24 with I18nItem

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

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