如何在不使用PHP / Jquery重新加载页面的情况下更改语言 [英] How to change language without reloading page with PHP / Jquery

查看:80
本文介绍了如何在不使用PHP / Jquery重新加载页面的情况下更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个多语言网站。
我目前包括语言短语的相关语言文件('lange / _en.php')。
要更改语言,用户将从<选择>项目。我想要做的是在页面中更改相关短语(如果可能的话也是网址),而不刷新或提交页面。

I am working on a multilangual website right now. I am currently including the related language file ('lange/_en.php') for language phrases. To change languages users will select their language from a < select > item. The thing i want to do is changing related phrases (and urls too if possible) in the page without refreshing or submitting the page.

我记得我在这里看过类似的东西网页,但我不知道在哪里。

I remember i saw something like this in web but i have no idea where.

有关如何做到这一点的任何帮助或任何想法?

Any help or any ideas about how this thing can be done?

推荐答案

这个问题是语言更改不仅会影响页面的一小部分,而且会影响整个页面。所以真的,你有三个选择。

The issue with this is that a language change doesn't only affect a small section of the page, it affects the whole page. So really, you are left with three choices.


  1. 简单方法确实正在重新加载整页。它易于实现,易于维护,并且不需要您确保页面上当前运行的JavaScript在运行时知道新语言。

  1. The simple way which is indeed reloading the whole page. It's easy to implement, easy to maintain, and doesn't require you to make sure that JavaScript currently running on your page is aware of the new language at runtime.

复杂的方式,它通过AJAX获取所有新标记,并用重新加载的内容替换< body> 标记的内容。这将导致运行其他脚本(例如图像轮播等)的问题,这些脚本包含对元素的引用,因此您必须重新初始化在 settimeout()在你的页面上。

The complicated way which is getting all the new markup via AJAX and replacing the content of the <body> tag with the reloaded content. This will cause issues with other scripts running (such as image carousels, etc.) that holds a reference to an element so you have to reinitialize every single script that is running on settimeout() on your page.

接近不可能的方式这是一个客户端字典,选择每个相关标签,并用新语言改变其内容。这是一种痛苦的设置和维护的痛苦。您确实需要为每个特定页面量身定制的部分。同样,如果你有带字符串的脚本,你必须确保他们使用的字符串更新为新语言。

The close to impossible way which is to have a client side dictionary, selecting each relevant tag, and changing its contents with the new language. This is a pain to setup and a pain to maintain. You literally need a section tailored to each specific page. Again, if you have scripts with strings, you'll have to make sure that the strings they use are updated to the new language.

最好只是重新加载页面。它可以在没有JavaScript的情况下工作,这是一次性的交易,不会打扰用户。

You are better off simply reloading the page. It will work without JavaScript and it's a one time deal that won't bother users.

这篇关于如何在不使用PHP / Jquery重新加载页面的情况下更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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