Answers.Body: <p>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/</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T21:19:13.017Z
Answers.LastActivityDate: 2018-08-13T21:19:13.017Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>This is only a partial answer - but the PHP <code>$_SERVER</code> global variable contain the requested language code (e.g. <code>en_US</code>) (See <a href="http://php.net/manual/en/reserved.variables.server.php" rel="nofollow">here</a>).  <code>civicrm_option_value</code> stores the "Languages" option group, which provides a mapping from the language code to the language option value ID.  </p>
  
  <p>It seems like you could parse the requested language (<code>en</code> and <code>en-US</code> must be mapped to <code>en_US</code>), add an API call to <code>OptionValue.get</code> to get the correct ID value, and set the default value for preferred language.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-25T10:00:54.960Z
Answers.Text: in my experience, the requested language is not that reliable, eg. lots are having the en software, despite having a different language. but we can easily get the drupal language in php, so that would work too
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-25T06:24:12.603Z
Answers.LastActivityDate: 2016-02-25T06:24:12.603Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>There is a way to force the language of a contact created via webform:
  <a href="https://civicrm.stackexchange.com/questions/9274/how-to-set-a-constant-value-for-a-field-in-webform-eg-the-prefered-language">How to set a constant value for a field in webform (eg the prefered language)?</a></p>
  
  <p>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</p>
  
  <p>Is this possible with webform civicrm?</p>
  
Tags: <webform-civicrm><localisation>
Title: How to set the CMS language as the preferred language of the contact?
ThreadText: # How to set the CMS language as the preferred language of the contact?
  
  (Asked by: username_0 on 2016-02-24)
  
  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)?](https://civicrm.stackexchange.com/questions/9274/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?
  
  **Tags:** webform-civicrm, localisation
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-08-13. Score: 1
  
  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/
  
  
  ---
  
  ### Answer by username_2 on 2016-02-25. Score: 1
  
  This is only a partial answer - but the PHP `$_SERVER` global variable contain the requested language code (e.g. `en_US`) (See [here](http://php.net/manual/en/reserved.variables.server.php)). `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.
  
  > **Comments:**
  > **username_0**: in my experience, the requested language is not that reliable, eg. lots are having the en software, despite having a different language. but we can easily get the drupal language in php, so that would work too  
  
  ---
  
  