use of org.omegat.util.TMXWriter2 in project omegat by omegat-org.
the class TestTeamIntegration method prepareRepo.
/**
* Prepare repository.
*/
static String prepareRepo() throws Exception {
File tmp = new File(DIR);
FileUtils.deleteDirectory(tmp);
if (tmp.exists()) {
throw new Exception("Impossible to delete test dir");
}
tmp.mkdirs();
File origDir = new File(tmp, "repo");
origDir.mkdir();
ProjectProperties config = createConfig(REPO, origDir);
RemoteRepositoryProvider remote = new RemoteRepositoryProvider(config.getProjectRootDir(), config.getRepositories());
remote.switchAllToLatest();
new File(origDir, "omegat").mkdirs();
File f = new File(origDir, "omegat/project_save.tmx");
TMXWriter2 wr = new TMXWriter2(f, SRC_LANG, TRG_LANG, true, false, true);
wr.close();
ProjectFileStorage.writeProjectFile(config);
remote.copyFilesFromProjectToRepo("omegat.project", null);
remote.commitFiles("omegat.project", "Prepare for team test");
remote.copyFilesFromProjectToRepo("omegat/project_save.tmx", null);
remote.commitFiles("omegat/project_save.tmx", "Prepare for team test");
return remote.getVersion("omegat/project_save.tmx");
}
use of org.omegat.util.TMXWriter2 in project omegat by omegat-org.
the class Aligner method writePairsToTMX.
public void writePairsToTMX(File outFile, List<Entry<String, String>> pairs) throws Exception {
TMXWriter2 writer = null;
String creator = OStrings.getApplicationName() + " Aligner";
long time = System.currentTimeMillis();
try {
writer = new TMXWriter2(outFile, srcLang, trgLang, true, true, false);
for (Entry<String, String> e : pairs) {
writer.writeEntry(e.getKey(), e.getValue(), null, creator, time, null, 0L, null);
}
} finally {
if (writer != null) {
try {
writer.close();
} catch (Exception ex) {
Log.log(ex);
}
}
}
}
use of org.omegat.util.TMXWriter2 in project omegat by omegat-org.
the class ProjectTMX method exportTMX.
public void exportTMX(ProjectProperties props, File outFile, final boolean forceValidTMX, final boolean levelTwo, final boolean useOrphaned) throws Exception {
TMXWriter2 wr = new TMXWriter2(outFile, props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), levelTwo, forceValidTMX);
try {
Map<String, TMXEntry> tempDefaults = new TreeMap<>();
Map<EntryKey, TMXEntry> tempAlternatives = new TreeMap<>();
synchronized (this) {
if (useOrphaned) {
// fast call - just copy
tempDefaults.putAll(defaults);
tempAlternatives.putAll(alternatives);
} else {
// slow call - copy non-orphaned only
for (Map.Entry<String, TMXEntry> en : defaults.entrySet()) {
if (checkOrphanedCallback.existSourceInProject(en.getKey())) {
tempDefaults.put(en.getKey(), en.getValue());
}
}
for (Map.Entry<EntryKey, TMXEntry> en : alternatives.entrySet()) {
if (checkOrphanedCallback.existEntryInProject(en.getKey())) {
tempAlternatives.put(en.getKey(), en.getValue());
}
}
}
}
List<String> p = new ArrayList<>();
wr.writeComment(" Default translations ");
for (Map.Entry<String, TMXEntry> en : new TreeMap<>(tempDefaults).entrySet()) {
p.clear();
if (Preferences.isPreferenceDefault(Preferences.SAVE_AUTO_STATUS, false)) {
if (en.getValue().linked == TMXEntry.ExternalLinked.xAUTO) {
p.add(PROP_XAUTO);
p.add("auto");
}
}
wr.writeEntry(en.getKey(), en.getValue().translation, en.getValue(), p);
}
wr.writeComment(" Alternative translations ");
for (Map.Entry<EntryKey, TMXEntry> en : new TreeMap<>(tempAlternatives).entrySet()) {
EntryKey k = en.getKey();
p.clear();
p.add(PROP_FILE);
p.add(k.file);
p.add(PROP_ID);
p.add(k.id);
p.add(PROP_PREV);
p.add(k.prev);
p.add(PROP_NEXT);
p.add(k.next);
p.add(PROP_PATH);
p.add(k.path);
if (Preferences.isPreferenceDefault(Preferences.SAVE_AUTO_STATUS, false)) {
if (en.getValue().linked == TMXEntry.ExternalLinked.xICE) {
p.add(PROP_XICE);
p.add(k.id);
} else if (en.getValue().linked == TMXEntry.ExternalLinked.x100PC) {
p.add(PROP_X100PC);
p.add(k.id);
}
}
wr.writeEntry(en.getKey().sourceText, en.getValue().translation, en.getValue(), p);
}
} finally {
wr.close();
}
}
Aggregations