[SPIP] Proposé : Internationalising templates


Article proposé

L’article « Internationalising templates
(SPIP) » est proposé
à la publication depuis في السبت 9 أيلول (سبتمبر) 2023.

Internationalising templates

السبت 9 أيلول (سبتمبر) 2023 , بقلم


  • Creating multilingual templates
  • Using language files
  • The structure of a language file
  • Creating your own codes
  • Plugins and language files
  • See also

SPIP naturally displays interface elements (dates, button labels) in the
language chosen by the user.

Creating multilingual templates[|عودة الى


When you create a template, you can introduce new language strings for the
most common headings (such as « Site map », « Reply to this article », etc.).
As well as facilitating maintenance (when you modify a language string, all
the pages are modified), this can also be used to create sites in other
languages (and even multilingual sites where you can switch from one
language to another).

Using language files[|عودة الى


Regardless of the structure decided for the site (language sectors or not),
all you need to do is insert a « language string » like this
<:language_string:> spip will look for the translation in one of the SPIP
files or in a local_xx.php file (xx being the language code) that you have
For example, to display the much-used word « Download » in different
languages, all you have to do is insert <:bouton_telecharger:> into its
template, which can be found in the SPIP language files.

For example, we can decide that the code telechargement corresponds :
in French, to the "Télécharger " string,
in English, to the ’Download’ string,
in Spanish, the string ’Descargar’,
and so on.


If the article in question is in French, this will produce:
Télécharger (https://www.spip.net/IMG/jpg/mondocument.jpg)

if the article is in English :
Download (https://www.spip.net/IMG/jpg/mondocument.jpg)

and so on. A single template, containing a single code, displays text
translated into all the languages used on the site.

The structure of a language file[|عودة الى


A language file is stored in a lang directory.
It is structured as follows:
The language files contain the various translations of the codes you will
be using; these are PHP files, each containing an array associating the
corresponding strings in each language with the codes.

Caution :
The name of these language files must not contain the _ character
(« underscore » or « hyphen ») except to mark the separation with the code of
the language (en, fr, it,…). For example, we would create
« myperso_fr.php » and not « my_perso_fr.php ».

These files will contain, for example:

French version (lang/myperso_fr.php) :

  $GLOBALS[$GLOBALS['idx_lang']] = array(
    'telechargement' => 'Télécharger la dernière version',
    'quoideneuf' => 'Modifications récentes'

Catalan version (lang/myperso_ca.php) :

  $GLOBALS[$GLOBALS['idx_lang']] = array(
    'telechargement' => 'Descarregar la darrera versió',
    'quoideneuf' => 'Modificacions recents'

— Each line of the definition ends with a comma, except for the last line
where the comma is not required.
— Apostrophes within the string must be escaped, i.e. preceded by a
backslash. For example, the string « what’s new » should be written:
what\'s new.
— It is possible not to escape apostrophes, as long as you use
apostrophes of the « closing single inverted comma » type '.

Creating your own codes[|عودة الى


It is also possible to create your own codes, corresponding to strings you
want to add yourself.
This involves creating personal language files, based on the model of the
public_xx.php files. To create your own files, install the following in a
squelettes/lang directory (to be created if necessary)
local_fr.php to define strings in French,
local_en.php for English,

The part you have to enrich yourself consists of several lines of
definitions, based on the model:

    'code' => 'String to display',

Plugins and language files[|عودة الى


Many functions are provided by plug-ins, either core plug-ins such as Quill
or SVP, or plug-ins added by webmasters because they want to use a specific
function. All these plug-ins have language files.

See also |عودة الى الفهرس

For more information on language strings, visit


the initial versions of this article presented solutions other than
language files for making templates multilingual. Let’s just note here
that these solutions are not recommended:
one template per language" (required the
« squelettes_par_rubrique » plug-in): this is difficult to maintain and
simply useless for basic use.
multilingual blocks": these <multi> blocks are very useful in
the editorial section; they allow you to present a title in different
possible languages, display different captions for each language… but
should be avoided in the structure section.

— Envoyé par SPIP (https://www.spip.net/)