Le 18/03/2018 à 19:35, JLuc a écrit :
Le 18/03/2018 à 19:33, JLuc a écrit :
Le 15/03/2018 à 16:29, Urs Riggenbach via spip-en a écrit :
For a project I'm working on I would like to set the language of the
page based on the users's language setting (#LANG from Auteurs Boucle).
However, SPIP normalls sets the language based on the content one is
viewing. It is also easy to set language when calling a Boucle (lang=en).
But I have custom pages without boucles and also PHP files which can't
have boucles. Still I would like to set the language on these
dynamically. Is there a function to call?
Not sure, but $forcer_lang might help you.
with $GLOBALS['forcer_lang']=true;
and
if (function_exists('changer_langue')) {
changer_langue($langue);
if ($langue != $_COOKIE['spip_lang']) {
include_spip('inc/cookie');
spip_setcookie('spip_lang', $langue);
}
}
see also the wiki
https://contrib.spip.net/Carnet-Wiki?id_rubrique=607&page=rubrique&recherche=multilinguisme
$forcer_lang=true SPIP fixe la langue du contexte sur la langue principale du site, sauf si l’utilisateur a choisi une autre langue dans le #MENU_LANG (auquel cas il renvoie vers l’URL de la page agrémenté d’un ?lang=xx ?lang=en pour la langue anglaise)
La "langue du navigateur" n’est pas prise en compte.
Fil : rien n’interdit d’utiliser un test de la langue du navigateur pour renvoyer de manière autoritaire vers la page ?lang=xx correspondant à celle-ci si l’utilisateur n’a pas de cookie de langue.
Mais ça n’est pas très utile en général pour un "site Internet" au sens "publication d’informations" ; ça peut se défendre, en revanche, pour un "service en ligne", genre application distante, comme par exemple l’espace privé de SPIP.
$forcer_lang=true et Inclusion de code (INCLURE)
Rappel : le code xxx inclus (<INCLURE(xxx)> ) fonctionne différemment selon le contexte, et donc selon les critères qui lui sont passés : <INCLURE(xxx){critères}> .
Ainsi, si le but est de conserver la langue (qui est passée dans l’URL) dans les <INCLURE>, il faut faire <INCLURE(xxx){lang}>
Utiliser $forcer_lang fera que le critère d’inclusion {lang} se rapportera à la langue de l’URL et pas à la langue de l’objet (article, rubrique, etc).
...
« the $forcer_lang customisation variable tells SPIP that it must check to see if the site visitor has a language cookie, and if they do, then to pass it as an active parameter to the corresponding page. This is what the login page for the private zone does in the SPIP standard distribution. »
Read
Choosing the navigation language - Coding with SPIP 4
Forcing the language of the visitor's choice - Coding with SPIP 4
Forcing a change in the interface language - Coding with SPIP 4
MultilinguismeEtForcerLang
JL
_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en
_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en