简体   繁体   English

Html + javascript处理网站中的语言

[英]Html + javascript dealing with languages in a website

I've got a website under development and it is in spanish. 我有一个正在开发的网站,它是西班牙语。 Now i want to translate it to english. 现在我想把它翻译成英文。 The website is composed of 8 pages. 该网站由8页组成。 I have added the english flag on top of the website but i was wondering how to do the integration of multiple idioms on my website. 我在网站上添加了英国国旗,但我想知道如何在我的网站上整合多个习语。 I can think of two alternatives: 我可以想到两个选择:

1.- Clone each page and translate it. 1.-克隆每一页并翻译。 After that, inside the root folder create two folders "/es/" and another "/en/". 之后,在根文件夹中创建两个文件夹“/ es /”和另一个“/ en /”。 This way, when clicking on the flag i just have to change the url from www.ejemplo.com/es/index.html to www.ejemplo.com/en/index.html. 这样,当点击标志时,我只需要将网址从www.ejemplo.com/es/index.html更改为www.ejemplo.com/en/index.html。 The problem I can see is that if later I translate the site to other idioms i have to generate new folders, more files.... On the other hand, I think this solution can be better for google position as the url is cleaner... 我可以看到的问题是,如果以后我将网站翻译成其他成语我必须生成新文件夹,更多文件....另一方面,我认为这个解决方案可以更好的谷歌位置,因为网址更清晰。 ..

2.- Add a parameter in the url: www.ejemplo.com/index.html?lang=en . 2.-在网址中添加一个参数:www.ejemplo.com/index.html?lang = en。 I would have all the text in the website in JS and I would load the text in the correct idiom after reading the url parameter. 我会在JS的网站上有所有文本,我会在阅读url参数后以正确的习惯用法加载文本。

I don't know which method is better or if there is a better method for dealing with languages... 我不知道哪种方法更好,或者是否有更好的方法来处理语言......

I must say that I am using HTML5 + CSS3 + JS (and jquery) in the frontend and node.js in the backend... 我必须说我在后端使用HTML5 + CSS3 + JS(和jquery),在后端使用node.js ...

Any help will be appreciated.. 任何帮助将不胜感激..

您可以使用navigator.language查找用户使用的语言,然后相应地加载存储在您的js中的所需语言。

Easiest way to achieve is using Google Translate 最简单的方法是使用谷歌翻译

You can see other suggestions at following question on SO: 您可以在以下问题上看到有关SO的其他建议:

Best practice multi language website 最佳实践多语言网站

Following blog also have lot of useful information 以下博客也有很多有用的信息

Creating A Multilingual Website: A Beginner's Guide 创建多语言网站:初学者指南

Hoping this information helps. 希望这些信息有所帮助。

Cheers ! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM