问题
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.
<dim:field element="relation" qualifier="hasversion" language="en"
mdschema="dc">http://hdl.handle.net/10862/152</dim:field>
My xsl template 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 template above, it is just displaying the text en
. What I want to achieve is to display the appropriate labels for the assigned language (eg. English for en, 日本語 for ja) just like in the language switcher if we enabled the webui.supported.locales
. I've read in dspace-tech here that DSpace doesn't know them.
Thanks in advance.
回答1:
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);
来源:https://stackoverflow.com/questions/31593065/how-to-display-appropriate-language-labels-for-items-that-have-non-english-versi