How to display appropriate language labels for items that have non-english version

前端 未结 1 720
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 04:59

I have an item with URI http://hdl.handle.net/10862/717 in our local language that has an english version: http://hdl.handle.net/10862/152.



        
相关标签:
1条回答
  • 2021-01-24 05:16

    I had a similar use case -- store the iso version of the language code in dc.language.iso but show it on the item page using the English name of the language.

    I did this:

    <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>
    

    You need to add the isoLanguageToDisplay method to the class referenced by the util namespace, org.dspace.app.xmlui.utils.XSLUtils (or to a different class/namespace and pull that in via the same mechanism):

    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;
    }
    

    You can ignore the bit in there that just fixes up the spelling of "Māori".

    In your case, it sounds like you want the name of the language in that language, not in English. I think you'd just need to change

    locale.getDisplayLanguage(Locale.getDefault());

    to

    locale.getDisplayLanguage(locale);

    0 讨论(0)
提交回复
热议问题