我用英语制作了一个网站,添加一种语言的最佳方法是什么?

发布于 2024-09-03 14:23:53 字数 97 浏览 2 评论 0原文

所以,我创建了一个大网站(不同文件中的大量文本和大量编程)。我需要添加一种语言,我该怎么办?添加第二语言并让访问者在它们之间进行选择的最快方法是什么?有什么想法吗?
谢谢。

So, I have created a big website (a lot of text in different files and a lot of programming). I need to add one more language, how should I do? What is the fastest way I can add second language and let my visitors to choose between them? Any ideas?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回眸一遍 2024-09-10 14:23:53

翻译是您从一开始就必须考虑的事情,尤其是对于动态网站。

  1. 确保您的所有消息都分成一个或多个单独的文件,以便翻译人员处理。这是一种艺术形式 - 您需要带有格式说明符的大文本块,因为不同的语言不遵循相同的名词/动词/形容词顺序。例如,制作诸如“请选择”之类的文本字符串,后跟“项目”,其中中间是数字是一个坏主意,制作字符串“请选择%d项目” - 这允许翻译人员将数字放在理想的位置地点。
  2. 您需要一个强大的翻译工具。填充字符串常量可以接受,但可用性较差。尝试使用 gettext,这是一个成熟的翻译工具。

Translation is something you have to think about from the beginning, especially with dynamic sites.

  1. Make sure all of your messages are split into a separate file or files which a translator can work on. There is an art form to this - you want large text blocks with formatting specifiers, as different languages don't follow the same noun/verb/adjective order. For instance, making text strings such as "Please choose" followed by "items" where the middle is a number is a bad idea, make the string "Please choose %d items" - this allows the translator to place the number in the ideal location.
  2. You want a strong translation tool. The fill full of string constants is acceptable, but has poor usability. Try gettext which is a mature tool for doing translations.
梨涡少年 2024-09-10 14:23:53

无论您采用哪种方法,您都需要将所有输出的字符串存储在单独的资源中。带有数组的平面文件是最快的,尽管 SQLite 数据库会更灵活。

如果您要使用数组,您基本上只需创建一些语言文件,例如 english.php:

$lang = array(
  'I am a language.' => 'I am a language.'
);

... 和 french.php:

$lang = array(
  'I am a language.' => 'Je suis une langue.'
);

然后您可以创建一个静态语言类,该类将导入适当的语言文件,并返回翻译后的语言文件基于该文件中的数组的字符串。例如:

Language::init('french');
...
echo Language::get('I am a language.'); // outputs Je suis une langue.

Regardless of your approach, you are going to need to store all of your outputted strings in a separate resource. Flat files with arrays would be the fastest, though an SQLite database would be more flexible.

If you were to use arrays, you would basically just make a few language files, such as english.php:

$lang = array(
  'I am a language.' => 'I am a language.'
);

... and french.php:

$lang = array(
  'I am a language.' => 'Je suis une langue.'
);

Then you could make a static Language class that would import the appropriate language file, and return translated strings based on the array in that file. For example:

Language::init('french');
...
echo Language::get('I am a language.'); // outputs Je suis une langue.
段念尘 2024-09-10 14:23:53

首先,您需要国际化您的整个网站,然后您需要将其本地化为您的目标语言。

这是另一种情况,唯一重要的数字是零、一和无穷大。要么支持零种语言(根本没有人机界面),要么支持一种语言(只需硬编码),要么支持任意数量的语言。添加一种语言并不比添加 10 种语言容易。

First you need to internationalize your entire web site, and then you need to localize it into your target language.

This is another case where the only numbers that matter are zero, one, and infinity. Either you support zero languages (there is no human interface at all), one language (which you just hardcode throughout), or any number of languages. Adding one more language is no easier than adding 10 more.

伪心 2024-09-10 14:23:53

您可以将 gettext 与 poedit 一起使用,请检查此 http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/

停顿的约定 2024-09-10 14:23:53

我的建议是:将内容写入单独的 xml 文件中,每种语言一个,并且根据用户的语言,您将加载您的网站,从包含所选语言的 Xml 中检索内容。

My suggestion is: write the content in separated xml files, one for each language, and depending on the language of the user, you will load your website retrieving the content from the Xml that contains the selected language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文