简体   繁体   English

在php或mysql中翻译网站?

[英]translating a website in php or mysql?

i need to translate my site in multiple languages. 我需要用多种语言翻译我的网站。 i was thinking to use a database called language and put the translation there. 我正在考虑使用一个名为language的数据库并将翻译放在那里。

database : translation
tables:  language
column: id, english, french, german, italian, spanish

or i was thinking about a php solution like: 或者我正在考虑像以下的PHP解决方案:

english.php
french.php
german.php
italian.php
spanish.php

so you simply include the file you need. 所以你只需要包含你需要的文件。

now, i can see pros and cons for both, what i want to know is what is consider the standard in the industry to do something like this? 现在,我可以看到两者的利弊,我想知道的是业内的标准是什么才能做到这样的事情?

You can use gettext , this function is proposed for this feature, not a "standard" but fast enough. 你可以使用gettext ,这个功能是针对这个功能提出的,不是“标准”而是足够快。

The second options in the use of a PHP file with a big array (really big, for each string), this is the most common solution. 使用带有大数组的PHP文件的第二个选项(对于每个字符串来说真的很大),这是最常见的解决方案。

To the database content (the big problem here, don't forget), if all your content must have the translation, one column for each language, otherwise use a flag of language for each line on database. 对于数据库内容(这里的大问题,不要忘记),如果所有内容都必须有翻译,每种语言一列,否则在数据库上使用每行语言标记。

There is no industry standard. 没有行业标准。 I have seen (and implemented) solutions using flat files, XML, PHP code, a database, and gettext files to store the localized strings. 我已经看到(并实现)使用平面文件,XML,PHP代码,数据库和gettext文件来存储本地化字符串的解决方案。 It's a matter of what is more suitable for you . 这是一个更适合你的问题

My go-to method for PHP is simply files containing arrays of strings, for example 我的PHP的首选方法就是包含字符串数组的文件

en.php en.php

return array (
    'How are you?' => 'How are you?',
    'Goodbye' => 'Goodbye',
);

de.php de.php

return array (
    'How are you?' => 'Wie gehts?',
    'Goodbye' => 'Auf wiedersehen',
);

This can be integrated into an application with reasonable granularity (there can be many such files, eg one for each component) and control (you can easily fall back to any other language if you don't find a string) and it is also very convenient to modify without need for special tools. 这可以以合理的粒度集成到应用程序中(可以有许多这样的文件,例如每个组件一个)和控制(如果你没有找到字符串,你可以轻松地回退到任何其他语言),它也非常无需特殊工具即可轻松修改。

My favorite PHP framework ( Yii ) and a giant open source project I have worked on ( Moodle ) also use this approach. 我最喜欢的PHP框架( Yii )和我曾经使用的巨型开源项目( Moodle )也使用这种方法。

Noone of the two solutions seems great to me. 这两种解决方案中没有一个对我来说似乎很棒。 You should think in the long run when you think a solution. 从长远来看,你应该考虑一个解决方案。

What if you choose to translate your website in other languages different from those you thought as russian or chinese? 如果您选择使用与您认为俄语或中文不同的其他语言翻译您的网站,该怎么办? In the first case you have to add more and more columns, in the second you've to create more and more file. 在第一种情况下,您必须添加越来越多的列,在第二种情况下,您需要创建越来越多的文件。 Another cons is what if you translate a page in italian and spanish but not yet in french? 另一个缺点是,如果你翻译意大利语和西班牙语的页面但尚未用法语翻译?

I think that a good thing is to have a database based solution and a main language. 我认为,有一个基于数据库的解决方案和主要语言是一件好事。 Now you can do something like this: 现在你可以这样做:

  • Create a table 'page' (id, title, ...) where you'll store the page in the main language and where you'll have the info of the translated page too 创建一个表'page'(id,title,...),您将以主语言存储页面,并且您将获得翻译页面的信息。
  • Create a table 'translation' (idsource, idtranslation, language) 创建表'翻译'(idsource,idtranslation,language)
  • Everytime check the available translations and give those to the users 每次检查可用的翻译并将其提供给用户

In database localization you have four main strategies. 在数据库本地化中,您有四个主要策略。 Each has particular advantages and disadvantages. 每个都有特定的优点和缺点。 For the long term I would definitely recommend cloning. 从长远来看,我肯定会推荐克隆。 You can see the four methods at the link below: 您可以在以下链接中看到以下四种方法:

http://www.sisulizer.com/localization/software/server-desktop-database.shtml http://www.sisulizer.com/localization/software/server-desktop-database.shtml

There are two main ideas you want to be sure to be implementing. 您希望确保实施两个主要想法。 The first, be sure you are integrating some form of translation memory. 首先,请确保您正在整合某种形式的翻译记忆库。 Your language vendor should be instructing you on how to do this and probably doing it for you. 您的语言供应商应该指导您如何执行此操作并可能为您执行此操作。

The second, for each additional language you target, your data will get at least 2x more complex. 第二种,对于您定位的每种其他语言,您的数据将至少复杂2倍。 Keep this in mind as you move forward. 当你前进时,请记住这一点。 Not only your data, but your file sets, management, etc. 不仅是您的数据,还有您的文件集,管理等。

Hope that helps. 希望有所帮助。 Let me know if you have further questions. 如果您有其他问题,请与我们联系。 Russell 罗素

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

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