Questions

Dropdown

To allow users to select their preferred language, create a language dropdown in your HTML. Here's an example:

											
	<select id="languageDropdown">
		<option data-lang-code="en" data-notranslate>English</option>
		<option data-lang-code="fr" data-notranslate>French</option>
		<option data-lang-code="es" data-notranslate>Spanish</option>
	</select>
											
										

Switch the Current Language from a Dropdown

Add JavaScript code to implement the "lzSwitchLanguage('fr')" function when the user selects a language from the dropdown. Use the selected language code as a parameter.

																			
	<script> document.getElementById('languageDropdown').addEventListener('change', function() { let selectedLanguage = this.options[this.selectedIndex].dataset.langCode; lzSwitchLanguage(selectedLanguage); }); </script>
																		

Toggle

To allow users to select their preferred language from a toggle, create a language toggle in your HTML. Here's an example:

                      
  <select id="toggle-container">
    <button id="englishBtn" class="toggle-option active">English</button>
    <button id="spanishBtn" class="toggle-option">EspaƱol</button>
  </select>
                      
                    

Here is some sample Javascript Code to switch between the languages in a Toggle:

                      
<script>
    // Initial language state (English)
    let lzCurrentLanguage = 'en';

    // Get buttons
    const englishBtn = document.getElementById('englishBtn');
    const spanishBtn = document.getElementById('spanishBtn');

    // Function to handle language toggle
    englishBtn.addEventListener('click', function() {
      if (lzCurrentLanguage !== 'en') {
        lzCurrentLanguage = 'en';
        englishBtn.classList.add('active');
        spanishBtn.classList.remove('active');
      }
    });

    spanishBtn.addEventListener('click', function() {
      if (lzCurrentLanguage !== 'es') {
        lzCurrentLanguage = 'es';
        spanishBtn.classList.add('active');
        englishBtn.classList.remove('active');
      }
    });
  </script>
                      
                    

URL Paramter

To test/force translations, add this URL Parameter:

                      
  https://www.SAMPLEURL.com?langtarget=es
                      
                    

The ?langtarget=ANY LANGUAGE CODE can be added to any URL to force a translation

lzCurrentLanguage()

This command can be run from the browser console to force a translation into a different language:

                      
  lzCurrentLangauge("es")
                      
                    

lzCurrentLanguage("ANY LANGUAGE CODE") will allow you to test translations.

Supporting Links

Languages
  • List of all possible language codes
  • Sample dropdown script with every language