Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Warn and mark fuzzy if TextFlowTarget has unexpected plural forms
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Oct 18, 2013
1 parent e835fe4 commit 4b0d4c8
Showing 1 changed file with 10 additions and 18 deletions.
Expand Up @@ -22,7 +22,6 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -311,7 +310,7 @@ private void write(Writer writer, String charset, Resource document,
}
copyCommentsToMessage(tfTarget, message);
}
copyTFTContentsToMessage(textFlow, tftContents, nPlurals, message);
copyTFTContentsToMessage(document.getName(), textFlow, tftContents, nPlurals, message);

if (entryData != null) {
copyMetadataToMessage(entryData, srcComment, message);
Expand Down Expand Up @@ -371,7 +370,7 @@ private void copyTFContentsToMessage(TextFlow textFlow, Message message) {
if (tfContents.size() > 1) {
if (continueAfterError) {
log.warn(
"textflow has no plural flag but has multiple plural forms: restId={}",
"textflow has no plural flag but has multiple plural forms: resId={}",
textFlow.getId());
} else {
throwContinueableException(
Expand Down Expand Up @@ -417,7 +416,7 @@ private static void throwContinueableException(String specificErrorMessage,
}
}

private void copyTFTContentsToMessage(TextFlow textFlow,
private void copyTFTContentsToMessage(String docName, TextFlow textFlow,
List<String> tftContents, int nPlurals, Message message) {
if (message.isPlural()) {
while (tftContents.size() < nPlurals) {
Expand All @@ -427,27 +426,20 @@ private void copyTFTContentsToMessage(TextFlow textFlow,
message.addMsgstrPlural(tftContents.get(i), i);
}
if (tftContents.size() > nPlurals) {
log.warn("too many plural forms for text flow: resId={}",
textFlow.getId());
log.warn("Marking as fuzzy: too many plural forms for text "
+ "flow: resId={}, doc={}", textFlow.getId(), docName);
message.setFuzzy(true);
}
} else {
if (tftContents.size() == 0) {
message.setMsgstr("");
} else {
message.setMsgstr(tftContents.get(0));
if (tftContents.size() > 1) {
if (continueAfterError) {
log.warn(
"extra translation found and will be ignored in this text flow: resId={}",
textFlow.getId());
} else {
throwContinueableException(
"textflow has no plural flag but multiple plural forms: [resId="
+ textFlow.getId()
+ "]. This is likely caused by changed plural forms",
"To write content as singular form and continue");
}

log.warn("Marking as fuzzy: unexpected plural translation "
+ "found for text flow: resId={}, doc={}",
textFlow.getId(), docName);
message.setFuzzy(true);
}
}
}
Expand Down

0 comments on commit 4b0d4c8

Please sign in to comment.