Skip to content

Multilingual sites: display of multilingual metadata

Polina Yordanova edited this page Oct 26, 2017 · 2 revisions

The practice used in the IOSPE project for encoding metadata in multiple languages is to put it in subsequent elements having the attribute xml:lang. Here's an example:

     <msContents>
       <summary corresp="document-search.xml#doc1">
         <seg xml:lang="ru">Строительная надпись.</seg>
         <seg xml:lang="en">Building inscription.</seg>
       </summary>
     </msContents>

It is generally a good practice to do so as it cuts the number of files we have to work with and allows for a better control over the translation. However, when we put the files into content/xml/epidoc and transform them using the EpiDoc XSLT the display in EFES has both languages one after the other.

In order to solve this problem we need to preprocess the EpiDoc xml files before they get transformed by the EpiDoc stylesheets. It would be useful to only transform the elements having the xml:lang attribute with the value of the language that was passed as a parameter in the url. Preprocessing is done in webapps/ROOT/sitemaps/internal.xmap. We need to change the <map:match> that processes the EpiDoc document in a language context prior to its use in another pipeline - this map:match starts at circa line 48. As it is, this map:match only generates content from the file disc and serializes it as xml. We need to add a <map:transform> that will use a stylesheet which will remove the elements with the xml:lang attribute not matching the language parameter supplied in the url. Such a stylesheet does not exist yet so we need to create one in webapps/ROOT/stylesheets/epidoc. Let's name it prune-to-language.xsl.

We begin by defining a parameter to the transformation:

    <xsl:param name="language"/>

We then need to write a template that matches on any element that has the xml:lang attribute different from the supplied language parameter:

    <xsl:template match="*[@xml:lang!=$language]"/>

Another template will make a copy of all attributes and nodes and apply

We can now include the map:transform using this xsl in the map:match in internal.xmap. Inside the <map:transform> element we need to pass the language parameter with value="{1}" as this is the first variable supplied in through the url. This is how the entire map:match should look like when we're done:

    <map:match id="local-preprocess-epidoc-language"
         pattern="epidoc/preprocess/language/*/**.xml">
      <map:generate src="../content/xml/epidoc/{2}.xml" />
      <map:transform src="../stylesheets/epidoc/prune-to-language.xsl">
        <map:parameter name="language" value="{1}" />
      </map:transform>
      <map:serialize type="xml" />
    </map:match>