How to display appropriate language labels for elements that do not have an English version

I have an element with a URI http://hdl.handle.net/10862/717 in our local language that has the English version: http://hdl.handle.net/10862/152 .

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

My xsl template is below:

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

Using the above template, it just displays the text en. What I want to achieve is to display the corresponding labels for the assigned language (for example, English for en, 日本語 for ja), as in the language switch, if we turned it on webui.supported.locales. I read in dspace-tech here that DSpace doesn't know them.

Thanks in advance.

+1
source share
1 answer

- dc.language.iso 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;
}

, "".

, , , . ,

locale.getDisplayLanguage(Locale.getDefault());

to

locale.getDisplayLanguage(locale);

+1

Source: https://habr.com/ru/post/1599790/


All Articles