Interactively set #LANG based on user's lang

Hello,

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?

Best wishes,

Urs

--
Urs Riggenbach
Energy - Webdesign - Consulting

Weissensteinstrasse 76
4500 Solothurn
Switzerland

+41 79 918 0663 (CH)
+358 45 872 3836 (FI)

https://ursrig.com

Important: This email is confidential and may be privileged.
If you are not the intended recipient, please delete
it and notify us immediately; you should not copy
or use it for any purpose, nor disclose its contents
to any other person. Thank you.

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.
« 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
https://programmer.spip.net/Choosing-the-navigation-language
https://programmer.spip.net/Forcing-the-language-of-the
https://programmer.spip.net/Forcing-a-change-in-the-interface
https://contrib.spip.net/MultilinguismeEtForcerLang

JL

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;

« 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
https://programmer.spip.net/Choosing-the-navigation-language
https://programmer.spip.net/Forcing-the-language-of-the
https://programmer.spip.net/Forcing-a-change-in-the-interface
https://contrib.spip.net/MultilinguismeEtForcerLang

JL

_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

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
https://programmer.spip.net/Choosing-the-navigation-language
https://programmer.spip.net/Forcing-the-language-of-the
https://programmer.spip.net/Forcing-a-change-in-the-interface
https://contrib.spip.net/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