use of org.pentaho.di.ui.i18n.KeyOccurrence in project pentaho-kettle by pentaho.
the class Translator2 method readFiles.
public void readFiles() throws KettleFileException {
log.logBasic(BaseMessages.getString(PKG, "i18n.Log.ScanningSourceDirectories"));
try {
// crawl through the source directories...
//
crawler = new MessagesSourceCrawler(log, rootDirectories, singleMessagesFile, xmlFolders);
crawler.setScanPhrases(scanPhrases);
crawler.setFilesToAvoid(filesToAvoid);
crawler.crawl();
store = new TranslationsStore(log, localeList, referenceLocale, crawler.getSourcePackageOccurrences());
store.read(rootDirectories);
// What are the statistics?
//
Map<String, int[]> folderKeyCounts = new HashMap<String, int[]>();
Map<String, Integer> nrKeysPerFolder = new HashMap<String, Integer>();
for (String sourceFolder : rootDirectories) {
folderKeyCounts.put(sourceFolder, new int[localeList.size()]);
}
for (String sourceFolder : rootDirectories) {
int[] keyCounts = folderKeyCounts.get(sourceFolder);
int nrKeys = 0;
for (int i = 0; i < localeList.size(); i++) {
String locale = localeList.get(i);
//
for (KeyOccurrence keyOccurrence : crawler.getKeyOccurrences(sourceFolder)) {
//
if (showKey(keyOccurrence.getKey(), keyOccurrence.getMessagesPackage())) {
String value = store.lookupKeyValue(locale, keyOccurrence.getMessagesPackage(), keyOccurrence.getKey());
if (!Utils.isEmpty(value)) {
keyCounts[i]++;
}
if (locale.equals(referenceLocale)) {
nrKeys++;
}
}
}
}
nrKeysPerFolder.put(sourceFolder, new Integer(nrKeys));
}
DecimalFormat pctFormat = new DecimalFormat("#00.00");
DecimalFormat nrFormat = new DecimalFormat("00");
for (String sourceFolder : rootDirectories) {
System.out.println("-------------------------------------");
System.out.println("Folder: " + sourceFolder);
System.out.println("-------------------------------------");
int nrKeys = nrKeysPerFolder.get(sourceFolder);
System.out.println(BaseMessages.getString(PKG, "i18n.Log.NumberOfKeysFound", "" + nrKeys));
int[] keyCounts = folderKeyCounts.get(sourceFolder);
String[] locales = localeList.toArray(new String[localeList.size()]);
for (int i = 0; i < locales.length; i++) {
for (int j = 0; j < locales.length - 1; j++) {
if (keyCounts[j] < keyCounts[j + 1]) {
int c = keyCounts[j];
keyCounts[j] = keyCounts[j + 1];
keyCounts[j + 1] = c;
String l = locales[j];
locales[j] = locales[j + 1];
locales[j + 1] = l;
}
}
}
for (int i = 0; i < locales.length; i++) {
double donePct = 100 * (double) keyCounts[i] / nrKeys;
int missingKeys = nrKeys - keyCounts[i];
String statusKeys = "# " + nrFormat.format(i + 1) + " : " + locales[i] + " : " + pctFormat.format(donePct) + "% " + BaseMessages.getString(PKG, "i18n.Log.CompleteKeys", keyCounts[i]) + (missingKeys != 0 ? BaseMessages.getString(PKG, "i18n.Log.MissingKeys", missingKeys) : "");
System.out.println(statusKeys);
}
}
} catch (Exception e) {
throw new KettleFileException(BaseMessages.getString(PKG, "i18n.Log.UnableToGetFiles", rootDirectories.toString()), e);
}
}
use of org.pentaho.di.ui.i18n.KeyOccurrence in project pentaho-kettle by pentaho.
the class Translator2 method showKeySelection.
protected void showKeySelection(String key) {
if (!key.equals(selectedKey)) {
applyChangedValue();
}
if (selectedLocale != null && key != null && selectedMessagesPackage != null) {
String mainValue = store.lookupKeyValue(referenceLocale, selectedMessagesPackage, key);
String value = store.lookupKeyValue(selectedLocale, selectedMessagesPackage, key);
KeyOccurrence keyOccurrence = crawler.getKeyOccurrence(key, selectedMessagesPackage);
wKey.setText(key);
wMain.setText(Const.NVL(mainValue, ""));
wValue.setText(Const.NVL(value, ""));
wSource.setText(Const.NVL(keyOccurrence.getSourceLine(), ""));
// Focus on the entry field
// Put the cursor all the way at the back
//
wValue.setFocus();
wValue.setSelection(wValue.getText().length());
wValue.showSelection();
wValue.clearSelection();
selectedKey = key;
lastValueChanged = false;
wApply.setEnabled(false);
wRevert.setEnabled(false);
}
}
use of org.pentaho.di.ui.i18n.KeyOccurrence in project pentaho-kettle by pentaho.
the class Translator2 method getTodoList.
private java.util.List<KeyOccurrence> getTodoList(String locale, String messagesPackage, String sourceFolder, boolean strict) {
// Get the list of keys that need a translation...
//
java.util.List<KeyOccurrence> keys = crawler.getOccurrencesForPackage(messagesPackage);
java.util.List<KeyOccurrence> todo = new ArrayList<KeyOccurrence>();
for (KeyOccurrence keyOccurrence : keys) {
//
if (showKey(keyOccurrence.getKey(), keyOccurrence.getMessagesPackage())) {
String value = store.lookupKeyValue(locale, messagesPackage, keyOccurrence.getKey());
if (Utils.isEmpty(value) || (wAll.getSelection() && !strict)) {
todo.add(keyOccurrence);
}
}
}
return todo;
}
use of org.pentaho.di.ui.i18n.KeyOccurrence in project pentaho-kettle by pentaho.
the class Translator2 method refreshPackages.
public void refreshPackages() {
int index = wPackages.getSelectionIndex();
// OK, we have a distinct list of packages to work with...
wPackages.table.removeAll();
Map<String, Map<String, java.util.List<KeyOccurrence>>> sourceMessagesPackages = crawler.getSourcePackageOccurrences();
for (String sourceFolder : sourceMessagesPackages.keySet()) {
Map<String, java.util.List<KeyOccurrence>> messagesPackages = sourceMessagesPackages.get(sourceFolder);
for (String messagesPackage : messagesPackages.keySet()) {
TableItem item = new TableItem(wPackages.table, SWT.NONE);
item.setText(1, sourceFolder);
item.setText(2, messagesPackage);
//
if (selectedLocale != null) {
java.util.List<KeyOccurrence> todo = getTodoList(selectedLocale, messagesPackage, sourceFolder, true);
if (todo.size() > 50) {
item.setBackground(GUIResource.getInstance().getColorRed());
} else if (todo.size() > 25) {
item.setBackground(GUIResource.getInstance().getColorOrange());
} else if (todo.size() > 10) {
item.setBackground(GUIResource.getInstance().getColorYellow());
} else if (todo.size() > 5) {
item.setBackground(GUIResource.getInstance().getColorBlue());
} else if (todo.size() > 0) {
item.setBackground(GUIResource.getInstance().getColorGreen());
}
}
}
if (messagesPackages.size() == 0) {
new TableItem(wPackages.table, SWT.NONE);
} else {
wPackages.setRowNums();
wPackages.optWidth(true);
wPackages.getTable().getColumn(1).setWidth(100);
}
}
if (index >= 0) {
wPackages.table.setSelection(index);
wPackages.table.showSelection();
}
}
Aggregations