Search in sources :

Example 1 with OutputFileOptions

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);
    }
}
Also used : OutputFileOptions(com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions) IOException(java.io.IOException) File(java.io.File) SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) SoyMsgBundleHandler(com.google.template.soy.msgs.SoyMsgBundleHandler)

Example 2 with OutputFileOptions

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());
}
Also used : OutputFileOptions(com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions) SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) URL(java.net.URL) Test(org.junit.Test)

Example 3 with OutputFileOptions

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));
}
Also used : OutputFileOptions(com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions) SoyMsgBundleHandler(com.google.template.soy.msgs.SoyMsgBundleHandler)

Aggregations

OutputFileOptions (com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions)3 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)2 SoyMsgBundleHandler (com.google.template.soy.msgs.SoyMsgBundleHandler)2 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Test (org.junit.Test)1