use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.
the class Translator2 method saveFiles.
protected boolean saveFiles() {
java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
if (changedMessagesStores.size() > 0) {
StringBuilder msg = new StringBuilder();
for (MessagesStore messagesStore : changedMessagesStores) {
String filename = messagesStore.getSaveFilename(messagesStore.getSourceFolder());
messagesStore.setFilename(filename);
msg.append(messagesStore.getFilename());
if (!new File(filename).exists()) {
msg.append(" (NEW!)");
}
msg.append(Const.CR);
}
EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "i18nDialog.ChangedFiles"), BaseMessages.getString(PKG, "i18nDialog.ChangedMessagesFiles"), msg.toString());
if (dialog.open() != null) {
try {
for (MessagesStore messagesStore : changedMessagesStores) {
messagesStore.write();
log.logBasic(BaseMessages.getString(PKG, "i18n.Log.SavedMessagesFile", messagesStore.getFilename()));
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
return false;
}
return true;
} else {
return false;
}
} else {
// TODO: disable the button if nothing changed.
return true;
}
}
use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.
the class Translator2 method saveFilesToZip.
protected void saveFilesToZip() {
if (saveFiles()) {
java.util.List<MessagesStore> messagesStores = store.getMessagesStores(selectedLocale, null);
if (messagesStores.size() > 0) {
StringBuilder msg = new StringBuilder();
for (MessagesStore messagesStore : messagesStores) {
// Find the main locale variation for this messages store...
//
MessagesStore mainLocaleMessagesStore = store.findMainLocaleMessagesStore(messagesStore.getSourceFolder(), messagesStore.getMessagesPackage());
String sourceDirectory = mainLocaleMessagesStore.getSourceDirectory(rootDirectories);
String filename = messagesStore.getSaveFilename(sourceDirectory);
messagesStore.setFilename(filename);
msg.append(filename).append(Const.CR);
}
// Ask for the target filename if we're still here...
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.zip", "*" });
dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.ZIPFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
if (dialog.open() != null) {
String zipFilename = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename));
byte[] buf = new byte[1024];
for (MessagesStore messagesStore : messagesStores) {
FileInputStream in = new FileInputStream(messagesStore.getFilename());
out.putNextEntry(new ZipEntry(messagesStore.getFilename()));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
}
}
}
}
}
use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.
the class Translator2 method quitFile.
public boolean quitFile() {
java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
if (changedMessagesStores.size() > 0) {
MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_WARNING);
mb.setMessage(BaseMessages.getString(PKG, "i18nDialog.ChangedFilesWhenExit", changedMessagesStores.size() + ""));
mb.setText(BaseMessages.getString(PKG, "i18nDialog.Warning"));
int answer = mb.open();
if (answer == SWT.NO) {
return false;
}
}
WindowProperty winprop = new WindowProperty(shell);
props.setScreen(winprop);
props.saveProps();
shell.dispose();
display.dispose();
return true;
}
use of org.pentaho.di.ui.i18n.MessagesStore in project pentaho-kettle by pentaho.
the class Translator2 method searchAgain.
protected void searchAgain(String searchLocale) {
if (searchString != null) {
// We want to search for key in the list here...
// That means we'll enter a String to search for in the values
//
String upperSearchString = searchString.toUpperCase();
boolean lastKeyFound = lastFoundKey == null;
// Search through all the main locale messages stores for the selected
// package
//
java.util.List<MessagesStore> mainLocaleMessagesStores = store.getMessagesStores(searchLocale, selectedMessagesPackage);
for (MessagesStore messagesStore : mainLocaleMessagesStores) {
for (String key : messagesStore.getMessagesMap().keySet()) {
String value = messagesStore.getMessagesMap().get(key);
String upperValue = value.toUpperCase();
if (upperValue.indexOf(upperSearchString) >= 0) {
//
if (lastKeyFound) {
int index = wTodo.indexOf(key);
if (index >= 0) {
lastFoundKey = key;
wTodo.setSelection(index);
showKeySelection(wTodo.getSelection()[0]);
return;
}
}
if (key.equals(lastFoundKey)) {
lastKeyFound = true;
}
}
}
}
}
}
Aggregations