Skip to content
Advertisement

How to translate button in menu depending on the language of the site – use JS or PHP

https://jsfiddle.net/09fqps3n/

<div class="nav-button">
        <a href="#" class="button">
          <svg 
           ...
          </svg>
          <span>Contact Us</span>
        </a>
    </div>

I have WPML translator plugin, it add to domain /language in link (for example domain.com/en, domain.com/ru and so on). I created the menu on the top of my site and it translates my ul-li list.

So

I want to translate the button “Contact Us”. What is the simpliest way how can i do it use JS or PHP. I imagine it something like this: when i have /ru – my button become to be “Связаться с нами”

Advertisement

Answer

The wpml plugin has options to change translation for individual strings. Assuming your code has

<span>Contact Us</span>

It should have been output using php like this

<span><?php echo __('Contact Us', 'text-domain')__; ?></span>

(More about text-domain later)

Then you can go to wpml menu in admin and choose “Theme and Plugin Localization” where you will see possibility to translate all plugins and themes in their different text-domains.

As for your theme, it should appear there with its text-domain name. Then you can “Scan selected themes for strings” and afterwards once you click on your theme name you will see all the strings that were found. Now translate.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement