@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof SoyMsg) { SoyMsg that = (SoyMsg) o; return ((this.localeString == null) ? (that.getLocaleString() == null) : this.localeString.equals(that.getLocaleString())) && (this.id == that.getId()) && (this.altId == that.getAltId()) && ((this.meaning == null) ? (that.getMeaning() == null) : this.meaning.equals(that.getMeaning())) && ((this.desc == null) ? (that.getDesc() == null) : this.desc.equals(that.getDesc())) && (this.hidden == that.isHidden()) && ((this.contentType == null) ? (that.getContentType() == null) : this.contentType.equals(that.getContentType())) && (this.plrselMsg == that.isPlrselMsg()) && (this.parts.equals(that.getParts())); } return false; }
@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)); } } }
/** * Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins. * However, the source paths from subsequent duplicates will be added to the source paths for the * message. * * @param localeString The language/locale string of this bundle of messages, or null if unknown. * Should only be null for bundles newly extracted from source files. Should always be set for * bundles parsed from message files/resources. * @param msgs The list of messages. List order will become the iteration order. */ public SoyMsgBundleImpl(@Nullable String localeString, List<SoyMsg> msgs) { this.localeString = localeString; this.locale = localeString == null ? null : new ULocale(localeString); this.isRtl = BidiGlobalDir.forStaticLocale(localeString) == BidiGlobalDir.RTL; // Preserve the ordering of the input. Map<Long, SoyMsg> tempMsgMap = new LinkedHashMap<>(); for (SoyMsg msg : msgs) { checkArgument(Objects.equals(msg.getLocaleString(), localeString)); long msgId = msg.getId(); SoyMsg existingMsg = tempMsgMap.get(msgId); if (existingMsg == null) { // new message id tempMsgMap.put(msgId, msg); } else { // duplicate message id for (SourceLocation source : msg.getSourceLocations()) { existingMsg.addSourceLocation(source); } } } msgMap = ImmutableMap.copyOf(tempMsgMap); }
/** * Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins. * However, the source paths from subsequent duplicates will be added to the source paths for the * message. * * @param localeString The language/locale string of this bundle of messages, or null if unknown. * Should only be null for bundles newly extracted from source files. Should always be set * for bundles parsed from message files/resources. * @param msgs The list of messages. List order will become the iteration order. */ public SoyMsgBundleImpl(@Nullable String localeString, List<SoyMsg> msgs) { this.localeString = localeString; SortedMap<Long, SoyMsg> tempMsgMap = Maps.newTreeMap(); for (SoyMsg msg : msgs) { checkArgument(Objects.equal(msg.getLocaleString(), localeString)); long msgId = msg.getId(); if (!tempMsgMap.containsKey(msgId)) { // new message id tempMsgMap.put(msgId, msg); } else { // duplicate message id SoyMsg existingMsg = tempMsgMap.get(msgId); for (String source : msg.getSourcePaths()) { existingMsg.addSourcePath(source); } } } msgMap = ImmutableMap.copyOf(tempMsgMap); }
ilb.appendLineStart("<trans-unit id=\"", Long.toString(msg.getId()), "\""); String contentType = msg.getContentType(); if (contentType != null && contentType.length() > 0) { String xliffDatatype = CONTENT_TYPE_TO_XLIFF_DATATYPE_MAP.get(contentType); for (SoyMsgPart msgPart : msg.getParts()) { if (msgPart instanceof SoyMsgRawTextPart) { String rawText = ((SoyMsgRawTextPart) msgPart).getRawText(); } else { throw new RuntimeException( "Xliff doesn't support plurals or genders. " + msg.getSourceLocations()); String desc = msg.getDesc(); if (desc != null && desc.length() > 0) { ilb.appendLine( "<note priority=\"1\" from=\"description\">", contentEscaper.escape(desc), "</note>"); String meaning = msg.getMeaning(); if (meaning != null && meaning.length() > 0) { ilb.appendLine(
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); checkArgument( msg.getAltId() < 0, "RenderOnlySoyMsgBundleImpl doesn't support alternate ID's."); long msgId = msg.getId(); checkArgument( !partsMap.containsKey(msgId), "Duplicate messages are not permitted in the render-only impl."); ImmutableList<SoyMsgPart> parts = msg.getParts(); checkArgument( MsgPartUtils.hasPlrselPart(parts) == msg.isPlrselMsg(), "Message's plural/select status is inconsistent -- internal compiler bug."); partsMap.put(msgId, parts);
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); long msgId = msg.getId(); SoyMsg.Builder mergedMessage = existingMsg .toBuilder() .setDesc(existingMsg.getDesc() + extractAttributes(msg)) .addAllSourceLocations(msg.getSourceLocations()); tempMsgMap.put(msgId, mergedMessage.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 the message parts, or an empty array if there is no such message. * * <p>This is useful for rendering only usecases when the rest of the {@link SoyMsg} doesn't * matter. The default implementation is just {@link SoyMsg#getParts} but some subclasses may have * more efficient implementations */ public ImmutableList<SoyMsgPart> getMsgParts(long msgId) { SoyMsg msg = getMsg(msgId); return msg == null ? ImmutableList.<SoyMsgPart>of() : msg.getParts(); }
List<SoyMsgPart> msgParts = soyMsg.getParts(); new PlrselMsgPartsVisitor(node, new ULocale(soyMsg.getLocaleString())) .visitPart((SoyMsgPluralPart) firstPart); new PlrselMsgPartsVisitor(node, new ULocale(soyMsg.getLocaleString())) .visitPart((SoyMsgSelectPart) firstPart);
/** * Extracts message attributes from the message description. Returns an empty {@link String} if * the description doesn't contain any message attribute. */ private String extractAttributes(SoyMsg msg) { StringBuilder attributes = new StringBuilder(); Matcher matcher = MESSAGE_ATTRIBUTE_PATTERN.matcher(msg.getDesc()); while (matcher.find()) { attributes.append(matcher.group()); } return attributes.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()); } } }
public SoyMsg build() { SoyMsg msg = new AutoValue_SoyMsg( localeString, id, altId, meaning, desc, isHidden, contentType, isPlrselMsg, parts); if (sourceLocation != null) { msg.addSourceLocation(sourceLocation); } return msg; } }
ilb.appendLineStart("<trans-unit id=\"", Long.toString(msg.getId()), "\""); String contentType = msg.getContentType(); if (contentType != null && contentType.length() > 0) { String xliffDatatype = CONTENT_TYPE_TO_XLIFF_DATATYPE_MAP.get(contentType); for (SoyMsgPart msgPart : msg.getParts()) { if (msgPart instanceof SoyMsgRawTextPart) { String rawText = ((SoyMsgRawTextPart) msgPart).getRawText(); } else { throw new RuntimeException( "Xliff doesn't support plurals or genders. " + msg.getSourceLocations()); String desc = msg.getDesc(); if (desc != null && desc.length() > 0) { ilb.appendLine( "<note priority=\"1\" from=\"description\">", contentEscaper.escape(desc), "</note>"); String meaning = msg.getMeaning(); if (meaning != null && meaning.length() > 0) { ilb.appendLine(
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); checkArgument( msg.getAltId() < 0, "RenderOnlySoyMsgBundleImpl doesn't support alternate ID's."); long msgId = msg.getId(); checkArgument( !partsMap.containsKey(msgId), "Duplicate messages are not permitted in the render-only impl."); ImmutableList<SoyMsgPart> parts = msg.getParts(); checkArgument( MsgPartUtils.hasPlrselPart(parts) == msg.isPlrselMsg(), "Message's plural/select status is inconsistent -- internal compiler bug."); partsMap.put(msgId, parts);
/** * 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 the message parts, or an empty array if there is no such message. * * <p>This is useful for rendering only usecases when the rest of the {@link SoyMsg} doesn't * matter. The default implementation is just {@link SoyMsg#getParts} but some subclasses may have * more efficient implementations */ public ImmutableList<SoyMsgPart> getMsgParts(long msgId) { SoyMsg msg = getMsg(msgId); return msg == null ? ImmutableList.<SoyMsgPart>of() : msg.getParts(); }
@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()); } } }
/** Creates a new {@link Builder} based on the current instance. */ Builder toBuilder() { Builder builder = builder() .setId(getId()) .setIsHidden(isHidden()) .setParts(getParts()) .addAllSourceLocations(getSourceLocations()) .setIsPlrselMsg(isPlrselMsg()); if (getLocaleString() != null) { builder.setLocaleString(getLocaleString()); } if (getMeaning() != null) { builder.setMeaning(getMeaning()); } if (getDesc() != null) { builder.setDesc(getDesc()); } if (getAltId() != -1) { builder.setAltId(getAltId()); } if (getContentType() != null) { builder.setContentType(getContentType()); } return builder; }