@Override public final String toString() { return getRawText(); }
@Override public void endElement(String uri, String localName, String qName) { if (qName.equals("target")) { // End 'target': Save the preceding raw text (if any). Then create a SoyMsg object from the // collected message data and add it to msgs list. if (currRawTextPart != null) { currMsgParts.add(new SoyMsgRawTextPart(currRawTextPart)); currRawTextPart = null; } isInMsg = false; if (currMsgParts.size() > 0) { msgs.add(new SoyMsg( currMsgId, targetLocaleString, null, null, false, null, null, currMsgParts)); } } }
/** * Given a list of msg parts: (a) if it contains any plural/select parts, then builds a new list * of msg parts where plural/select parts in the original msg parts are all embedded as raw text * in ICU format, (b) if it doesn't contain any plural/select parts, then simply returns the * original msg parts instead of creating a new list of identical msg parts. * * @param origMsgParts The msg parts to convert. * @return A new list of msg parts with embedded ICU syntax if the original msg parts contain * plural/select parts, otherwise the original msg parts. */ public static ImmutableList<SoyMsgPart> convertMsgPartsToEmbeddedIcuSyntax( ImmutableList<SoyMsgPart> origMsgParts) { // If origMsgParts doesn't have plural/select parts, simply return it. if (!MsgPartUtils.hasPlrselPart(origMsgParts)) { return origMsgParts; } // Build the new msg parts. ImmutableList.Builder<SoyMsgPart> newMsgPartsBuilder = ImmutableList.builder(); StringBuilder currRawTextSb = new StringBuilder(); convertMsgPartsHelper( newMsgPartsBuilder, currRawTextSb, origMsgParts, /* isInPlrselPart= */ false); if (currRawTextSb.length() > 0) { newMsgPartsBuilder.add(SoyMsgRawTextPart.of(currRawTextSb.toString())); } return newMsgPartsBuilder.build(); }
String rawText = ((SoyMsgRawTextPart) origMsgPart).getRawText(); if (isInPlrselPart) { rawText = icuEscape(rawText); newMsgPartsBuilder.add(SoyMsgRawTextPart.of(currRawTextSb.toString())); currRawTextSb.setLength(0);
String rawText = ((SoyMsgRawTextPart) origMsgPart).getRawText(); if (isInPlrselPart) { rawText = icuEscape(rawText); newMsgPartsBuilder.add(SoyMsgRawTextPart.of(currRawTextSb.toString())); currRawTextSb.setLength(0);
@Override public final String toString() { return getRawText(); }
/** * Given a list of msg parts: (a) if it contains any plural/select parts, then builds a new list * of msg parts where plural/select parts in the original msg parts are all embedded as raw text * in ICU format, (b) if it doesn't contain any plural/select parts, then simply returns the * original msg parts instead of creating a new list of identical msg parts. * * @param origMsgParts The msg parts to convert. * @return A new list of msg parts with embedded ICU syntax if the original msg parts contain * plural/select parts, otherwise the original msg parts. */ public static ImmutableList<SoyMsgPart> convertMsgPartsToEmbeddedIcuSyntax( ImmutableList<SoyMsgPart> origMsgParts) { // If origMsgParts doesn't have plural/select parts, simply return it. if (!MsgPartUtils.hasPlrselPart(origMsgParts)) { return origMsgParts; } // Build the new msg parts. ImmutableList.Builder<SoyMsgPart> newMsgPartsBuilder = ImmutableList.builder(); StringBuilder currRawTextSb = new StringBuilder(); convertMsgPartsHelper( newMsgPartsBuilder, currRawTextSb, origMsgParts, /* isInPlrselPart= */ false); if (currRawTextSb.length() > 0) { newMsgPartsBuilder.add(SoyMsgRawTextPart.of(currRawTextSb.toString())); } return newMsgPartsBuilder.build(); }
currMsgParts.add(new SoyMsgRawTextPart(currRawTextPart)); currRawTextPart = null;
/** Append the raw text segment to the output stream. */ private static void writeRawText(SoyMsgRawTextPart msgPart, Appendable out) throws IOException { out.append(msgPart.getRawText()); }
currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null;
/** * 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; }
/** * 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(); }
currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null;
/** * 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(); }
@Override public void endElement(String uri, String localName, String qName) { if (qName.equals("target")) { // End 'target': Save the preceding raw text (if any). Then create a SoyMsg object from the // collected message data and add it to msgs list. if (currRawTextPart != null) { currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null; } isInMsg = false; if (!currMsgParts.isEmpty()) { msgs.add( SoyMsg.builder() .setId(currMsgId) .setLocaleString(targetLocaleString) .setParts(currMsgParts) .build()); } } }
/** * Processes a {@code SoyMsgRawTextPart} and appends the contained text to * the {@code StringBuilder} object in {@code RenderVisitor}. * @param rawTextPart The raw text part. */ private void visitPart(SoyMsgRawTextPart rawTextPart) { RenderVisitor.append(master.getCurrOutputBufForUseByAssistants(), rawTextPart.getRawText()); }
@Override public void endElement(String uri, String localName, String qName) { if (qName.equals("target")) { // End 'target': Save the preceding raw text (if any). Then create a SoyMsg object from the // collected message data and add it to msgs list. if (currRawTextPart != null) { currMsgParts.add(SoyMsgRawTextPart.of(currRawTextPart)); currRawTextPart = null; } isInMsg = false; if (!currMsgParts.isEmpty()) { msgs.add( SoyMsg.builder() .setId(currMsgId) .setLocaleString(targetLocaleString) .setParts(currMsgParts) .build()); } } }
/** * Processes a {@code SoyMsgRawTextPart} and appends the contained text to the {@code * StringBuilder} object in {@code RenderVisitor}. * * @param rawTextPart The raw text part. */ private void appendRawTextPart(SoyMsgRawTextPart rawTextPart) { RenderVisitor.append(master.getCurrOutputBufForUseByAssistants(), rawTextPart.getRawText()); } }
/** * 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(); }
msgStrSb.append(((SoyMsgRawTextPart) msgPart).getRawText());