I would like to translate the subject (MeSH) terms displayed in the -view.xsl clause in the DSPACE instance, which I retain when switching the language. I used to use the code below (I added this to the XSLUtils.java class) to search the Babelmesh site and translate it on the fly.
public static String lookupBabelMeSH(String term, String lang) { try { URLConnection babelMeshConn = (new URL("https://babelmesh.nlm.nih.gov/mesh_trans.php?oterm=" + URLEncoder.encode(term, "UTF-8") + "&in=ENG&out=" + lang)).openConnection(); babelMeshConn.setConnectTimeout(5000); babelMeshConn.setReadTimeout(5000); BufferedReader in = new BufferedReader(new InputStreamReader(babelMeshConn.getInputStream(), "UTF-8")); String value = in.readLine(); in.close(); if (!StringUtils.isEmpty(value)) { return value; } } catch (MalformedURLException mue) { } catch (IOException ioe) { } return null; }
Then I used it in item-view.xsl as follows:
<xsl:choose> <xsl:when test="$active-locale!='en'"> <xsl:variable name="current-locale"> <xsl:if test="$active-locale='fr'"> <xsl:text>FRE</xsl:text> </xsl:if> <xsl:if test="$active-locale='zh'"> <xsl:text>CHN</xsl:text> </xsl:if> </xsl:variable> <xsl:variable name="translation"> <xsl:value-of select="util:lookupBabelMeSH(node(),$current-locale)"/> </xsl:variable> <xsl:choose> <xsl:when test="$translation=''"> <xsl:value-of select="node()"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$translation"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="node()"/> </xsl:otherwise> </xsl:choose>
Now I would like to translate the text without calling the BabelMesh site of each language switch since the limit on the number of requests. In addition, since the BabelMesh URL is hard-coded, any changes to the BabelMesh service will disrupt translation rendering. I only need to translate the terms into Chinese and French. I have translations located in the [dspace]/config/mesh directory. Files are called mterms_fr and mterms_zh for French and Chinese translations, respectively.
The contents of these files looked like this:
mterms_fr
Acanthocheilonemiasis::acanthocheilonemiase Acanthocytes::ACANTHOCYTE Acantholysis::ACANTHOLYSE Acanthoma::ACANTHOME Acanthopodina::ACANTHOPODINA Acanthosis Nigricans::ACANTHOSIS NIGRICANS Acarbose::ACARBOSE Acari::ACARIEN Acaricides::Acaricides Acaridae::ACARIDAE Acatalasia::ACATALASIE Accelerated Idioventricular Rhythm::RYTHME IDIOVENTRICULAIRE ACCELERE Acceleration::ACCELERATION
mterms_zh
Acanthocheilonemiasis::棘唇虫病Acanthocytes::棘形红细胞Acantholysis::皮肤棘层松解Acanthoma::棘皮瘤Acanthopodina::Acanthopodina Acanthosis Nigricans::Acanthosis Nigricans Acarbose::Acarbose Acari::Acari Acaricides::Acaricides Acaridae::Acaridae Acatalasia::Acatalasia Accelerated Idioventricular Rhythm::Accelerated Idioventricular Rhythm Acceleration::加速度
If you notice, :: is the separator between English terms and translations. If there is no translation for this term, the English term is retained (e.g. Acaricides ).
So it would be possible only to search for these files from the [dspace]/config/mesh directory and do the translation on the fly?
EDIT
I would like to add that if this term is never found in the translation file, it should be returned as is (for example, some random text should return some random text ), since it is expected that I can not control which users will be entered in the subject field (i.e. through batch import).
Thanks in advance!