Search in sources :

Example 6 with I18nItem

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

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

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

the class SingleKeyTranslatorController method deleteI18nKey.

/**
 * delete a key that is no longer used.
 *
 * @param key
 */
public void deleteI18nKey(String key) {
    for (I18nRowBundle bundle : bundles) {
        I18nItem item = i18nMng.getI18nItem(translatorBaseClass.getPackage().getName(), key, bundle.getOverlayLocale());
        i18nMng.saveOrUpdateI18nItem(item, "");
    }
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

Example 8 with I18nItem

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

the class TranslationDevManager method getDouplicateValues.

// do this only for reference language!
public List<I18nItem> getDouplicateValues() {
    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.findI18nItemsByValueSearch(keyValue, refLocale, refLocale, bundleName, false);
                doupList.addAll(tmpItem);
            } else {
                tempKeyMap.put(keyValue, keyName);
            }
        }
    }
    log.info("found " + doupList.size() + " douplicated values in 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 9 with I18nItem

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

the class TranslationDevManager method addKey.

protected void addKey(Locale locale, String bundleName, String key, String value) {
    I18nItem i18nItem = new I18nItem(bundleName, key, locale, I18nManager.DEFAULT_BUNDLE_PRIORITY, I18nManager.DEFAULT_KEY_PRIORITY);
    i18nMgr.saveOrUpdateI18nItem(i18nItem, value);
}
Also used : I18nItem(org.olat.core.util.i18n.I18nItem)

Example 10 with I18nItem

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

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)

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