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;
}
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();
}
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");
}
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();
}
Aggregations