-5

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
2

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.)

1

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.

-3

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>
                    </ul>
                </div>
            <!-- Translate design and connection -->
                    <style type="text/css">
                     .goog-te-banner-frame.skiptranslate{display:none!important;}body{top:0px!important;}

                     .translation-links {
                         right:0px;
                         top:3px;
                         }
                     .translation-links img {
                        filter:alpha(opacity=100);
                        -moz-opacity: 1.0;
                        opacity: 1.0;
                        border:0;
                        cursor: pointer;
                        margin-right:8px;
                        height:24px;
                        width:24px;
                        }
                     .translation-links img:hover {
                        filter:alpha(opacity=30);
                        -moz-opacity: 0.30;
                        opacity: 0.30;
                        }
                     </style>



                <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>

                <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">
                    TranslateIt.init();

function triggerHtmlEvent(element, eventName)
        {
            var event;
                if(document.createEvent) {
                    event = document.createEvent('HTMLEvents');
                    event.initEvent(eventName, true, true);
                    element.dispatchEvent(event);
        }
            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)
                                {
                                    e.preventDefault();
                                    var lang = jq(this).data('lang');
                                    jq('#google_translate_element select option').each(function(){
                                    if(jq(this).text().indexOf(lang) > -1) {
                                        jq(this).parent().val(jq(this).val());
                                        var container = document.getElementById('google_translate_element');
                                        var select = container.getElementsByTagName('select')[0];
                                        triggerHtmlEvent(select, 'change');
                                    }
                                    });
                                });

                </script>

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.