更新时间:2023-02-25 18:40:04
我可以看到三种方法来做到这一点,哪种方法***(或者是否有其他方法可供选择)取决于何时以及如何需要最终的xml. :
I can see three ways to do this, which one is best (or if any of these is an alternative) depends on when and how you need the final xml:
以编程方式构造xsl
使用例如 XmlDocument 构建xsl-那么您可以使用常规的字符串资源来填写标签,并可能利用应用程序的区域性设置.
Build the xsl using for example XmlDocument - then you can use regular string resources to fill in the labels, and possibly make use of the culture settings of your application.
将翻译内容嵌入xsl
使用 <xsl:param>
告诉转换要使用哪种语言,然后在每个字符串后放置<xsl:choose>
:
<xsl:choose>
<xsl:when test="$language='en'">Contact Details</xsl:when>
<xsl:when test="$language='sv'">Kontaktuppgifter</xsl:when>
<xsl:otherwise>Unknown language <xsl:value-of select="$language"/></xsl:otherwise>
</xsl:choose>
在转换中查找翻译
将翻译内容放入其自己的translation.xml
的xml文档中:
Put the translations in an xml documents of its own translation.xml
:
<strings>
<string language="en" key="ContactDetails">Contact Details</string>
<string language="sv" key="ContactDetails">Kontaktuppgifter</string>
[...]
</strings>
然后使用以下内容加载其内容:
Then load it's contents with:
<xsl:variable name="strings" select="document('translation.xml')/strings"/>
...并通过以下方式访问它们:
...and access them with:
<xsl:value-of select="$strings/string[@key='ContactDetails' and @language=$language]"/>