Translating Ontomasticon

Ontomasticon is a simple, lightweight ontology and glossary server written in PHP and making use of MariaDB or MySQL.

Ontomasticon is simple to customise using a mixture of CSS and PHP templates.

Translating the interface

The user interface can be translated by creating a 'language pack' in the lang folder, the jibberish language pack is provided as an example and basis for user translations. Please consider submitting a pull request on GitHub for new language pack files.

A language pack is named after its language code, such as lang/fr.php, and defines a function named lang_ followed by the code, which returns the translations. A hyphen in the code becomes an underscore in the function's name, so lang/pt-BR.php defines lang_pt_BR().

Choosing the language

A site is offered in its default language, and in the languages listed under Other languages on the site configuration page (language codes separated by spaces, such as fr pt-BR). Pages are shown in the one of these that the visitor's browser prefers, from its language settings. A browser that prefers a language with a region, such as en-GB, gets the language without it, such as en, and the other way round. Browsers that prefer none of the site's languages get the default language.

When a site is offered in more than one language, the menu has links to switch the page to each of them. A language chosen this way is used for the rest of the visit. Adding ?lang= and a language code to a page's address also shows it in that language, for example [base_url]/?lang=fr.

Translating user content

Content entered by users, such as the site's settings, vocabularies and terms, is not translated by language packs. Only the site name and site description can be given in more than one language. Each term is recorded in a single language.

Site name and description

When a page is shown in a language other than the site's default language (set on the site configuration page, see Administering Ontomasticon), the site name and description are taken from rows of the config table named after the setting, followed by an underscore and the language code, if they exist.

Config keyUsed for
site_name_[language code]The page header, the browser title and the suggested citation.
description_[language code]The description on the home page (HTML can be used), and the page's description meta tag.

If there is no row for the language, the untranslated setting is used. The language code must be exactly the code the page is shown in, which is also the name of the language pack file (for example fr for lang/fr.php). See Choosing the language for how a page's language is chosen.

These rows cannot be set on the site configuration page, and must be added to the config table of the database directly. For example, for French:

INSERT INTO `config` (`key`, `value`) VALUES
  ('site_name_fr', 'Glossaire des sons'),
  ('description_fr', '<p>Un glossaire des sons des animaux.</p>');

and to change a translation later:

UPDATE `config` SET `value` = 'Glossaire' WHERE `key` = 'site_name_fr';

A key can be at most 25 characters long. Saving the site configuration page does not change or remove these rows. Other settings, such as the author and publisher, cannot be translated. The translations are not included in linked data (JSON-LD and Turtle), where the site's name and description are only given in the default language.

Controlled vocabularies

The name and description of a controlled vocabulary can only be given in one language. In linked data they are tagged with the site's default language.

Terms in other languages

Each term has one name, one description and one language, set in the term's Language field (see Editing vocabularies and terms). The language is shown in the term's entry. Use a language tag such as fr or pt-BR: the field holds at most 35 characters, and a term isn't saved if its language isn't a valid language tag. For example, pt_BR is refused, as it has an underscore rather than a hyphen. In linked data the term's name and description are tagged with its language. A term saved before languages were checked may still have a language that isn't a valid language tag: its name and description are then not tagged, and the linked data readiness report lists it.

A vocabulary can contain terms in several languages. Terms are not chosen by the language a page is shown in: every page lists all of its terms, whatever their language.

There is no way to give one term's name or description in several languages. Instead, a term in another language can be added as a term of its own, with its own short name (for example song_fr), and linked to the original term by giving the original's short name as its Parent.