Package org.olat.core.util.i18n

Examples of org.olat.core.util.i18n.I18nManager


   * @see org.olat.core.util.FileVisitor#visit(java.io.File)
   */
  public void visit(File file) {
    if (file.isFile()) { // regular file
      String toBeChechedkFilName = file.getName();
      I18nManager i18nMgr = I18nManager.getInstance();
      String computedFileName = i18nMgr.buildI18nFilename(moveLanguage);
      // match?
      if (toBeChechedkFilName.equals(computedFileName)) {
        File parentFile = file.getParentFile();
        String pPath = parentFile.getPath();
        String relTargetPath = "";
View Full Code Here


  /**
   * @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String, javax.servlet.http.HttpServletRequest)
   */
  public MediaResource handle(String relPath, HttpServletRequest request) {
    I18nManager i18nManager = I18nManager.getInstance();
    // Get bundle and locale
    String[] parts = relPath.split("/");
    String localeKey = parts[1];
    String bundleName = parts[2];
    Locale locale = i18nManager.getLocaleOrDefault(localeKey);
    // Create a media resource   
    StringMediaResource resource = new StringMediaResource() {
      @Override
      public void prepare(HttpServletResponse hres) {
        // don't use normal string media headers which prevent caching,
        // use standard browser caching based on last modified timestamp
      }
    };
    resource.setLastModified(i18nManager.getLastModifiedDate(locale, bundleName));
    resource.setContentType("text/javascript");
    // Get the translation data
    String translationData = i18nManager.getJSTranslatorData(locale, bundleName);
    resource.setData(translationData);
    // UTF-8 encoding used in this js file since explicitly set in the ajax
    // call (usually js files are 8859-1)
    resource.setEncoding("utf-8");
    return resource;
View Full Code Here

   * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
   */
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormUIFactory formFactory = FormUIFactory.getInstance();
    I18nManager i18nMgr = I18nManager.getInstance();
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    this.flc.contextPut("referenceLanguageKey", referenceLocale.toString());
    this.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 = formFactory.addDropdownSingleselect("bundlesSelection", this.flc, bundlesListArray, bundlesListArray, null);
    bundlesSelection.addActionListener(this, FormEvent.ONCHANGE);
    bundlesSelection.select(currentItem.getBundleName(), true);
    keysSelection = formFactory.addDropdownSingleselect("keysSelection", this.flc, keysListArray, keysListArray, null);
    keysSelection.addActionListener(this, FormEvent.ONCHANGE);
    keysSelection.select(currentItem.getKey(), true);
    // Add reference box
    referenceArea = formFactory.addTextAreaElement("referenceArea", "edit.referenceArea", -1, 1, -1, true, null, this.flc);
    referenceArea.setEnabled(false); // read only
    // Add compare box
    Boolean compareEnabledPrefs = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.FALSE);
    compareArea = formFactory.addTextAreaElement("compareArea", "edit.compareArea", -1, 1, -1, true, null, this.flc);
    compareArea.setEnabled(false); // read only
    compareArea.setVisible(compareEnabledPrefs.booleanValue());
    compareSwitch = formFactory.addCheckboxesHorizontal("compareSwitch", null, this.flc, new String[] { KEYS_ENABLED },
        new String[] { KEYS_EMPTY }, null);//i18nLabel set to null -> disabled label
    compareSwitch.select(KEYS_ENABLED, compareEnabledPrefs.booleanValue());
    compareSwitch.addActionListener(listener, FormEvent.ONCLICK);
    formLayout.add(compareSwitch);
    this.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[] compareLangCssClasses = i18nMgr.createLanguageFlagsCssClasses(comparelangKeys, "b_with_small_icon_left");
    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 = formFactory.addDropdownSingleselect("compareLangSelection", this.flc, comparelangKeys, compareLangValues,
        compareLangCssClasses);
    compareLangSelection.select(i18nMgr.getLocaleKey(compareLocale), true);
    this.flc.contextPut("compareLanguageKey", i18nMgr.getLocaleKey(compareLocale));
    compareLangSelection.addActionListener(this, FormEvent.ONCHANGE);
    compareLangSelection.setEnabled(compareEnabledPrefs.booleanValue());
    // Add target box
    this.flc.contextPut("targetLanguageKey", i18nMgr.getLocaleKey(currentItem.getLocale()));
    this.flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nMgr.getLocaleKey(currentItem.getLocale()), false));     
    targetArea = formFactory.addTextAreaElement("targetArea", "edit.targetArea", -1, 1, -1, true, null, this.flc);
    // Add annotation box
    annotationArea = formFactory.addTextAreaElement("annotationArea", "edit.annotationArea", -1, 1, -1, true, null, this.flc);
    // Add progress bar
    // init with values
    progressBarBundle = new ProgressBar("progressBarBundle", 200, 1, bundlesList.size(), translate("generic.bundles"));
    progressBarBundle.setPercentagesEnabled(false);
    this.flc.put("progressBarBundle", progressBarBundle);
    progressBarKey = new ProgressBar("progressBarKey", 200, 1, keysList.size(), translate("generic.keys"));
    progressBarKey.setPercentagesEnabled(false);
    this.flc.put("progressBarKey", progressBarKey);
    // Add navigation buttons
    previousLink = new FormLinkImpl("previousLink", "previousLink", "edit.button.previous", Link.BUTTON);
    formLayout.add(previousLink);
    saveLink = new FormLinkImpl("saveLink", "saveLink", "edit.button.save", Link.BUTTON);
    formLayout.add(saveLink);
    saveNextLink = new FormLinkImpl("saveNextLink", "saveNextLink", "edit.button.saveNext", Link.BUTTON);
    formLayout.add(saveNextLink);
    nextLink = new FormLinkImpl("nextLink", "nextLink", "edit.button.next", Link.BUTTON);
    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()));
      this.flc.contextPut("targetLanguageKey", i18nMgr.getLocaleKey(origLocale));     
      this.flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nMgr.getLocaleKey(origLocale), true));           
    }
    this.flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
    this.flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));

  }
