How to change language from a url link in OpenCart 2

April 23, 2015 - By 
multi-language2

multi-language2

Although the built-in language selection in OpenCart close to perfect, If you need a language switcher extension for any text anywhere on the site, here are simple code to create links that direct users to the store in a specific language.

Firstly, open file in catalog/controller/module/language.php.

And add this code before line 4:

Now you may test your language in URL. If you have English and Spanish on your site and you would use:
http://yourstore.com/?lang=en (for English) or
http://yourstore.com/?lang=es (for Spanish)

  • Vincent Cap

    Hi, i can’t find the file catalog/controller/module/language.php in opc 2.0.1, seems missing on opc 2.1.0.1

    • malam

      hi, the same, i have 2.0.3.1 and i can find the file catalog/controller/module/language.php.

      • viethemes

        Hi,

        Could you send your site URL, an admin account and a FTP account to our technical support email viethemes@gmail.com so we can take a look at the problem closer?

        Best Regards,
        viethemes.

  • Alain

    Dear all, with OpenCart 2.0, you must work on the file index.php (in your website root) and place this code :

    if (isset($request->get[‘lang’]) && array_key_exists($request->get[‘lang’], $languages)) {
    $session->data[‘language’] = $request->get[‘lang’];
    }

    between line 155 and line 157

    Line 153 : foreach ($query->rows as $result) {
    Line 154 : $languages[$result[‘code’]] = $result;
    Line 155 : }

    (you add here the new code)

    Line 157 : if (isset($session->data[‘language’]) && array_key_exists($session->data[‘language’], $languages)) {
    Line 158 : $code = $session->data[‘language’];

    • Meline

      hello,please help me oc 2.0.3.1 don’t worke’d :(

      • Alain

        What is not working ?

        • Meline

          i have oc 2.0.3.1 and language code in URL dont show,please i want show lang code in my seo url

          • Meline

            i dont have $request->get[‘lang’]

      • malam

        i try this code too but still do doesn’t work

        • viethemes

          Hi @disqus_S0nVEMNUXS:disqus,

          Could you send your site URL, an admin account and a FTP account to our technical support email viethemes@gmail.com so we can take a look at the problem closer?

          Best Regards,
          viethemes.

  • Rico666

    Perfect. Done and works. And now please how do I the same thing with currency?

    • Alain

      Let me see.

  • Ninad Jadhav

    is their any solution for currency change by URL?

  • John

    Hi, I am using 2.0.2.0. when I use http://yourstore.com/?lang=en is working but when I use http://yourstore.com/product/?lang=en it just changes to index.php?route=common/home.

    Is there any way to revise the code and make it not to change to other page? Thank you very much!

    • viethemes

      Hi,

      Could you provide your site URL so I can take a look at the problem closer? Best Regards, vie.

      On Wed, 24 May at 12:02 AM

  • rlcw

    Hello,

    We’re trying to get this works on my opencart 2.2.0.0, we’ve used .htaccess to force all HTTP to HTTPS, will this overrides the /?lang=en as it’s not work ? I’ve copy and paste the command before line 4 already

    My website is https://www.prepaid.com.hk

    Thanks
    Raymond