Esempio n. 1
0
 /** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
 public void removeXKeysTask(boolean reallyRemoveIt) {
   List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
   Set<String> allLangs = getAllLanguages();
   int counter = 0;
   for (String langKey : allLangs) {
     Locale locale = i18nMgr.getLocaleOrNull(langKey);
     for (String bundleName : allBundles) {
       Properties properties =
           i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
       Set<Object> keys = properties.keySet();
       for (Object keyObj : keys) {
         String key = (String) keyObj;
         if (key.endsWith("X")) {
           String value = properties.getProperty(key);
           if (StringHelper.containsNonWhitespace(value)) {
             log.warn(
                 "NONEMPTY XKEY detected in lang::"
                     + locale.getLanguage()
                     + " bundle::"
                     + bundleName
                     + " key::"
                     + key
                     + " value::"
                     + value);
             if (reallyRemoveIt) {
               addKey(locale, bundleName, key.substring(0, key.length() - 1), value);
             }
           }
           log.info(
               "XKEY detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key);
           logText.append(
               i18nMgr.getPropertiesFile(
                       locale, bundleName, I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                   + " XKEY detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value
                   + "\n");
           if (reallyRemoveIt) {
             deleteKey(locale, bundleName, key);
           }
           counter++;
         }
       }
     }
   }
   if (reallyRemoveIt) {
     log.info(counter + " X-Keys got removed!");
   }
 }
Esempio n. 2
0
 /** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
 public void removeTodoKeysTask(boolean reallyRemoveIt) {
   List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
   Set<String> allLangs = getAllLanguages();
   int counter = 0;
   String[] comparisonStrings = {"TODO"};
   for (String langKey : allLangs) {
     Locale locale = i18nMgr.getLocaleOrNull(langKey);
     for (String bundleName : allBundles) {
       Properties properties =
           i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
       Set<Object> keys = properties.keySet();
       for (Object keyObj : keys) {
         String key = (String) keyObj;
         String value = properties.getProperty(key);
         for (int i = 0; i < comparisonStrings.length; i++) {
           int pos = value.toLowerCase().indexOf(comparisonStrings[i].toLowerCase());
           if (pos != -1 && pos < 2 && !value.toLowerCase().equals("todos")) {
             log.info(
                 "TODO-Key detected in lang::"
                     + locale.getLanguage()
                     + " bundle::"
                     + bundleName
                     + " key::"
                     + key
                     + " value::"
                     + value);
             if (value.length() > comparisonStrings[i].length() + 1) {
               log.warn(
                   "this is a TODO-Key WITH TEXT::"
                       + value.substring(comparisonStrings[i].length())
                       + "::");
             } else {
               logText.append(
                   i18nMgr.getPropertiesFile(
                           locale,
                           bundleName,
                           I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                       + " TODO-Key detected in lang::"
                       + locale.getLanguage()
                       + " bundle::"
                       + bundleName
                       + " key::"
                       + key
                       + " value::"
                       + value
                       + "\n");
               if (reallyRemoveIt) {
                 deleteKey(locale, bundleName, key);
               }
             }
             counter++;
           }
         }
       } // each key
     } // each bundle
   }
   log.info(counter + " TODO-Keys got removed!");
 }
Esempio n. 3
0
 protected void moveSingleKey(
     Locale locale,
     String originBundleName,
     String targetBundleName,
     String origKey,
     String targetKey) {
   Properties prop = i18nMgr.getPropertiesWithoutResolvingRecursively(locale, originBundleName);
   String value = prop.getProperty(origKey);
   deleteKey(locale, originBundleName, origKey);
   addKey(locale, targetBundleName, targetKey, value);
 }
Esempio n. 4
0
 public void movePackageTask(String originBundleName, String targetBundleName) {
   // remove package priority from metadata first
   deleteKey(null, originBundleName, I18nManager.METADATA_BUNDLE_PRIORITY_KEY);
   // copy all local string files and also the metadata file
   try {
     File sourceDir = getBundlePath(originBundleName);
     File destDir = getBundlePath(targetBundleName);
     copyDirectory(sourceDir, destDir);
   } catch (IOException e) {
     log.error("Files could not be copied from " + originBundleName + " to " + targetBundleName);
     e.printStackTrace();
   }
   deletePackage(originBundleName);
 }
Esempio n. 5
0
 /** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
 public void removeEmptyKeysTask(boolean reallyRemoveIt) {
   List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
   int counter = 0;
   Set<String> allLangs = getAllLanguages();
   for (String langKey : allLangs) {
     Locale locale = i18nMgr.getLocaleOrNull(langKey);
     for (String bundleName : allBundles) {
       Properties properties =
           i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
       Set<Object> keys = properties.keySet();
       for (Object keyObj : keys) {
         String key = (String) keyObj;
         String value = properties.getProperty(key);
         if (!StringHelper.containsNonWhitespace(value)) {
           log.info(
               "empty Key detected in lang::"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value);
           logText.append(
               i18nMgr.getPropertiesFile(
                       locale, bundleName, I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                   + " empty Key detected in lang"
                   + locale.getLanguage()
                   + " bundle::"
                   + bundleName
                   + " key::"
                   + key
                   + " value::"
                   + value
                   + "\n");
           if (reallyRemoveIt) {
             deleteKey(locale, bundleName, key);
           }
         }
         counter++;
       } // each key
     } // each bundle
   }
   log.info(counter + " empty Keys got removed!");
 }
Esempio n. 6
0
  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);
      }
    }
  }
Esempio n. 7
0
  /** @param reallyRemoveIt true: really remove it; false: dry run, only produce logging */
  public void removeReferenceLanguageCopiesTask(boolean reallyRemoveIt) {
    List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
    // don't remove EN and DE here, this is a shared Map!!
    int counter = 0;
    int aliasCounter = 0;
    // prepare exclusion list
    String exKeys =
        FileUtils.load(
            new File(
                I18nModule.getTransToolApplicationLanguagesSrcDir()
                    + "/org/olat/lms/commons/i18n/devtools/exclusionKeys.txt"),
            "UTF-8");
    String[] exArray = exKeys.split("\n");
    List<String> exList = new ArrayList<String>(Arrays.asList(exArray));

    Set<String> allLangs = getAllLanguages();
    for (String langKey : allLangs) {
      Locale locale = i18nMgr.getLocaleOrNull(langKey);
      if (locale.toString().equals("de") || locale.toString().equals("en")) {
        // don't compare with DE and EN itself
        continue;
      }
      for (String bundleName : allBundles) {
        Properties properties =
            i18nMgr.getPropertiesWithoutResolvingRecursively(locale, bundleName);
        Properties refPropDe =
            i18nMgr.getPropertiesWithoutResolvingRecursively(new Locale("de"), bundleName);
        Properties refPropEn =
            i18nMgr.getPropertiesWithoutResolvingRecursively(new Locale("en"), bundleName);
        Set<Object> keys = properties.keySet();
        for (Object keyObj : keys) {
          String key = (String) keyObj;
          // dont handle if in exclusion list
          if (!exList.contains(key)) {
            String value = properties.getProperty(key);
            // get ref-lang. value and compare:
            boolean foundInReferenceDe = false;
            boolean foundInReferenceEn = false;
            if (value.equals(refPropDe.getProperty(key))) {
              log.info(
                  "Value of Key found in reference Language DE. lang::"
                      + locale.getLanguage()
                      + " bundle::"
                      + bundleName
                      + " key::"
                      + key
                      + " value::"
                      + value);
              foundInReferenceDe = true;
            }
            if (value.equals(refPropEn.getProperty(key))) {
              log.info(
                  "Value of Key found in reference Language EN. lang::"
                      + locale.getLanguage()
                      + " bundle::"
                      + bundleName
                      + " key::"
                      + key
                      + " value::"
                      + value);
              foundInReferenceEn = true;
            }
            // probably an alias if found in both ref. lang.
            boolean readyToDelete = (foundInReferenceDe || foundInReferenceEn);
            if (foundInReferenceDe && foundInReferenceEn) {
              log.info(
                  "Matching value in both reference languages. lang::"
                      + locale.getLanguage()
                      + " bundle::"
                      + bundleName
                      + " key::"
                      + key
                      + " value::"
                      + value);
              readyToDelete = false;
              aliasCounter++;
            }
            if (readyToDelete && reallyRemoveIt) {
              deleteKey(locale, bundleName, key);
            }
            if (readyToDelete) {
              counter++;
              logText.append(
                  i18nMgr.getPropertiesFile(
                          locale,
                          bundleName,
                          I18nModule.getPropertyFilesBaseDir(locale, bundleName))
                      + " value of key found in reference -> remove lang::"
                      + locale.getLanguage()
                      + " bundle::"
                      + bundleName
                      + " key::"
                      + key
                      + " value::"
                      + value
                      + "\n");
            }
          }
        }
      }
    }
    log.info(counter + " Keys found/deleted with values copied from only one reference languages!");
    log.info(aliasCounter + " Keys which seems to be alias found and NOT deleted!");
  }
Esempio n. 8
0
 protected void changeValueForSingleKey(
     Locale locale, String bundleName, String key, String newValue) {
   deleteKey(locale, bundleName, key);
   addKey(locale, bundleName, key, newValue);
 }