Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建多语言网站_Javascript_Android_Html_Multilingual - Fatal编程技术网

Javascript 创建多语言网站

Javascript 创建多语言网站,javascript,android,html,multilingual,Javascript,Android,Html,Multilingual,我是一名经验丰富的Android开发人员,在我的应用程序中,我习惯于为不同语言提供多个string.xml资源文件 对于HTML5网站,有没有类似的方法来实现这个结果 我希望有不同语言的字符串,并通过标识符引用它们。您可以将所有语言存储在单独的JSON文件中。问题在于,使用Javascript时,您将在页面加载后加载语言文件,以便在添加替换之前短暂地看到原始字符串 HTML Javascript // Itentifier would be "hello" // Element would b

我是一名经验丰富的Android开发人员,在我的应用程序中,我习惯于为不同语言提供多个string.xml资源文件

对于HTML5网站,有没有类似的方法来实现这个结果


我希望有不同语言的字符串,并通过标识符引用它们。

您可以将所有语言存储在单独的JSON文件中。问题在于,使用Javascript时,您将在页面加载后加载语言文件,以便在添加替换之前短暂地看到原始字符串

HTML

Javascript

// Itentifier would be "hello" 
// Element would be the actual element
// json would be the contents of the JSON file
element.text = json[identifier]

更好的方法是使用服务器端语言,如PHP,这样在将内容输出到浏览器之前就可以替换内容。

如果您编写大量jQuery(class
shouldtranslate
)并使用JSON,这是可能的,但这不是一种好的做法,因为用户可以禁用JavaScript,而JavaScript不会正常降级,更不用说,这意味着为每种语言加载一次站点和布局。我认为使用PHP会更好。
{
    "hello": "bonjeur"
}
// Itentifier would be "hello" 
// Element would be the actual element
// json would be the contents of the JSON file
element.text = json[identifier]