use of com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions in project closure-templates by google.
the class SoyMsgPruner method compile.
@Override
void compile(SoyFileSet.Builder sfsBuilder, Injector injector) throws IOException {
sfsBuilder.setAllowExternalCalls(allowExternalCalls);
SoyFileSet sfs = sfsBuilder.build();
SoyMsgBundleHandler msgBundleHandler = new SoyMsgBundleHandler(messagePlugin);
// Main loop.
for (int i = 0; i < inputMsgFiles.size(); i++) {
// Get the input msg bundle.
File inputMsgFilePath = inputMsgFiles.get(i);
SoyMsgBundle origTransMsgBundle = msgBundleHandler.createFromFile(inputMsgFilePath);
if (origTransMsgBundle.getLocaleString() == null) {
throw new IOException("Error opening or parsing message file " + inputMsgFilePath);
}
// Do the pruning.
SoyMsgBundle prunedTransSoyMsgBundle = sfs.pruneTranslatedMsgs(origTransMsgBundle);
// Write out the pruned msg bundle.
File outputMsgFilePath = outputMsgFiles.get(i);
msgBundleHandler.writeToTranslatedMsgsFile(prunedTransSoyMsgBundle, new OutputFileOptions(), outputMsgFilePath);
}
}
use of com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions in project closure-templates by google.
the class XliffMsgPluginTest method testGenerateExtractedMsgsFile.
@Test
public void testGenerateExtractedMsgsFile() throws Exception {
URL testSoyFile = Resources.getResource(XliffMsgPluginTest.class, "test_data/test-v2.soy");
SoyMsgBundle msgBundle = SoyFileSet.builder().add(testSoyFile).build().extractMsgs();
XliffMsgPlugin msgPlugin = new XliffMsgPlugin();
// Test without target language.
OutputFileOptions outputFileOptions = new OutputFileOptions();
CharSequence extractedMsgsFile = msgPlugin.generateExtractedMsgsFile(msgBundle, outputFileOptions, ErrorReporter.exploding());
URL expectedExtractedMsgsFile = Resources.getResource(XliffMsgPluginTest.class, "test_data/test-v2_extracted.xlf");
assertEquals(Resources.toString(expectedExtractedMsgsFile, UTF_8), extractedMsgsFile.toString());
// Test with target language.
outputFileOptions.setTargetLocaleString("x-zz");
extractedMsgsFile = msgPlugin.generateExtractedMsgsFile(msgBundle, outputFileOptions, ErrorReporter.exploding());
expectedExtractedMsgsFile = Resources.getResource(XliffMsgPluginTest.class, "test_data/test-v2_extracted_x-zz.xlf");
assertEquals(Resources.toString(expectedExtractedMsgsFile, UTF_8), extractedMsgsFile.toString());
}
use of com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions in project closure-templates by google.
the class SoyMsgExtractor method compile.
@Override
void compile(SoyFileSet.Builder sfsBuilder, Injector injector) throws IOException {
sfsBuilder.setAllowExternalCalls(allowExternalCalls);
SoyFileSet sfs = sfsBuilder.build();
OutputFileOptions options = new OutputFileOptions();
options.setSourceLocaleString(sourceLocaleString);
if (targetLocaleString.length() > 0) {
options.setTargetLocaleString(targetLocaleString);
}
sfs.extractAndWriteMsgs(new SoyMsgBundleHandler(messagePlugin), options, Files.asByteSink(outputFile));
}
Aggregations