xslt - How to display appropriate language labels for items that have non-english version -
i have item uri http://hdl.handle.net/10862/717 in our local language has 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' , @qualifier='hasversion' , 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' , @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' , @qualifier='hasversion']) != 0"> <xsl:text>; </xsl:text> </xsl:if> </xsl:for-each> </span> </div> </xsl:if> </xsl:template>
using template above, displaying text en
. want achieve display appropriate labels assigned language (eg. english en, 日本語 ja) in language switcher if enabled webui.supported.locales
. i've read in dspace-tech here dspace doesn't know them.
thanks in advance.
i had similar use case -- store iso version of language code in dc.language.iso show on item page using english name of language.
i did this:
<xsl:for-each select="dim:field[@element='language' , @qualifier='iso']"> <xsl:value-of select="util:isolanguagetodisplay(node())"/> <xsl:if test="count(following-sibling::dim:field[@element='language' , @qualifier='iso']) != 0"> <xsl:text>; </xsl:text> </xsl:if> </xsl:for-each>
you need add isolanguagetodisplay
method class referenced util
namespace, org.dspace.app.xmlui.utils.xslutils
(or different class/namespace , pull in via 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 bit in there fixes spelling of "māori".
in case, sounds want name of language in language, not in english. think you'd need change
locale.getdisplaylanguage(locale.getdefault());
to
locale.getdisplaylanguage(locale);
Comments
Post a Comment