/** * Returns a SoyMsgBundle containing all messages extracted from the given nodes (locale string is * null). */ public SoyMsgBundle execOnMultipleNodes(Iterable<? extends SoyNode> nodes) { msgs = Lists.newArrayList(); for (SoyNode node : nodes) { visit(node); } Collections.sort(msgs, SOURCE_LOCATION_ORDERING); return new SoyMsgBundleImpl(null, msgs); }
existingMsg .toBuilder() .setDesc(existingMsg.getDesc() + extractAttributes(msg)) .addAllSourceLocations(msg.getSourceLocations()); tempMsgMap.put(msgId, mergedMessage.build());
/** * Returns a SoyMsgBundle containing all messages extracted from the given SoyFileSetNode or * SoyFileNode (locale string is null). */ @Override public SoyMsgBundle exec(SoyNode node) { Preconditions.checkArgument(node instanceof SoyFileSetNode || node instanceof SoyFileNode); msgs = Lists.newArrayList(); visit(node); Collections.sort(msgs, SOURCE_LOCATION_ORDERING); return new SoyMsgBundleImpl(null, msgs); }
/** * Returns a SoyMsgBundle containing all messages extracted from the given nodes (locale string is * null). */ public SoyMsgBundle execOnMultipleNodes(Iterable<? extends SoyNode> nodes) { msgs = Lists.newArrayList(); for (SoyNode node : nodes) { visit(node); } Collections.sort(msgs, SOURCE_LOCATION_ORDERING); return new SoyMsgBundleImpl(null, msgs); }
/** * Returns a SoyMsgBundle containing all messages extracted from the given SoyFileSetNode or * SoyFileNode (locale string is null). */ @Override public SoyMsgBundle exec(SoyNode node) { Preconditions.checkArgument(node instanceof SoyFileSetNode || node instanceof SoyFileNode); msgs = Lists.newArrayList(); visit(node); Collections.sort(msgs, SOURCE_LOCATION_ORDERING); return new SoyMsgBundleImpl(null, msgs); }
/** * Returns a SoyMsgBundle containing all the extracted messages (locale string is null). */ @Override public SoyMsgBundle exec(SoyNode node) { msgs = Lists.newArrayList(); currentSource = null; visit(node); return new SoyMsgBundleImpl(null, msgs); }
/** * Merge msg bundles together, creating new MsgBundle with merges msg bundles passed in as a method argument */ private Optional<? extends SoyMsgBundle> mergeMsgBundles(final Locale locale, final List<SoyMsgBundle> soyMsgBundles) { if (soyMsgBundles.isEmpty()) { return Optional.absent(); } final List<SoyMsg> msgs = Lists.newArrayList(); for (final SoyMsgBundle smb : soyMsgBundles) { for (final Iterator<SoyMsg> it = smb.iterator(); it.hasNext();) { msgs.add(it.next()); } } return Optional.of(new SoyMsgBundleImpl(locale.toString(), msgs)); }
/** * Take a list of SoyMsgBundles and merge. This is a little hacky but to make life easier we'll use an * internal/restricted class: SoyMsgBundleImpl. * * @param soyMsgBundles * A list of SoyMsgBundles to merge. * @return a merged set of messages. */ public static SoyMsgBundle mergeMsgBundles(List<SoyMsgBundle> soyMsgBundles) { Preconditions.checkArgument(soyMsgBundles != null && soyMsgBundles.size() > 0, "No MsgBundels defined"); String localString = ""; List<SoyMsg> msgs = Lists.newArrayList(); for (SoyMsgBundle smb : soyMsgBundles) { localString = smb.getLocaleString(); Iterator<SoyMsg> iter = smb.iterator(); while (iter.hasNext()) { msgs.add(iter.next()); } } return new SoyMsgBundleImpl(localString, msgs); }
/** * Parses the content of a translated XLIFF file and creates a SoyMsgBundle. * * @param xliffContent The XLIFF content to parse. * @return The resulting SoyMsgBundle. * @throws SAXException If there's an error parsing the data. * @throws SoyMsgException If there's an error in parsing the data. */ static SoyMsgBundle parseXliffTargetMsgs(String xliffContent) throws SAXException { // Get a SAX parser. SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser saxParser; try { saxParser = saxParserFactory.newSAXParser(); } catch (ParserConfigurationException pce) { throw new AssertionError("Could not get SAX parser for XML."); } // Construct the handler for SAX parsing. XliffSaxHandler xliffSaxHandler = new XliffSaxHandler(); // Parse the XLIFF content. try { saxParser.parse(new InputSource(new StringReader(xliffContent)), xliffSaxHandler); } catch (IOException e) { throw new AssertionError("Should not fail in reading a string."); } // Build a SoyMsgBundle from the parsed data (stored in xliffSaxHandler). return new SoyMsgBundleImpl(xliffSaxHandler.getTargetLocaleString(), xliffSaxHandler.getMsgs()); }
/** * Parses the content of a translated XLIFF file and creates a SoyMsgBundle. * * @param xliffContent The XLIFF content to parse. * @return The resulting SoyMsgBundle. * @throws SAXException If there's an error parsing the data. * @throws SoyMsgException If there's an error in parsing the data. */ static SoyMsgBundle parseXliffTargetMsgs(String xliffContent) throws SAXException { // Get a SAX parser. SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser saxParser; try { saxParser = saxParserFactory.newSAXParser(); } catch (ParserConfigurationException pce) { throw new AssertionError("Could not get SAX parser for XML."); } // Construct the handler for SAX parsing. XliffSaxHandler xliffSaxHandler = new XliffSaxHandler(); // Parse the XLIFF content. try { saxParser.parse(new InputSource(new StringReader(xliffContent)), xliffSaxHandler); } catch (IOException e) { throw new AssertionError("Should not fail in reading a string."); } // Build a SoyMsgBundle from the parsed data (stored in xliffSaxHandler). return new SoyMsgBundleImpl(xliffSaxHandler.getTargetLocaleString(), xliffSaxHandler.getMsgs()); }
/** * Parses the content of a translated XLIFF file and creates a SoyMsgBundle. * * @param xliffContent The XLIFF content to parse. * @return The resulting SoyMsgBundle. * @throws SAXException If there's an error parsing the data. * @throws SoyMsgException If there's an error in parsing the data. */ static SoyMsgBundle parseXliffTargetMsgs(String xliffContent) throws SAXException, SoyMsgException { // Get a SAX parser. SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser saxParser; try { saxParser = saxParserFactory.newSAXParser(); } catch (ParserConfigurationException pce) { throw new AssertionError("Could not get SAX parser for XML."); } // Construct the handler for SAX parsing. XliffSaxHandler xliffSaxHandler = new XliffSaxHandler(); // Parse the XLIFF content. try { saxParser.parse(new InputSource(new StringReader(xliffContent)), xliffSaxHandler); } catch (IOException e) { throw new AssertionError("Should not fail in reading a string."); } // Build a SoyMsgBundle from the parsed data (stored in xliffSaxHandler). return new SoyMsgBundleImpl(xliffSaxHandler.getTargetLocaleString(), xliffSaxHandler.getMsgs()); }
return new SoyMsgBundleImpl( origTransMsgBundle.getLocaleString(), prunedTransMsgsBuilder.build());