Ariadne is a completely multilingual system. Not only can you change the language of the user interface and edit pages in multiple languages, you can also create language specific templates or use custom language 'libraries' in more generic templates. Ariadne makes it easy to create a single site in multiple languages and allows the visitor to easily switch between languages on any page.

Storing nls specific data

One of the more striking differences between Ariadne and most other multilingual CMS systems is the way language specific data is stored. Instead of storing each data seperate for each language, all data for all languages is stored in a single object in Ariadne. If you create a page with contact information in english, french and german, all that data is stored in the same object.

Retrieving the object to display it in a template, is the same for all those languages:

<pinp>
  echo $nlsdata->name;
</pinp>

This is exactly the same as you've already been using for your normal single language website. There is also no need to specify in which language you want to display the name, Ariadne already 'knows'. The $nlsdata object is actually something like a shortcut, but instead of a shortcut to a file, it is a shortcut that points to the 'correct' section in the data of the current object.

Each set of language specific values in an object is stored inside its own section. For english that section is $data->en, for french it is $data->fr, for german it is $data->de, etc. One of the many things the Ariadne system does before it ever starts your template is to set a 'pointer' to the currently selected language section in each object when it is retrieved from the database. This shortcut is the $nlsdata variable you're already using. A simple experiment will show this, instead of the above template, try this:

<pinp>
  echo $data->en->name;
</pinp>

In a default Ariadne setup, this will show exactly the same name.

Some information is always the same, independant of which language the visitor is using. Those values are usually stored directly in $data. One of these values is the name of a person, in the pperson object. As an experiment try the following template on a pperson object:

My name is: <pinp> echo $nlsdata->firstname; </pinp><br>
Or is it: <pinp> echo $data->firstname; </pinp>?

You will see that only the second part will show the first name of the person. Since the name of someone usually doesn't change depending on the language someone else is using, it is only stored under $data, and not in any of the language sections. There is one exception: $nlsdata->name will actually show the correct name for a pperson object. This is because $data->name is a commonly used variable in templates. By copying it into each language section, you don't have to change your generic templates for the pperson class.

Switching languages

Ariadne has two configuarion settings for languages, the list of all languages which are available in a site (or a section of a site) and the default language for that site. Both these settings can be changed through the  'set language settings' link in the Windows XP interface, or the edit > layout > language menu item in the 'new' interface.

The default language is very important, Ariadne requires one language to be leading in the site and will refuse to save any object which has not at least a name in that language.

You can change the default language setting in any part of a site, thus allowing you to create entire language specific sections. First create an object (page, section, etc.) with a name in both the current default language and the new default language. Then browse to that object and change the default language to the new one. Now you can again edit the object and remove the name for the previous default language, if you so wish. If you have no need for the previous default language at all, you can finally also remove it from the list of available languages.

The list of available languages allows you to specify for which languages an editor may enter data (names, summaries, etc.) and which languages a visitor may switch to. The default list for the enire Ariadne installation is available in the ariadne.phtml configuration file. In the language configuration screen you can select which of these languages are actually used in your site.

You can switch to another language simply by creating a link to that language and clicking on it, or redirecting to it, e.g.:

<a href="<pinp> echo make_url($path, 'de'); </pinp>">Deutsch</a>

The above template will show a link to the current page in german. Creating a list of links to hardcoded languages like this is a bit cumbersome however, so you'd better make use of the language lists in Ariadne.

There are two lists of languages you can use to switch, one is the list of languages which are configured to be available, and the other is the list of languages which actually have data entered in the current object. Usually you only want to use the second list to display a language switch option, but in some cases the other may also be useful.

<ul>
<pinp>
  $config = loadConfig();
  foreach ($config->nls->list as $nls => $language) {
    </pinp>
    <li><a href="<pinp> echo make_url($path, $nls); </pinp>"><pinp>
echo $language</pinp></a></li>
    <pinp>
  }
</pinp>
</ul>

The template above shows a list of all languages which are configured. This may be usefull in an editing/management environment, where the user must be able to select a language which has no data entered yet. The list of languages which actually have data is retrieved as follows:

<ul>
<pinp>
  foreach ($data->nls as $nls => $language) {
    </pinp>
    <li><a href="<pinp> echo make_url($path, $nls); </pinp>"><pinp>
echo $language</pinp></a></li>
    <pinp>
  }
</pinp>
</ul>

Language specific templates

You've made a multilingual site and entered data in different languages, you've added a way for the visitor to switch to a different language, but there's one problem left. Your templates contain some text also, and that text simply doesn't translate itself. There are some ways to fix this problem. The easiest one is to simply create a number of templates with the same name and for the same class, but change the language setting in the template editor.

Just edit your template, change the language and translate all the text to that language. When you save it the list should now display an extra flag next to the normal white one. If you want to edit this template again, be sure to click exactly on the flag image, or otherwise you'll get the 'normal' template again.

This approach is very easy to use, but it does mean you'll need to copy a lot of html around for each language. A change in the design suddenly means editing each and every language version of the template. For that reason there's also another way to make your templates behave:

gettext and loadtext

The method gettext allows you to use the builtin language libraries of Ariadne, or you can create your own lists. Instead of writing a template like this:

<a href="<pinp> echo make_url('somewhere/'); </pinp>">Go to somewhere</a>

You write instead:

<a href="<pinp> echo make_url('somewhere/'); </pinp>"><pinp> 
echo gettext('goto_somewhere'); </pinp></a>

This won't actually show much however untill you've told Ariadne what should be displayed for 'goto_somewhere'. To do this properly, you'll need one or more language list templates like this:

mylist.html:

<pinp>
  $ARnls['goto_somewhere'] = 'Go to somewhere';
  return $ARnls;
</pinp>

Each of these templates should be defined for their specific language, as explained in the section above. Now the rewritten template becomes:

<pinp>
  loadtext($nls, 'mylist.html');
</pinp>
<a href="<pinp> echo make_url('somewhere/'); </pinp>"><pinp>
echo gettext('goto_somewhere'); </pinp></a>

In addition to your own list of text strings, you can also use the Ariadne lists used in the Ariadne user interface. Each of the language files in ariadne/lib/nls/ can be loaded for use in your own templates through the loadtext() method. E.g.:

<pinp>
  loadtext('de');
</pinp>

This will load the german list of strings for the normal Ariadne interface, or:

<pinp>
  loadtext('de', 'edit');
</pinp>

This will load the german list of strings for the wysiwyg editor.