private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
/** Append the placeholder to the output stream. */ private static void writePlaceholder( SoyMsgPlaceholderPart placeholder, Map<String, Object> placeholders, Appendable out) throws IOException { String placeholderName = placeholder.getPlaceholderName(); String str = (String) placeholders.get(placeholderName); if (str == null) { throw new IllegalArgumentException( "No value provided for placeholder: '" + placeholderName + "'"); } out.append(str); }
currRawTextPart = null; currMsgParts.add(new SoyMsgPlaceholderPart(atts.getValue("id"), atts.getValue("example")));
ilb.appendParts( "<x id=\"", attributeEscaper.escape(placeholder.getPlaceholderName()), "\"" + (placeholder.getPlaceholderExample() != null ? " example=\"" + attributeEscaper.escape(placeholder.getPlaceholderExample()) + "\"" : "")
/** * Process a {@code SoyMsgPlaceholderPart} and updates the internal data structures. * * @param msgPlaceholderPart the Placeholder part. */ private void visitPart(SoyMsgPlaceholderPart msgPlaceholderPart) { // Since the content of a placeholder is not altered by translation, just render // the corresponding placeholder node. visit(msgNode.getRepPlaceholderNode(msgPlaceholderPart.getPlaceholderName())); }
currRawTextPart = null; currMsgParts.add(new SoyMsgPlaceholderPart(atts.getValue("id")));
ilb.appendParts( "<x id=\"", attributeEscaper.escape(placeholder.getPlaceholderName()), "\"" + (placeholder.getPlaceholderExample() != null ? " example=\"" + attributeEscaper.escape(placeholder.getPlaceholderExample()) + "\"" : "")
/** * Process a {@code SoyMsgPlaceholderPart} and updates the internal data structures. * @param msgPlaceholderPart the Placeholder part. */ private void visitPart(SoyMsgPlaceholderPart msgPlaceholderPart) { // Since the content of a placeholder is not altered by translation, just render // the corresponding placeholder node. visit(msgNode.getRepPlaceholderNode(msgPlaceholderPart.getPlaceholderName())); }
private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
currRawTextPart = null; currMsgParts.add(new SoyMsgPlaceholderPart(atts.getValue("id"), atts.getValue("example")));
/** * Process a {@code SoyMsgPlaceholderPart} and updates the internal data structures. * * @param msgPlaceholderPart the Placeholder part. */ private void visitPart(SoyMsgPlaceholderPart msgPlaceholderPart) { // Since the content of a placeholder is not altered by translation, just render // the corresponding placeholder node. visit(msgNode.getRepPlaceholderNode(msgPlaceholderPart.getPlaceholderName())); }
/** * Builds the list of SoyMsgParts for all the children of a given parent node. * * @param parent Can be MsgNode, MsgPluralCaseNode, MsgPluralDefaultNode, MsgSelectCaseNode, or * MsgSelectDefaultNode. * @param msgNode The MsgNode containing 'parent'. */ private static ImmutableList<SoyMsgPart> buildMsgPartsForChildren( BlockNode parent, MsgNode msgNode) { ImmutableList.Builder<SoyMsgPart> msgParts = ImmutableList.builder(); for (StandaloneNode child : parent.getChildren()) { if (child instanceof RawTextNode) { String rawText = ((RawTextNode) child).getRawText(); msgParts.add(SoyMsgRawTextPart.of(rawText)); } else if (child instanceof MsgPlaceholderNode) { PlaceholderInfo placeholder = msgNode.getPlaceholder((MsgPlaceholderNode) child); msgParts.add(new SoyMsgPlaceholderPart(placeholder.name(), placeholder.example())); } else if (child instanceof MsgPluralNode) { msgParts.add(buildMsgPartForPlural((MsgPluralNode) child, msgNode)); } else if (child instanceof MsgSelectNode) { msgParts.add(buildMsgPartForSelect((MsgSelectNode) child, msgNode)); } } return msgParts.build(); }
/** * Private helper to build valid Python string for a list of {@link SoyMsgPart}s. * * <p>It only processes {@link SoyMsgRawTextPart} and {@link SoyMsgPlaceholderPart} and ignores * others, because we didn't generate a direct string for plural and select nodes. * * <p>For {@link SoyMsgRawTextPart}, it appends the raw text and applies necessary escaping; For * {@link SoyMsgPlaceholderPart}, it turns the placeholder's variable name into Python replace * format. * * @param parts The SoyMsgPart parts to convert. * @param escaper A Function which provides escaping for raw text. * @return A String representing all the {@code parts} in Python. */ private static String processMsgPartsHelper( ImmutableList<SoyMsgPart> parts, Function<String, String> escaper) { StringBuilder rawMsgTextSb = new StringBuilder(); for (SoyMsgPart part : parts) { if (part instanceof SoyMsgRawTextPart) { rawMsgTextSb.append(escaper.apply(((SoyMsgRawTextPart) part).getRawText())); } if (part instanceof SoyMsgPlaceholderPart) { String phName = ((SoyMsgPlaceholderPart) part).getPlaceholderName(); rawMsgTextSb.append("{" + phName + "}"); } } return rawMsgTextSb.toString(); }
private static void doBuildMsgPartsForChildren( MsgBlockNode parent, MsgNode msgNode, ImmutableList.Builder<SoyMsgPart> msgParts) { for (StandaloneNode child : parent.getChildren()) { if (child instanceof RawTextNode) { String rawText = ((RawTextNode) child).getRawText(); msgParts.add(SoyMsgRawTextPart.of(rawText)); } else if (child instanceof MsgPlaceholderNode) { PlaceholderInfo placeholder = msgNode.getPlaceholder((MsgPlaceholderNode) child); msgParts.add(new SoyMsgPlaceholderPart(placeholder.name(), placeholder.example())); } else if (child instanceof MsgPluralNode) { msgParts.add(buildMsgPartForPlural((MsgPluralNode) child, msgNode)); } else if (child instanceof MsgSelectNode) { msgParts.add(buildMsgPartForSelect((MsgSelectNode) child, msgNode)); } else if (child instanceof VeLogNode) { doBuildMsgPartsForChildren((VeLogNode) child, msgNode, msgParts); } else { throw new AssertionError("unexpected child: " + child); } } }
/** * Private helper to build valid Python string for a list of {@link SoyMsgPart}s. * * <p>It only processes {@link SoyMsgRawTextPart} and {@link SoyMsgPlaceholderPart} and ignores * others, because we didn't generate a direct string for plural and select nodes. * * <p>For {@link SoyMsgRawTextPart}, it appends the raw text and applies necessary escaping; For * {@link SoyMsgPlaceholderPart}, it turns the placeholder's variable name into Python replace * format. * * @param parts The SoyMsgPart parts to convert. * @param escaper A Function which provides escaping for raw text. * @return A String representing all the {@code parts} in Python. */ private static String processMsgPartsHelper( ImmutableList<SoyMsgPart> parts, Function<String, String> escaper) { StringBuilder rawMsgTextSb = new StringBuilder(); for (SoyMsgPart part : parts) { if (part instanceof SoyMsgRawTextPart) { rawMsgTextSb.append(escaper.apply(((SoyMsgRawTextPart) part).getRawText())); } if (part instanceof SoyMsgPlaceholderPart) { String phName = ((SoyMsgPlaceholderPart) part).getPlaceholderName(); rawMsgTextSb.append("{" + phName + "}"); } } return rawMsgTextSb.toString(); }
/** * Builds the list of SoyMsgParts for all the children of a given parent node. * @param parent Can be MsgNode, MsgPluralCaseNode, MsgPluralDefaultNode, * MsgSelectCaseNode, or MsgSelectDefaultNode. * @param msgNode The MsgNode containing 'parent'. */ private static List<SoyMsgPart> buildMsgPartsForChildren( BlockNode parent, MsgNode msgNode) { List<SoyMsgPart> msgParts = Lists.newArrayList(); for (StandaloneNode child : parent.getChildren()) { if (child instanceof RawTextNode) { String rawText = ((RawTextNode) child).getRawText(); msgParts.add(new SoyMsgRawTextPart(rawText)); } else if (child instanceof MsgPlaceholderNode) { String placeholderName = msgNode.getPlaceholderName((MsgPlaceholderNode) child); msgParts.add(new SoyMsgPlaceholderPart(placeholderName)); } else if (child instanceof MsgPluralRemainderNode) { msgParts.add(new SoyMsgPluralRemainderPart( msgNode.getPluralVarName(child.getNearestAncestor(MsgPluralNode.class)))); } else if (child instanceof MsgPluralNode) { msgParts.add(buildMsgPartForPlural((MsgPluralNode) child, msgNode)); } else if (child instanceof MsgSelectNode) { msgParts.add(buildMsgPartForSelect((MsgSelectNode) child, msgNode)); } } return msgParts; }
msgStrSb.append('{'); msgStrSb.append(((SoyMsgPlaceholderPart) msgPart).getPlaceholderName()); if (doUseBracedPhs) { msgStrSb.append('}');
msgStrSb.append('{'); msgStrSb.append(((SoyMsgPlaceholderPart) msgPart).getPlaceholderName()); if (doUseBracedPhs) { msgStrSb.append('}');
String placeholderName = ((SoyMsgPlaceholderPart) msgPart).getPlaceholderName(); if (doUseBracedPhs) {
/** * Generates code bits for a normal {@code MsgPlaceholderNode} inside a message. * * @param placeholder A node of type {@code MsgPlaceholderNode}. * @param msgNode The enclosing {@code MsgNode} object. * @param codeGenInfo Data structure holding information on placeholder names, plural variable * names, and select variable names to be used for message code generation. */ private void genGoogMsgCodeForPlaceholder( SoyMsgPlaceholderPart placeholder, MsgNode msgNode, GoogMsgPlaceholderCodeGenInfo codeGenInfo) { // For plural/select, the placeholder is an ICU placeholder, i.e. kept in all-caps. But for // goog.getMsg(), we must change the placeholder name to lower camel-case format. String googMsgPlaceholderName = codeGenInfo.isPlrselMsg ? placeholder.getPlaceholderName() : genGoogMsgPlaceholderName(placeholder.getPlaceholderName()); if (codeGenInfo.placeholders.contains(googMsgPlaceholderName)) { return; } MsgPlaceholderNode reprNode = msgNode.getRepPlaceholderNode(placeholder.getPlaceholderName()); codeGenInfo.placeholders.put(googMsgPlaceholderName, genGoogMsgPlaceholder(reprNode)); }