如何为非英语版本的项目显示适当的语言标签

2023-11-29

我有一个带有 URI 的项目http://hdl.handle.net/10862/717用我们当地的语言(有英文版本):http://hdl.handle.net/10862/152.

<dim:field element="relation" qualifier="hasversion" language="en"
mdschema="dc">http://hdl.handle.net/10862/152</dim:field>

我的 xsl 模板如下:

<xsl:template name="itemSummaryView-DIM-HASVERSION">
    <xsl:if test="dim:field[@element='relation' and @qualifier='hasversion' and descendant::text()]">
        <div class="simple-item-view-uri item-page-field-wrapper table">
            <h5><i18n:text>xmlui.dri2xhtml.METS-1.0.item-hasversion</i18n:text></h5>
            <span>
                <xsl:for-each select="dim:field[@element='relation' and @qualifier='hasversion']">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:copy-of select="./node()"/>
                        </xsl:attribute>
                        <xsl:value-of select="./@language"/>
                    </a>
                    <xsl:if test="count(following-sibling::dim:field[@element='relation' and @qualifier='hasversion']) != 0">
                        <xsl:text>; </xsl:text>
                    </xsl:if>
                </xsl:for-each>
            </span>
        </div>
    </xsl:if>
</xsl:template>

使用上面的模板,它只是显示文本en。我想要实现的是显示指定语言的适当标签(例如,英语表示 en,日本语表示 ja),就像在语言切换器中一样,如果我们启用webui.supported.locales。我读过 dspace-techhereDSpace 不认识他们。

提前致谢。


我有一个类似的用例 - 将语言代码的 iso 版本存储在 dc.language.iso 中,但使用该语言的英文名称在项目页面上显示它。

我这样做了:

<xsl:for-each select="dim:field[@element='language' and @qualifier='iso']">
    <xsl:value-of select="util:isoLanguageToDisplay(node())"/>
        <xsl:if test="count(following-sibling::dim:field[@element='language' and @qualifier='iso']) != 0">
        <xsl:text>; </xsl:text>
    </xsl:if>
</xsl:for-each>

您需要添加isoLanguageToDisplay方法引用的类util命名空间,org.dspace.app.xmlui.utils.XSLUtils(或者到不同的类/命名空间并通过相同的机制将其拉入):

public static String isoLanguageToDisplay(String iso) {
    if (StringUtils.isBlank(iso)) {
        return iso;
    }
    Locale locale;
    if (iso.contains("_")) {
        String language = iso.substring(0, iso.indexOf("_"));
        locale = new Locale(language);
    } else {
        locale = new Locale(iso);
    }
    String englishNameOfLanguage = locale.getDisplayLanguage(Locale.getDefault());
    if (!StringUtils.isBlank(englishNameOfLanguage))
    {
        if ("Maori".equals(englishNameOfLanguage)) {
            englishNameOfLanguage = "Māori";
        }
        return englishNameOfLanguage;
    }
    return iso;
}

您可以忽略其中仅修复“Māori”拼写的部分。

就您而言,听起来您想要该语言的语言名称,而不是英语。我想你只需要改变

locale.getDisplayLanguage(Locale.getDefault());

to

locale.getDisplayLanguage(locale);

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何为非英语版本的项目显示适当的语言标签 的相关文章

随机推荐