/** * 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(); }
/** * 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(); }
MsgPartUtils.hasPlrselPart(parts) == msg.isPlrselMsg(), "Message's plural/select status is inconsistent -- internal compiler bug."); partsMap.put(msgId, parts);
MsgPartUtils.hasPlrselPart(parts) == msg.isPlrselMsg(), "Message's plural/select status is inconsistent -- internal compiler bug."); partsMap.put(msgId, parts);
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build(); }
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build(); }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }