Search in sources :

Example 6 with SoyMsgBundleImpl

use of com.google.template.soy.msgs.restricted.SoyMsgBundleImpl 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)

Aggregations

SoyMsgBundleImpl (com.google.template.soy.msgs.restricted.SoyMsgBundleImpl)6 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)4 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)4 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)3 MsgNode (com.google.template.soy.soytree.MsgNode)3 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)3 TemplateNode (com.google.template.soy.soytree.TemplateNode)3 Test (org.junit.Test)3 RawTextNode (com.google.template.soy.soytree.RawTextNode)2 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)1 ExtractMsgsVisitor (com.google.template.soy.msgs.internal.ExtractMsgsVisitor)1 SoyMsgPart (com.google.template.soy.msgs.restricted.SoyMsgPart)1 SoyMsgPlaceholderPart (com.google.template.soy.msgs.restricted.SoyMsgPlaceholderPart)1 FindTransitiveDepTemplatesVisitor (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor)1 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)1 PluginResolver (com.google.template.soy.soyparse.PluginResolver)1 MsgHtmlTagNode (com.google.template.soy.soytree.MsgHtmlTagNode)1