I have a website created with Python Bottle. I had several requests from users to make it multilanguage, but since it wasn't created at first with this in my mind, it was difficult for me to find the easiest way.

I ended up with this way:

I created an xml file: languages.xml

<?xml version="1.0" encoding="UTF-8"?>
<translations>
    <translation id="myidtest">
        <english>english string</english>
        <italian>italian string</italian>
        <french>french string</french>
    </translation>
</translations>

Then I use this JQuery script to update the content:

<script type="text/javascript" language="javascript">

$(function() {
    var language = {{language}};
    $.ajax({
        url: '/static/languages/languages.xml',
        success: function(xml) {
            $(xml).find('translation').each(function(){
                var id = $(this).attr('id');
                var text = $(this).find(language).text();
                $("." + id).html(text);
            });
        }
    });
});
</script>

On user settings, I added the option to choose the prefered language and store it in cookies. Then each time I load a page, I read the cookies and pass the language in the language parameter in JQuery code. If there isn't any cookie, I pass the english language.

Then in HTML code, I changed every string in <span class="myidtest">english string</span>

My question is:

Should I remove the english string from the span tag as well and leave blank span tags to reduce the file sizes, load time and save my time each time I want to update a string from update them twice (in languages.xml and in html)? Or should I leave them there for crawlers or for any other reason?

有帮助吗?

解决方案

You should leave them there for search engine crawlers. Your organic positions will benefit from the content being there.

Also, you will not win much by removing the default text. In fact, you should do the translations in the back end, rather than putting this whole stress on the client.

Hope this helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top