View Full Code Here

    this.flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));

  }

  private void initOrUpdateCurrentItem(UserRequest ureq) {
    I18nManager i18nMgr = I18nManager.getInstance();
    // Set keys (must call before setting new currentItemPosition bundle name!
    if (bundlesSelection.getSelectedKey().equals(currentItem.getBundleName())) {
      // still in same bundle, just select the currentItemPosition key
      keysSelection.select(currentItem.getKey(), true);
      // Update key progress bar
      progressBarKey.setActual(keysSelection.getSelected() + 1);
    } else {
      // in new bundle, load new keys
      updateKeysSelectionAndProgress();
    }
    // Set reference value
    String refValue = i18nMgr.getLocalizedString(currentItem.getBundleName(), currentItem.getKey(), null, referenceLocale, false, false, false,
        false, 0);
    referenceArea.setValue(refValue);
    // Add target value
    String targetValue = i18nMgr.getLocalizedString(currentItem, null);
    targetArea.setValue(targetValue);
    // Add compare value
    updateCompareArea(ureq);
    // Add annotation
    currentAnnotation = i18nMgr.getAnnotation(currentItem);
    annotationArea.setValue(currentAnnotation);
    if (currentAnnotation == null) {
      annotationArea.setVisible(false);
      annotationAddLink = new FormLinkImpl("annotationAddLink", "annotationAddLink", "edit.button.add.annotation", Link.BUTTON_SMALL);
      this.flc.add(annotationAddLink);
View Full Code Here

  }

  private void updateCompareArea(UserRequest ureq) {
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    if (compareSwitch.isSelected(0)) {
      I18nManager i18nMgr = I18nManager.getInstance();
      // Add target value
      String compareValue = i18nMgr.getLocalizedString(currentItem.getBundleName(), currentItem.getKey(), null, compareLocale, customizingMode, false,
          false, false, 0);
      compareArea.setValue(compareValue);
      // save settings as gui prefs
      guiPrefs.put(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_COMPARE_LANG, compareLocale.toString());
      guiPrefs.putAndSave(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.TRUE);
View Full Code Here

    currentItem = i18nItems.get(currentItemPosition);
    initOrUpdateCurrentItem(ureq);
  }

  private void doSaveCurrentItem(UserRequest ureq) {
    I18nManager i18nMgr = I18nManager.getInstance();
    // update annotation if dirty
    String newAnnotation = annotationArea.getValue();
    if (!StringHelper.containsNonWhitespace(newAnnotation)) newAnnotation = null;
    // check if the same
    if (!StringUtils.equals(currentAnnotation, newAnnotation)) {
      currentAnnotation = newAnnotation;
      i18nMgr.setAnnotation(currentItem, currentAnnotation);
    }
    // update value if dirty
    String newValue = targetArea.getValue();
    if ((currentValue == null && newValue != null) || (newValue == null && currentValue != null) || !currentValue.equals(newValue)) {
      i18nMgr.saveOrUpdateI18nItem(currentItem, targetArea.getValue());
      currentValue = newValue;
      fireEvent(ureq, new I18nItemChangedEvent(currentItem));
    }
  }
View Full Code Here

   * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
   */
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormUIFactory formFactory = FormUIFactory.getInstance();
    I18nManager i18nMgr = I18nManager.getInstance();
    List<String> bundleNames = I18nModule.getBundleNamesContainingI18nFiles();
    String[] bundlesKeys = buildBundleArrayKeys(bundleNames, true);
    String[] bundlesValues = buildBundleArrayValues(bundleNames, true);
    // call init methods for each form part
    initLanguageSelectorElements(ureq.getUserSession(), formFactory, i18nMgr, listener, formLayout);
View Full Code Here

   * Internal helper to initialize or update the status bar and other
   * statistical information on the start page
   *
   */
  private void updateStatistics() {
    I18nManager i18nMgr = I18nManager.getInstance();
    // update progress bar with all package values
    int toTranslateCount = i18nMgr.countI18nItems(referenceLocale, null, true);
    int translatedCount = i18nMgr.countI18nItems(targetLocale, null, true);
    progressBar.setMax(toTranslateCount);
    progressBar.setActual(translatedCount);
    // calculate package dependent values for missing keys display
    String missingBundle = missingBundlesSelection.getSelectedKey();
    if (missingBundle.equals(ALL_BUNDLES_IDENTIFYER)) {
      this.flc.contextPut("missingCount", (toTranslateCount - translatedCount));
    } else {
      int missingToTranslateCount = i18nMgr.countI18nItems(referenceLocale, missingBundle, missingBundlesIncludeBundlesChildrenSwitch
          .isSelected(0));
      int missingTranslatedCount = i18nMgr.countI18nItems(targetLocale, missingBundle, missingBundlesIncludeBundlesChildrenSwitch
          .isSelected(0));
      this.flc.contextPut("missingCount", (missingToTranslateCount - missingTranslatedCount));
    }
    String existingBundle = existingBundlesSelection.getSelectedKey();
    if (existingBundle.equals(ALL_BUNDLES_IDENTIFYER)) {
      this.flc.contextPut("existingCount", translatedCount);
    } else {
      int existingTranslateCount = i18nMgr.countI18nItems(referenceLocale, existingBundle, existingBundlesIncludeBundlesChildrenSwitch.isSelected(0));
      this.flc.contextPut("existingCount", existingTranslateCount);
    }
    // calculate package dependent values for all keys display
    String allBundle = allBundlesSelection.getSelectedKey();
    if (allBundle.equals(ALL_BUNDLES_IDENTIFYER)) {
      this.flc.contextPut("allCount", toTranslateCount);
    } else {
      int allToTranslateCount = i18nMgr.countI18nItems(referenceLocale, allBundle, allBundlesIncludeBundlesChildrenSwitch.isSelected(0));
      this.flc.contextPut("allCount", allToTranslateCount);
    }
  }
View Full Code Here

  /**
   * Override text labels for all GUI elements to use the customizing texts
   * instead of the translation texts
   */
  private void setCustomizingTextLabels() {
    I18nManager i18nMgr = I18nManager.getInstance();
    referenceLangSelection.setLabel("start.customize.referenceLangSelection", null);
    targetLangSelection.setLabel("start.customize.targetLangSelection", null);   
    int bundlesCount = i18nMgr.countBundles(null, true);
    progressBar.setUnitLabel(translate("start.customize.progressBar.unitLabel", bundlesCount + ""));
    missingTranslateButton.setI18nKey("generic.customize.translateButton");
    allTranslateButton.setI18nKey("generic.customize.translateButton");
    searchTranslateButton.setI18nKey("generic.customize.translateButton");
   
View Full Code Here

   * formInnerEvent(org.olat.core.gui.UserRequest,
   * org.olat.core.gui.components.form.flexible.FormItem,
   * org.olat.core.gui.components.form.flexible.impl.FormEvent)
   */
  protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    I18nManager i18nMgr = I18nManager.getInstance();
    if (source == targetLangSelection) {
      String langKey = targetLangSelection.getSelectedKey();
      targetLocale = i18nMgr.getLocaleOrNull(langKey);
      // Add lang key for image - don't use customizing lang key
      if (customizingMode) {
        this.flc.contextPut("targetLangKey", i18nMgr.createOrigianlLocaleKeyForOverlay(targetLocale));
      } else {
        this.flc.contextPut("targetLangKey", targetLocale.toString());
      }
      updateStatistics();

    } else if (source == referenceLangSelection) {
      String langKey = referenceLangSelection.getSelectedKey();
      referenceLocale = i18nMgr.getLocaleOrNull(langKey);
      // update in gui prefs
      Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
      guiPrefs.putAndSave(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_REFERENCE_LANG, referenceLocale.toString());
      // update GUI
      this.flc.contextPut("referenceLangKey", i18nMgr.getLocaleKey(referenceLocale));
      // Set target language to reference language when in customizing mode
      if (customizingMode) {
        targetLocale = I18nModule.getOverlayLocales().get(referenceLocale)
        targetLangSelection.select(i18nMgr.getLocaleKey(targetLocale), true);
        this.flc.contextPut("targetLangKey", i18nMgr.getLocaleKey(referenceLocale));
      }
      updateStatistics();

    } else if (source == missingListButton || source == missingTranslateButton) {
      String bundle = missingBundlesSelection.getSelectedKey();
      if (bundle.equals(ALL_BUNDLES_IDENTIFYER)) bundle = null;
      boolean includeBundlesChildren = missingBundlesIncludeBundlesChildrenSwitch.isSelected(0);
      // use the fallback locale because it won't find the key if not already translated in the searchLocale
      List<I18nItem> i18nItems = i18nMgr.findMissingI18nItems(I18nModule.getFallbackLocale(), targetLocale, bundle,
          includeBundlesChildren);
      boolean prioSortEnabled = missingBundlesPrioritySortSwitch.isSelected(0);
      i18nMgr.sortI18nItems(i18nItems, prioSortEnabled, prioSortEnabled);
      deactivateAndDisposeChildCrumbController();
      // first the list controller
      TranslationToolI18nItemListCrumbController i18nItemlistCrumbCtr = new TranslationToolI18nItemListCrumbController(ureq,
          getWindowControl(), i18nItems, referenceLocale, customizingMode);
      activateAndListenToChildCrumbController(i18nItemlistCrumbCtr);
      // second the edit controller
      if (source == missingTranslateButton) {
        TranslationToolI18nItemEditCrumbController i18nItemEditCrumbCtr = new TranslationToolI18nItemEditCrumbController(ureq,
            getWindowControl(), i18nItems, referenceLocale, customizingMode);
        i18nItemlistCrumbCtr.activateAndListenToChildCrumbController(i18nItemEditCrumbCtr);
      }

    } else if (source == existingListButton || source == existingTranslateButton) {
      String bundle = existingBundlesSelection.getSelectedKey();
      if (bundle.equals(ALL_BUNDLES_IDENTIFYER)) bundle = null;
      boolean includeBundlesChildren = existingBundlesIncludeBundlesChildrenSwitch.isSelected(0);
      List<I18nItem> i18nItems = i18nMgr.findExistingI18nItems(targetLocale, bundle, includeBundlesChildren);
      boolean prioSortEnabled = existingBundlesPrioritySortSwitch.isSelected(0);
      i18nMgr.sortI18nItems(i18nItems, prioSortEnabled, prioSortEnabled);
      deactivateAndDisposeChildCrumbController();
      // first the list controller
      TranslationToolI18nItemListCrumbController i18nItemlistCrumbCtr = new TranslationToolI18nItemListCrumbController(ureq,
          getWindowControl(), i18nItems, referenceLocale, customizingMode);
      activateAndListenToChildCrumbController(i18nItemlistCrumbCtr);
      // second the edit controller
      if (source == existingTranslateButton) {
        TranslationToolI18nItemEditCrumbController i18nItemEditCrumbCtr = new TranslationToolI18nItemEditCrumbController(ureq,
            getWindowControl(), i18nItems, referenceLocale, customizingMode);
        i18nItemlistCrumbCtr.activateAndListenToChildCrumbController(i18nItemEditCrumbCtr);
      }

    } else if (source == allListButton || source == allTranslateButton) {
      String bundle = allBundlesSelection.getSelectedKey();
      if (bundle.equals(ALL_BUNDLES_IDENTIFYER)) bundle = null;
      boolean includeBundlesChildren = allBundlesIncludeBundlesChildrenSwitch.isSelected(0);
      List<I18nItem> i18nItems = i18nMgr.findExistingAndMissingI18nItems(referenceLocale, targetLocale, bundle,
          includeBundlesChildren);
      boolean prioSortEnabled = allBundlesPrioritySortSwitch.isSelected(0);
      i18nMgr.sortI18nItems(i18nItems, prioSortEnabled, prioSortEnabled);
      deactivateAndDisposeChildCrumbController();
      // first the list controller
      TranslationToolI18nItemListCrumbController i18nItemlistCrumbCtr = new TranslationToolI18nItemListCrumbController(ureq,
          getWindowControl(), i18nItems, referenceLocale, customizingMode);
      activateAndListenToChildCrumbController(i18nItemlistCrumbCtr);
      // second the edit controller
      if (source == allTranslateButton) {
        TranslationToolI18nItemEditCrumbController i18nItemEditCrumbCtr = new TranslationToolI18nItemEditCrumbController(ureq,
            getWindowControl(), i18nItems, referenceLocale, customizingMode);
        i18nItemlistCrumbCtr.activateAndListenToChildCrumbController(i18nItemEditCrumbCtr);
      }

    } else if (source == searchListButton || source == searchTranslateButton) {
      String bundle = searchBundlesSelection.getSelectedKey();
      if (bundle.equals(ALL_BUNDLES_IDENTIFYER)) bundle = null;
      boolean includeBundlesChildren = searchBundlesIncludeBundlesChildrenSwitch.isSelected(0);
      String searchString = searchInput.getValue();
      List<I18nItem> i18nItems;
      Locale searchLocale = (searchReferenceTargetSelection.getSelectedKey().equals(KEYS_REFERENCE) ? referenceLocale : targetLocale);
      if (searchKeyValueSelection.getSelectedKey().equals(KEYS_KEY)) {
        // use the fallback locale because it won't find the key if not already translated in the searchLocale
        i18nItems = i18nMgr.findI18nItemsByKeySearch(searchString, I18nModule.getFallbackLocale(), targetLocale, bundle,
            includeBundlesChildren);
      } else {
        i18nItems = i18nMgr.findI18nItemsByValueSearch(searchString, searchLocale, targetLocale, bundle,
            includeBundlesChildren);
      }
      boolean prioSortEnabled = searchBundlesPrioritySortSwitch.isSelected(0);
      I18nManager.getInstance().sortI18nItems(i18nItems, prioSortEnabled, prioSortEnabled);
      deactivateAndDisposeChildCrumbController();
View Full Code Here

TOP

Related Classes of org.olat.core.util.i18n.I18nManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.