简体   繁体   中英

Javascript multiple language choice

I have this code I used for my wordpress multi language website. (currently english and french).

To make the translation of a specific part in the footer I used that code :

<?php
 /*
 $lang = (ICL_LANGUAGE_CODE == 'fr') ? 'fr' : 'en';
 $newsletter = (ICL_LANGUAGE_CODE == 'fr') ? 'Infolettre' : 'Newsletter';
 $suscribe = (ICL_LANGUAGE_CODE == 'fr') ? 'Abonnez-vous à notre infolettre' : 'Suscribe to our newsletter';
 $enter = (ICL_LANGUAGE_CODE == 'fr') ? 'Entrez votre courriel' : 'Enter your email address';
 $submit = (ICL_LANGUAGE_CODE == 'fr') ? 'S\'inscrire' : 'Submit';
*/
 $about = (ICL_LANGUAGE_CODE == 'fr') ? 'À propos' : 'About Us';
 $texte = (ICL_LANGUAGE_CODE == 'fr') ? 'text.';
?>

The thing is, now I wanna make my website trilingual. I want to make it english, french and spanish.

I'm using WPML and the 3 code abbreviation used by the plugin is 'en' 'fr' 'es'

I know I must probably use like js with if and else. But I am not enough expert to do it... Is there anyone who could help me out on this one?

I am open to completely change the code I use up till now, if you have a better way to do this.

Thanks a lot!

A better approach to the problem would be:

  1. Make three array of languages(english, french and spanish). This array will store value as sentences in each of respective language and key of all value should be same in all array
  2. Then allow user to choose language
  3. Display language texts as per the language chosen by user from one of the three array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM