How to use JavaScript to change website language?

How to use JavaScript to change website language?

The best and most simple solution in my opinion is to make use of HTML lang attribute and use JavaScript to show and hide the desired language. This solution also gracefully degrades so if a site visitor has their JavaScript disabled it will still display the content. Here is my solution:

How to get current language in template in Drupal?

In Drupal 8.2 language got added to page the variables in template_preprocess_page. But in my current version 8.1 it didn’t exist so I added it with: Then in my Twig file I use { { language }}. Also I can get the language name with { { language.getName () }}.

Is the language variable available in Drupal 8.2?

After Drupal 8.2 a global variable language exists and now there’s no more need to add it first. on Drupal > 8.7.5 On Drupal version 8.2.3 the language variable is already available in Twig templates.

How to switch between two languages in jQuery?

I kept working on this and created an updated example switching between two languages Chinese and English (if you need more than two languages you would have to hide all languages and show only the one selected instead of using toggle the way I am). This code also detects if an existing cookie is already set for the language using jQuery Cookie.

How to change the language of a site user interface?

As a site owner or site collection administrator, you can use the Multiple Language User Interface (MUI) feature to offer individual users the ability to change the display language for their site user interface. What is a site user interface?

Where do I find language settings in SharePoint?

From a site page, click Settings , click Site Settings. If you don’t see Site settings, click Site information and then click View all site settings. Some pages might require you to select Site contents, and then Site settings. On the settings page, in the Site Administration section, click Language Settings.