use of org.omegat.util.Language in project omegat by omegat-org.
the class SegmentBuilder method createActiveSegmentElement.
/**
* Create active segment for given entry
*/
private void createActiveSegmentElement(TMXEntry trans) throws BadLocationException {
try {
if (EditorSettings.DISPLAY_MODIFICATION_INFO_ALL.equals(settings.getDisplayModificationInfo()) || EditorSettings.DISPLAY_MODIFICATION_INFO_SELECTED.equals(settings.getDisplayModificationInfo())) {
addModificationInfoPart(trans);
}
int prevOffset = offset;
sourceText = addInactiveSegPart(true, ste.getSrcText());
Map<Language, ProjectTMX> otherLanguageTMs = Core.getProject().getOtherTargetLanguageTMs();
for (Map.Entry<Language, ProjectTMX> entry : otherLanguageTMs.entrySet()) {
TMXEntry altTrans = entry.getValue().getDefaultTranslation(ste.getSrcText());
if (altTrans != null && altTrans.isTranslated()) {
Language language = entry.getKey();
addOtherLanguagePart(altTrans.translation, language);
}
}
posSourceBeg = doc.createPosition(prevOffset + (hasRTL ? 1 : 0));
posSourceLength = sourceText.length();
if (trans.isTranslated()) {
// translation exist
translationText = trans.translation;
} else {
boolean insertSource = !Preferences.isPreference(Preferences.DONT_INSERT_SOURCE_TEXT);
if (controller.entriesFilter != null && controller.entriesFilter.isSourceAsEmptyTranslation()) {
insertSource = true;
}
if (insertSource) {
// need to insert source text on empty translation
String srcText = ste.getSrcText();
if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) {
srcText = EditorUtils.replaceGlossaryEntries(srcText);
}
translationText = srcText;
} else {
// empty text on non-exist translation
translationText = "";
}
}
translationText = addActiveSegPart(translationText);
posTranslationBeg = null;
doc.activeTranslationBeginM1 = doc.createPosition(activeTranslationBeginOffset - 1);
doc.activeTranslationEndP1 = doc.createPosition(activeTranslationEndOffset + 1);
} catch (OutOfMemoryError oome) {
// Oh shit, we're all out of storage space!
// Of course we should've cleaned up after ourselves earlier,
// but since we didn't, do a bit of cleaning up now, otherwise
// we can't even inform the user about our slacking off.
doc.remove(0, doc.getLength());
// Well, that cleared up some, GC to the rescue!
System.gc();
// There, that should do it, now inform the user
long memory = Runtime.getRuntime().maxMemory() / 1024 / 1024;
Log.logErrorRB("OUT_OF_MEMORY", memory);
Log.log(oome);
Core.getMainWindow().showErrorDialogRB("TF_ERROR", "OUT_OF_MEMORY", memory);
// Just quit, we can't help it anyway
System.exit(0);
}
}
use of org.omegat.util.Language in project omegat by omegat-org.
the class PoFilter method autoFillInPluralStatement.
/**
* Replaces Plural-Forms: nplurals=INTEGER; plural=EXPRESSION; when selected
* @param header The header text that contains the Plural-forms line.
* @return Header with the correct plural forms line according to target language.
*/
private String autoFillInPluralStatement(String header, FilterContext fc) {
if (autoFillInPluralStatement) {
Language targetLang = fc.getTargetLang();
String lang = targetLang.getLanguageCode().toLowerCase(Locale.ENGLISH);
PluralInfo pluralInfo = PLURAL_INFOS.get(lang);
if (pluralInfo != null) {
return header.replaceAll("Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;", "Plural-Forms: nplurals=" + pluralInfo.plurals + "; plural=" + pluralInfo.expression + ";");
}
}
return header;
}
use of org.omegat.util.Language in project omegat by omegat-org.
the class PoFilter method flushTranslation.
protected void flushTranslation(MODE currentMode, FilterContext fc) throws IOException {
if (sources[0].length() == 0 && path.isEmpty()) {
if (targets[0].length() == 0) {
// there is no text to translate yet
return;
} else {
// header
// check existing plural statement. If it contains the number of plurals, then use it!
StringBuilder targets0 = targets[0];
String header = targets[0].toString();
Matcher pluralMatcher = PLURAL_FORMS.matcher(header);
if (pluralMatcher.find()) {
String nrOfPluralsString = header.substring(pluralMatcher.start(1), pluralMatcher.end(1));
plurals = Integer.parseInt(nrOfPluralsString);
} else {
// else use predefined number of plurals, if it exists
Language targetLang = fc.getTargetLang();
String lang = targetLang.getLanguageCode().toLowerCase(Locale.ENGLISH);
PluralInfo pluralInfo = PLURAL_INFOS.get(lang);
if (pluralInfo != null) {
plurals = pluralInfo.plurals;
}
}
// update the number of targets according to new plural number
targets = new StringBuilder[plurals];
targets[0] = targets0;
for (int i = 1; i < plurals; i++) {
targets[i] = new StringBuilder();
}
if (out != null) {
// Header is always written
out.write("msgstr " + getTranslation(null, targets[0], false, true, fc, 0) + "\n");
} else {
alignHeader(targets[0].toString(), fc);
}
}
fuzzy = false;
} else {
// source exist
if (sources[1].length() == 0) {
// non-plurals
if (out != null) {
if (formatMonolingual) {
out.write("msgstr " + getTranslation(sources[0].toString(), targets[0], allowBlank, false, fc, 0) + "\n");
} else {
out.write("msgstr " + getTranslation(null, sources[0], allowBlank, false, fc, 0) + "\n");
}
} else {
align(0);
}
} else {
// plurals
if (out != null) {
out.write("msgstr[0] " + getTranslation(null, sources[0], allowBlank, false, fc, 0) + "\n");
for (int i = 1; i < plurals; i++) {
out.write("msgstr[" + i + "] " + getTranslation(null, sources[1], allowBlank, false, fc, i) + "\n");
}
} else {
align(0);
for (int i = 1; i < plurals; i++) {
align(i);
}
}
}
fuzzy = false;
}
sources[0].setLength(0);
sources[1].setLength(0);
for (int i = 0; i < plurals; i++) {
targets[i].setLength(0);
}
path = "";
translatorComments.setLength(0);
extractedComments.setLength(0);
references.setLength(0);
sourceFuzzyTrue.setLength(0);
}
Aggregations