Search in sources :

Example 11 with SoyMsgBundle

use of com.google.template.soy.msgs.SoyMsgBundle in project closure-templates by google.

the class SoyFileSet method doExtractMsgs.

/**
 * Performs the parsing and extraction logic.
 */
private SoyMsgBundle doExtractMsgs() {
    // extractMsgs disables a bunch of passes since it is typically not configured with things
    // like global definitions, type definitions, etc.
    SoyFileSetNode soyTree = parse(passManagerBuilder(SyntaxVersion.V1_0).allowUnknownGlobals().setTypeRegistry(SoyTypeRegistry.DEFAULT_UNKNOWN).disableAllTypeChecking(), // can't resolve strict types
    SoyTypeRegistry.DEFAULT_UNKNOWN, new PluginResolver(PluginResolver.Mode.ALLOW_UNDEFINED, printDirectives, soyFunctionMap, errorReporter)).fileSet();
    throwIfErrorsPresent();
    SoyMsgBundle bundle = new ExtractMsgsVisitor().exec(soyTree);
    throwIfErrorsPresent();
    return bundle;
}
Also used : SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) PluginResolver(com.google.template.soy.soyparse.PluginResolver) SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) ExtractMsgsVisitor(com.google.template.soy.msgs.internal.ExtractMsgsVisitor)

Example 12 with SoyMsgBundle

use of com.google.template.soy.msgs.SoyMsgBundle in project closure-templates by google.

the class SoyFileSet method extractAndWriteMsgs.

/**
 * Extracts all messages from this Soy file set and writes the messages to an output sink.
 *
 * @param msgBundleHandler Handler to write the messages.
 * @param options Options to configure how to write the extracted messages.
 * @param output Where to write the extracted messages.
 * @throws IOException If there are errors writing to the output.
 */
public void extractAndWriteMsgs(SoyMsgBundleHandler msgBundleHandler, OutputFileOptions options, ByteSink output) throws IOException {
    resetErrorReporter();
    SoyMsgBundle bundle = doExtractMsgs();
    msgBundleHandler.writeExtractedMsgs(bundle, options, output, errorReporter);
    throwIfErrorsPresent();
    reportWarnings();
}
Also used : SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle)

Example 13 with SoyMsgBundle

use of com.google.template.soy.msgs.SoyMsgBundle in project closure-templates by google.

the class RenderVisitorTest method testRenderMsgStmtWithFallback.

@Test
public void testRenderMsgStmtWithFallback() throws Exception {
    String templateBody = "" + "  {msg desc=\"\"}\n" + "    blah\n" + "  {fallbackmsg desc=\"\"}\n" + "    bleh\n" + "  {/msg}\n";
    // Without msg bundle.
    assertRender(templateBody, "blah");
    // With msg bundle.
    SoyFileNode file = SoyFileSetParserBuilder.forFileContents("{namespace test}\n{template .foo}\n" + templateBody + "{/template}").parse().fileSet().getChild(0);
    MsgFallbackGroupNode msgGroup = SoyTreeUtils.getAllNodesOfType(file.getChild(0), MsgFallbackGroupNode.class).get(0);
    MsgNode fallbackMsg = msgGroup.getChild(1);
    SoyMsg translatedFallbackMsg = SoyMsg.builder().setId(MsgUtils.computeMsgIdForDualFormat(fallbackMsg)).setLocaleString("x-zz").setParts(ImmutableList.<SoyMsgPart>of(SoyMsgRawTextPart.of("zbleh"))).build();
    SoyMsgBundle msgBundle = new SoyMsgBundleImpl("x-zz", Lists.newArrayList(translatedFallbackMsg));
    assertThat(renderWithDataAndMsgBundle(templateBody, TEST_DATA, msgBundle)).isEqualTo("zbleh");
}
Also used : SoyMsg(com.google.template.soy.msgs.restricted.SoyMsg) SoyMsgBundleImpl(com.google.template.soy.msgs.restricted.SoyMsgBundleImpl) MsgFallbackGroupNode(com.google.template.soy.soytree.MsgFallbackGroupNode) SoyFileNode(com.google.template.soy.soytree.SoyFileNode) SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) MsgNode(com.google.template.soy.soytree.MsgNode) SoyMsgPart(com.google.template.soy.msgs.restricted.SoyMsgPart) Test(org.junit.Test)

Example 14 with SoyMsgBundle

use of com.google.template.soy.msgs.SoyMsgBundle in project closure-templates by google.

the class RenderOnlySoyMsgBundleImplTest method testCopy.

@Test
public void testCopy() {
    // Take advantage of the fact that SoyMsgBundle actually implements Iterable<SoyMsg>.
    SoyMsgBundle copy = new RenderOnlySoyMsgBundleImpl(LOCALE, bundle);
    assertThat(copy.getLocaleString()).isEqualTo(LOCALE);
    assertThat(bundle).hasSize(testMessages.size());
    assertThat(copy).containsExactlyElementsIn(bundle).inOrder();
}
Also used : SoyMsgBundle(com.google.template.soy.msgs.SoyMsgBundle) Test(org.junit.Test)

Aggregations

SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)14 Test (org.junit.Test)7 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)5 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)5 SoyMsgBundleImpl (com.google.template.soy.msgs.restricted.SoyMsgBundleImpl)4 SoyMsgBundleHandler (com.google.template.soy.msgs.SoyMsgBundleHandler)3 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)3 MsgNode (com.google.template.soy.soytree.MsgNode)3 TemplateNode (com.google.template.soy.soytree.TemplateNode)3 IOException (java.io.IOException)3 URL (java.net.URL)3 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)2 OutputFileOptions (com.google.template.soy.msgs.SoyMsgBundleHandler.OutputFileOptions)2 ExtractMsgsVisitor (com.google.template.soy.msgs.internal.ExtractMsgsVisitor)2 SoyMsgPart (com.google.template.soy.msgs.restricted.SoyMsgPart)2 PluginResolver (com.google.template.soy.soyparse.PluginResolver)2 RawTextNode (com.google.template.soy.soytree.RawTextNode)2 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)2 File (java.io.File)2