TransWikia.com

How to set the CMS language as the preferred language of the contact?

CiviCRM Asked by Xavier on February 9, 2021

There is a way to force the language of a contact created via webform:
How to set a constant value for a field in webform (eg the prefered language)?

but I’d like to do it automatically, eg if I see the form as /fr/form it will set the preferred Civi language to fr, if the visitor is on /de/form it will be in german

Is this possible with webform civicrm?

2 Answers

I think the best option is to add some jquery -> that reads the URL - parses it - and then writes to the appropriate field on the webform based on whether it finds /de/ , /fr/ or /en/

Answered by KarinG - Semper IT on February 9, 2021

This is only a partial answer - but the PHP $_SERVER global variable contain the requested language code (e.g. en_US) (See here). civicrm_option_value stores the "Languages" option group, which provides a mapping from the language code to the language option value ID.

It seems like you could parse the requested language (en and en-US must be mapped to en_US), add an API call to OptionValue.get to get the correct ID value, and set the default value for preferred language.

Note that this is slightly different from what you're requesting - a French-speaking user on an English-localised web browser will get English, not French - but the concept should be applicable.

Answered by Jon G - Megaphone Tech on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP