使用JQuery的多语言静态网站 [英] Multilanguage static website with JQuery

查看:145
本文介绍了使用JQuery的多语言静态网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Python Bottle创建的网站。我有几个来自用户的要求使其成为多语言的请求,但由于它并没有在我的脑海中开始创建,所以我很难找到最简单的方法。



<我创建了一个xml文件: languages.xml

结束了这种方式:



 <?xml version =1.0encoding =UTF-8?> 
< translations>
< translation id =myidtest>
< english>英文字符串< / english>
< italian>意大利语字符串< / italian>
< / translation>
< / translations>

然后我使用这个JQuery脚本来更新内容:

 < script type =text / javascriptlanguage =javascript> 
$ b $(函数(){
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>

在用户设置上,我添加了选项以选择首选语言并将其存储在Cookie中。然后每次加载一个页面时,我都会读取这些cookie,并在JQuery代码中的 language 参数中传递语言。然后在HTML代码中,我改变了< span class =>中的每个字符串, myidtest>英文字符串< / span>



我的问题是:

我是否应该从span标签中删除英文字符串,并留下空白的span标签以减少文件大小,加载时间,并且每次我想要更新字符串时都要更新两次(在languages.xml和in HTML)?或者我应该把它们留在抓取工具或任何其他原因?

你应该把它们留在那里用于搜索引擎抓取工具。您的有机职位将受益于那里的内容。



另外,您不会通过删除默认文本赢得太多。事实上,你应该在后端进行翻译,而不是把整个压力都放在客户端。



希望这有助于。


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.

这篇关于使用JQuery的多语言静态网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