【发布时间】:2010-11-03 04:04:43
【问题描述】:
我正在编写一个将语言字符串分隔在 xml 文件中的网站。根据语言,我包括一种或另一种。没有问题。
顺便说一下,这个网站是动态的,所以会有一个字符串,例如英文的 Hello ipalaus!,如 Bienvenido ipalaus! 等等。在这种情况下,我们有相同的单词顺序,但在某些情况下可能会是 name string、string name、string name string...
有没有办法回复sprintf() 在 PHP 中的作用?在 PHP 中我们有这个:
<?php
$name = "ipalaus";
$string = "Welcome %s";
echo sprintf($string, $name);
// OUTPUTS: Welcome ipalaus
?>
我想在我的 index.en.xml 中有一些类似的内容:
<language>
<welcome>Welcome %s</welcome>
</language>
在我的 index.xml 中,使用 PHP 生成的文件将具有:
<index>
<locale>en</locale>
<welcome>ipalaus</welcome>
</index>
并且,在 XSLT 文件中,代表 Welcome ipalaus。
实际上,在我的 XSLT 文件中,我使用它来加载语言:
<xsl:param name="language" select="document(concat('../lang/', $locale, '/index.xml'))" />
使用以下命令访问值:<xsl:value-of select="$base/language/welcome" />。
提前谢谢你!
编辑:向亚历杭德罗提出的关于他完全有效的回答的问题示例:
<index>
<video>
<author>ipalaus</author>
</video>
<video>
<author>Alejandro</author>
</video>
</index>
还有一个语言文件:
<language>
<video>
<made>This videos is made by <author/></made>
<random>Another string</random>
</video>
</language>
【问题讨论】:
-
我完全不明白。它发布了一个示例,但我正在寻找一种将其解析为大规模的方法,因此我不必为每个变量重复,因为在大规模项目中可能非常困难。请注意,必须与不同的 XML 文件混合使用。有吗?
-
@Alejandro,你没看到我能做些什么吗?提前致谢!