I had a website written in Chinese but works using English PHP language. I wish to translate it to Spanish, but when I try it in Google Translate, it translates the entire file to Spanish, including the English PHP language source code. How can I only translate the Chinese content inside the file?

  • 3
    Why do you send the source file to GT, not the PHP output? – fuxia Jun 13 '13 at 10:26

You need to separate the text you want to translate from the code. Google Translate can't do that for you. It simply tries to translate all of the text given to it.

(How to put your application together so that it's easier to translate the text of it into different languages is beyond the scope of this site.)

| improve this answer | |

In the box on the left type the web address or drag and drop the address on to the page.

I just did it from English to Chinese for two different websites.

| improve this answer | |

Here is the working code.

<!-- Translate flag start -->
                <div id="translateFlags">
                    <ul class="translation-links">
                      <a class="japanese" data-lang="Japanese"><img alt="Japanese" title="Japanese" src="images/flags/Ja_flag.png"></a>
                      <a class="english" data-lang="English"><img alt="English" title="English" src="images/flags/En_flag.png"></a>
                      <a class="tagalog" data-lang="Filipino"><img alt="Tagalog" title="Tagalog" src="images/flags/tl_flag.png"></a>
                      <a class="chinese" data-lang="Chinese (Traditional)"><img alt="Chinese" title="Chinese" src="images/flags/zh-TW_flag.png"></a>
                      <a class="korean" data-lang="Korean"><img alt="Korean" title="Korean" src="images/flags/ko_flag.png"></a>
            <!-- Translate design and connection -->
                    <style type="text/css">

                     .translation-links {
                     .translation-links img {
                        -moz-opacity: 1.0;
                        opacity: 1.0;
                        cursor: pointer;
                     .translation-links img:hover {
                        -moz-opacity: 0.30;
                        opacity: 0.30;

                <div id="google_translate_element" style="display:none;"></div>
                <script type="text/javascript">
                  function googleTranslateElementInit() {
                    new google.translate.TranslateElement({pageLanguage: 'ja', autoDisplay: false},     'google_translate_element'); //remove the layout

                <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
                <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

                <script type="text/javascript" src="translate-it.js"></script>
                <script type="text/javascript">

function triggerHtmlEvent(element, eventName)
            var event;
                if(document.createEvent) {
                    event = document.createEvent('HTMLEvents');
                    event.initEvent(eventName, true, true);
            else {
                event = document.createEventObject();
                event.eventType = eventName;
                element.fireEvent('on' + event.eventType, event);

                        // Flag click handler
                                       var jq = $.noConflict();
                                 jq('.translation-links a').click(function(e)
                                    var lang = jq(this).data('lang');
                                    jq('#google_translate_element select option').each(function(){
                                    if(jq(this).text().indexOf(lang) > -1) {
                                        var container = document.getElementById('google_translate_element');
                                        var select = container.getElementsByTagName('select')[0];
                                        triggerHtmlEvent(select, 'change');

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.