bodingtonclan localisation templates

Thu, May 26, 2005

Bodington templates are composed of 3 main types of localisable content:

Type 1 - Raw content: <p>Instructions for eating cakes</p>

Type 2 - Input elements: <input type=”submit” name=”ok_to_proceed” value=”OK” />

Type 3 - String literals in Facility calls: <literal type=“String”>Enter Web Site</literal>

If you have content that could be used by other entities in the system, you should put them in a Properties file under res/generic. Your new template’s localised strings should go under res/templates/NEW_TEMPLATE_NAME_LANGCODE.properties

We’ll step through the creation and localisation of a new template, cakes.html. The new template is shown below. It contains all 3 types of localisable elements and the content requiring translation is in bold:

  <html>     <head>       <!– Type 1 - raw content –>       <title>People should eat more cakes!</title>     </head>

    <body>

      <!– Type 1 - raw content –>       <p>People are not eating enough cakes</p>

      <form name=“eat_more_cakes” method=“POST” action="">         <!– Type 2 - input elements –>         <input type=“submit” name=“submit” value="I agree" />         <input type=“submit” name=“submit” value="Cancel" />       </form>

      <h2>         <call>           <target method=“loginOriginalLink”><variable name=“facility”/></target>           <parameters>             <variable name=“request”/>             <variable name=“writer”/>             <!– Type 3 - Facility string literal –>             <literal type=“String”>The system has eaten some cakes on your behalf</literal>           </parameters>         </call>       </h2>

    </body>

  </html>

</template>

In general, it’s a good idea to put all the localised files for a template under a directory of the same name as the template, under the res/templates directory in Bodington.

Create a new directory: res/templates/cakes

Create two new files: res/templates/cakes/strings_en.properties - to store the English strings res/templates/cakes/strings_gd.properties - to store the Gaelic strings

The filenames must always end in .properties as this is what the localisation system uses to find translated content. The _en and _gd postfix on the files denote the language that the file represents. The two letter language codes are defined by the ISO 639 standard. At the moment it’s not possible to specify the language variant using ISO 3166 but it’s coming.

As you can see from the bold items in the template, there are 5 strings that need to be localised. 4 that are specific to the template and the last one, which is quite useful and could be used by other templates. So, we split our content between our template’s resource files and system-wide generic files.

res/templates/cakes/strings_gd.properties: page.title=Bu choir do dhuine tuilleadh c?®icean ithe! page.explanation=Chan eil duine ag ithe c?®icean gu-le??r page.message=Tha an t-siostem air ithe c?®icean ?†s ur leth button.agree=Tha mi ag aontachadh

res/templates/generic/strings_gd.properties: button.cancel=Dubh a-mach

Now that we have our translated content, we can now modify the template to make use of Bodington’s localisation system.

<template facilityclass=“org.bodington.servlet.facilities.Facility” resources=“res.generic.strings,res.templates.cakes.strings”>

As you can see, templates can make use of multiple resource files. In this case, we’re loading the system-wide generic strings bundle as well as the template specific strings. In general, if you want to use multiple resource files for a template, you should specify them as a comma separated list. The Localiser will take care of which bundle the strings are in when you add localisation tags to the template, so you don’t have to remember where each string is.

The other point to note is you don’t add the _en, _gd or .properties parts of the resource filename. You just use the root filename, strings. The system takes care of loading the correct strings when you change the language in Bodington’s user options page.

<title>People should eat more cakes!</title> <title><localise id=“page.title” /></title>

<p>People are not eating enough cakes</p> <p><localise id=“page.explanation” /></p>

<input type=“submit” name=“submit” value=“I agree” /> <input type=“submit” name=“submit” value=“localise.button.agree” />

<input type=“submit” name=“submit” value=“Cancel” /> <input type=“submit” name=“submit” value=“localise.button.cancel” />

You’ll notice that localise.button.agree and localise.button.cancel are in two separate resoource files. The system will sort out which file each key is in, as we told it what files to load at the top of our template resources=“res.generic.strings,res.templates.cakes.strings”

<literal type=“String”>The system has eaten some cakes on your behalf</literal> <literal type=“String”><localise id=“page.message” /></literal>

That’s it. We’ve created a new template and localised it to English and Gaelic. The complete localised template is shown below.

Happy munching!

<template facilityclass=“org.bodington.servlet.facilities.Facility” resources=“res.generic.strings,res.templates.cakes.strings”>

  <html>     <head>       <!– Type 1 - raw content –>       <title><localise id=“page.title” /></title>     </head>

    <body>

      <!– Type 1 - raw content –>       <p><localise id=“page.explanation” /></p>

      <form name=“eat_more_cakes” method=“POST” action="">         <!– Type 2 - input elements –>         <input type=“submit” name=“submit” value="localise.button.agree" />         <input type=“submit” name=“submit” value="localise.button.cancel" />       </form>

      <h2>         <call>           <target method=“loginOriginalLink”><variable name=“facility”/></target>           <parameters>             <variable name=“request”/>             <variable name=“writer”/>             <!– Type 3 - Facility string literal –>             <literal type=“String”><localise id=“page.message” /></literal>           </parameters>         </call>       </h2>

    </body>

  </html>

</template>

comments powered by Disqus