use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.
the class RealProject method loadTM.
/**
* Locates and loads external TMX files with legacy translations. Uses directory monitor for check file
* updates.
*/
private void loadTM() throws IOException {
File tmRoot = new File(config.getTMRoot());
tmMonitor = new DirectoryMonitor(tmRoot, file -> {
if (!ExternalTMFactory.isSupported(file)) {
// not a TMX file
return;
}
if (file.getPath().replace('\\', '/').startsWith(config.getTMOtherLangRoot())) {
// tmx in other language, which is already shown in editor. Skip it.
return;
}
// create new translation memories map
Map<String, ExternalTMX> newTransMemories = new TreeMap<>(transMemories);
if (file.exists()) {
try {
ExternalTMX newTMX = ExternalTMFactory.load(file);
newTransMemories.put(file.getPath(), newTMX);
// directory separators into "/".
if (FileUtil.computeRelativePath(tmRoot, file).startsWith(OConsts.AUTO_TM + "/")) {
appendFromAutoTMX(newTMX, false);
} else if (FileUtil.computeRelativePath(tmRoot, file).startsWith(OConsts.AUTO_ENFORCE_TM + '/')) {
appendFromAutoTMX(newTMX, true);
}
} catch (Exception e) {
String filename = file.getPath();
Log.logErrorRB(e, "TF_TM_LOAD_ERROR", filename);
Core.getMainWindow().displayErrorRB(e, "TF_TM_LOAD_ERROR", filename);
}
} else {
newTransMemories.remove(file.getPath());
}
transMemories = newTransMemories;
});
tmMonitor.checkChanges();
tmMonitor.start();
}
use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.
the class ScriptsMonitor method start.
public void start(final File scriptDir) {
this.m_scriptDir = scriptDir;
m_monitor = new DirectoryMonitor(scriptDir, this, this);
m_monitor.start();
// Immediately execute APPLICATION_STARTUP event scripts
if (!applicationStartupEventScriptsExecuted) {
// first-time only
applicationStartupEventScriptsExecuted = true;
addEventScripts(EventType.APPLICATION_STARTUP);
ArrayList<ScriptItem> scripts = m_eventsScript.get(EventType.APPLICATION_STARTUP);
for (ScriptItem si : scripts) {
m_scriptingWindow.executeScriptFile(si);
}
scripts.clear();
}
}
use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.
the class GlossaryManager method start.
public void start() {
File dir = new File(Core.getProject().getProjectProperties().getGlossaryRoot());
priorityGlossary = new File(Core.getProject().getProjectProperties().getWriteableGlossary());
monitor = new DirectoryMonitor(dir, this);
monitor.start();
}
use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.
the class RealProject method loadOtherLanguages.
/**
* Locates and loads external TMX files with legacy translations. Uses directory monitor for check file
* updates.
*/
private void loadOtherLanguages() throws IOException {
File tmOtherLanguagesRoot = new File(config.getTMOtherLangRoot());
tmOtherLanguagesMonitor = new DirectoryMonitor(tmOtherLanguagesRoot, file -> {
String name = file.getName();
if (!name.matches("[A-Z]{2}([-_][A-Z]{2})?\\.tmx")) {
// not a TMX file in XX_XX.tmx format
return;
}
Language targetLanguage = new Language(name.substring(0, name.length() - ".tmx".length()));
// create new translation memories map
Map<Language, ProjectTMX> newOtherTargetLangTMs = new TreeMap<>(otherTargetLangTMs);
if (file.exists()) {
try {
ProjectTMX newTMX = new ProjectTMX(config.getSourceLanguage(), targetLanguage, config.isSentenceSegmentingEnabled(), file, checkOrphanedCallback);
newOtherTargetLangTMs.put(targetLanguage, newTMX);
} catch (Exception e) {
String filename = file.getPath();
Log.logErrorRB(e, "TF_TM_LOAD_ERROR", filename);
Core.getMainWindow().displayErrorRB(e, "TF_TM_LOAD_ERROR", filename);
}
} else {
newOtherTargetLangTMs.remove(targetLanguage);
}
otherTargetLangTMs = newOtherTargetLangTMs;
});
tmOtherLanguagesMonitor.checkChanges();
tmOtherLanguagesMonitor.start();
}
use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.
the class DictionariesManager method start.
public void start(File dictDir) {
monitor = new DirectoryMonitor(dictDir, this);
monitor.start();
}
Aggregations