/** * Appends the text representation of a plural part to a StringBuilder. * @param stringBuilder The StringBuilder to append to. * @param soyMsgPluralPart The SoyMsgPluralPart to add. * @param doUseBracedPhs Whether to use braced placeholders. */ private static void appendPluralToStringBuilder( StringBuilder stringBuilder, SoyMsgPluralPart soyMsgPluralPart, boolean doUseBracedPhs) { stringBuilder.append(IcuSyntaxUtils.getPluralOpenString( soyMsgPluralPart.getPluralVarName(), soyMsgPluralPart.getOffset())); for (Pair<SoyMsgPluralCaseSpec, List<SoyMsgPart>> pluralCase : soyMsgPluralPart.getCases()) { SoyMsgPluralCaseSpec pluralCaseSpec = pluralCase.first; stringBuilder.append(IcuSyntaxUtils.getPluralCaseOpenString( pluralCaseSpec.getType() == SoyMsgPluralCaseSpec.Type.OTHER ? null : pluralCaseSpec.getExplicitValue())); appendMsgPartsToTcStringBuilder(stringBuilder, pluralCase.second, doUseBracedPhs); stringBuilder.append(IcuSyntaxUtils.getPluralCaseCloseString()); } stringBuilder.append(IcuSyntaxUtils.getPluralCloseString()); }
/** * Appends the text representation of a select part to a StringBuilder. * @param stringBuilder The StringBuilder to append to. * @param soyMsgSelectPart The SoyMsgSelectPart to add. * @param doUseBracedPhs Whether to use braced placeholders. */ private static void appendSelectToStringBuilder( StringBuilder stringBuilder, SoyMsgSelectPart soyMsgSelectPart, boolean doUseBracedPhs) { stringBuilder.append(IcuSyntaxUtils.getSelectOpenString(soyMsgSelectPart.getSelectVarName())); for (Pair<String, List<SoyMsgPart>> oneSelectCase : soyMsgSelectPart.getCases()) { stringBuilder.append(IcuSyntaxUtils.getSelectCaseOpenString(oneSelectCase.first)); appendMsgPartsToTcStringBuilder(stringBuilder, oneSelectCase.second, doUseBracedPhs); stringBuilder.append(IcuSyntaxUtils.getSelectCaseCloseString()); } stringBuilder.append(IcuSyntaxUtils.getSelectCloseString()); }
msgTextCodeSb.append(IcuSyntaxUtils.getPluralCaseOpenString( ((MsgPluralCaseNode) parentNode).getCaseNumber())); } else if (parentNode instanceof MsgPluralDefaultNode) { msgTextCodeSb.append(IcuSyntaxUtils.getPluralCaseOpenString(null)); } else if (parentNode instanceof MsgSelectCaseNode) { msgTextCodeSb.append(IcuSyntaxUtils.getSelectCaseOpenString( ((MsgSelectCaseNode) parentNode).getCaseValue())); } else if (parentNode instanceof MsgSelectDefaultNode) { msgTextCodeSb.append(IcuSyntaxUtils.getSelectCaseOpenString(null)); genGoogMsgCodeForSelectNode((MsgSelectNode) child, googMsgNode, googMsgCodeGenInfo); } else if (child instanceof MsgPluralRemainderNode) { msgTextCodeSb.append(IcuSyntaxUtils.getPluralRemainderString()); } else { String nodeStringForErrorMsg = (child instanceof CommandNode) ? msgTextCodeSb.append(IcuSyntaxUtils.getPluralCaseCloseString()); } else if (parentNode instanceof MsgSelectCaseNode || parentNode instanceof MsgSelectDefaultNode) { msgTextCodeSb.append(IcuSyntaxUtils.getSelectCaseCloseString());
/** * Private helper for visitGoogMsgNode(). * Generates code for a {@code MsgSelectNode} inside a message. * @param selectNode A node of type {@code MsgSelectNode}. * @param googMsgNode The enclosing {@code GoogMsgNode} object. * @param googMsgCodeGenInfo Data structure holding information on placeholder * names, plural variable names, and select variable names to be used * for message code generation. */ private void genGoogMsgCodeForSelectNode( MsgSelectNode selectNode, GoogMsgNode googMsgNode, GoogMsgCodeGenInfo googMsgCodeGenInfo) { String selectVarName = googMsgNode.getSelectVarName(selectNode); StringBuilder msgTextCodeSb = googMsgCodeGenInfo.msgTextCodeSb; msgTextCodeSb.append(IcuSyntaxUtils.getSelectOpenString(selectVarName)); updatePlrselVarCodeBits( googMsgCodeGenInfo, selectVarName, jsExprTranslator.translateToJsExpr( selectNode.getExpr(), null, localVarTranslations).getText()); for (CaseOrDefaultNode child : selectNode.getChildren()) { genGoogMsgCodeForChildren(child, googMsgNode, googMsgCodeGenInfo); } msgTextCodeSb.append(IcuSyntaxUtils.getSelectCloseString()); }
/** * Private helper for visitGoogMsgNode(). * Generates code for a {@code MsgPluralNode} inside a message. * @param pluralNode A node of type {@code MsgPluralNode}. * @param googMsgNode The enclosing {@code GoogMsgNode} object. * @param googMsgCodeGenInfo Data structure holding information on placeholder * names, plural variable names, and select variable names to be used * for message code generation. */ private void genGoogMsgCodeForPluralNode( MsgPluralNode pluralNode, GoogMsgNode googMsgNode, GoogMsgCodeGenInfo googMsgCodeGenInfo) { String pluralVarName = googMsgNode.getPluralVarName(pluralNode); StringBuilder msgTextCodeSb = googMsgCodeGenInfo.msgTextCodeSb; msgTextCodeSb.append(IcuSyntaxUtils.getPluralOpenString(pluralVarName, pluralNode.getOffset())); updatePlrselVarCodeBits( googMsgCodeGenInfo, pluralVarName, jsExprTranslator.translateToJsExpr( pluralNode.getExpr(), null, localVarTranslations).getText()); for (CaseOrDefaultNode child : pluralNode.getChildren()) { genGoogMsgCodeForChildren(child, googMsgNode, googMsgCodeGenInfo); } msgTextCodeSb.append(IcuSyntaxUtils.getPluralCloseString()); }
/** * Appends a list of SoyMsgParts to the passed StringBuilder. * * @param stringBuilder The StringBuilder to append to. * @param soyMsgParts The list of SoyMsgParts to add. * @param doUseBracedPhs Whether to use braced placeholders. */ private static void appendMsgPartsToTcStringBuilder( StringBuilder stringBuilder, List<SoyMsgPart> soyMsgParts, boolean doUseBracedPhs) { for (SoyMsgPart msgPart : soyMsgParts) { if (msgPart instanceof SoyMsgRawTextPart) { stringBuilder.append(((SoyMsgRawTextPart) msgPart).getRawText()); } else if (msgPart instanceof SoyMsgPlaceholderPart) { if (doUseBracedPhs) { stringBuilder.append('{'); } stringBuilder.append(((SoyMsgPlaceholderPart) msgPart).getPlaceholderName()); if (doUseBracedPhs) { stringBuilder.append('}'); } } else if (msgPart instanceof SoyMsgPluralRemainderPart) { stringBuilder.append(IcuSyntaxUtils.getPluralRemainderString()); } else if (msgPart instanceof SoyMsgPluralPart) { appendPluralToStringBuilder(stringBuilder, (SoyMsgPluralPart) msgPart, doUseBracedPhs); } else if (msgPart instanceof SoyMsgSelectPart) { appendSelectToStringBuilder(stringBuilder, (SoyMsgSelectPart) msgPart, doUseBracedPhs); } } }