H5P Guides

Hello world - add translations

Here we extend the Hello World tutorial with a translation to illustrate how H5P libraries may include several languages.

H5P libraries have built-in support for translation of static strings in the library semantics, such as titles, descriptions and defaults. This is done by including language files that are merged on top of the semantics object.

Let's add support for Norwegian (bokmål) to the H5P.GreetingCard library. First create the directory "greeting/H5P.GreetingCard/language", then add the file "nb.json" with the following content:

{
  "semantics": [
    {
      "label": "Velkomsttekst",
      "default": "Hallo verden!",
      "description": "Velkomstteksten som vises til sluttbruker."
    },
    {
      "label": "Bilde til kort",
      "description": "Bildet som vises på kortet. Valgfritt, uten bilde vises bare teksten."
    }
  ]
}

Only replace the strings used and leave out other fields, such as "name" and "optional". It is important not to translate the name, since this is used in code.

After translating, the editor will look as below, if the site is set to 'Norwegian Bokmål".