@Override public int compare(SoyMsg left, SoyMsg right) { // the messages sorted by this comparator only have one source location. // messages gain extra source locations when merged together in a bundle. return Iterables.getOnlyElement(left.getSourceLocations()) .compareTo(Iterables.getOnlyElement(right.getSourceLocations())); } };
@Override public int compare(SoyMsg left, SoyMsg right) { // the messages sorted by this comparator only have one source location. // messages gain extra source locations when merged together in a bundle. return Iterables.getOnlyElement(left.getSourceLocations()) .compareTo(Iterables.getOnlyElement(right.getSourceLocations())); } };
/** * 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); }
.toBuilder() .setDesc(existingMsg.getDesc() + extractAttributes(msg)) .addAllSourceLocations(msg.getSourceLocations()); tempMsgMap.put(msgId, mergedMessage.build());
} else { throw new RuntimeException( "Xliff doesn't support plurals or genders. " + msg.getSourceLocations());
} else { throw new RuntimeException( "Xliff doesn't support plurals or genders. " + msg.getSourceLocations());
/** 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; }