您如何将现有的网络应用程序转换为多语言应用程序?

2022-01-18 00:00:00 internationalization php symfony

我将从事一个项目,其中需要调整一个相当大的网络应用程序以处理多种语言.这个东西使用手工制作的 PHP 代码运行,但它非常干净.

I am going to work on a project where a fairly large web app needs to tweaked to handle several languages. The thing runs with a hand crafted PHP code but it's pretty clean.

我想知道最好的方法是什么?

I was wondering what would be the best way to do that?

  1. 我自己做一些东西,试图适应实际的架构.

  1. Making something on my own, trying to fit the actual architecture.

使用将为我管理 i18n 的框架(例如 Symfony)重写大部分内容?

Rewriting a good part of it using a framework (e.g., Symfony) that will manage i18n for me?

对于选项 1,我应该将 i18n 数据存储在哪里?*.po、xliff、纯数据库?

For option 1, where should I store the i18n data? *.po, xliff, pure DB?

我想到了一个替代方案:仅使用 Symfony 进行翻译,但将控制器设置为按原样加载网站.很快,但很脏.另一方面,它允许我们进行下一次修改,慢慢转向完整的 Symfony:这个网站确实是一个很好的候选者.

I thought about an alternative: using Symfony only for the translation, but setting the controller to load the website as it already is. Quick, but dirty. On the other hand, it allows us to make the next modification, moving slowly to full Symfony: this web site is really a good candidate for that.

但也许有一些独立的翻译引擎会比整个网络框架做得更好.有点像用火箭筒杀死苍蝇……

But maybe there are some standalone translation engines that would do the job better than an entire web framework. It's a bit like using a bazooka to kill a fly...

推荐答案

有很多方法可以解决这个问题.它们都不是最好的方法",而且它们都存在短期或长期的问题.首先要说的是,多语言网站并不容易,翻译人员和可爱的人但很难与之合作,大多数程序员仅将问题视为技术问题.在此答案的范围之外,还有另一个维度,即您是在翻译还是本地化.这涉及查看目标受众的文化习俗,然后根据该文化定制语言、风格、布局、颜色、字体等.最后,不要将机器翻译(机器翻译)用于任何严肃或需要准确的事情,并且在获得翻译人员时确保他们正在从外语翻译成他们的母语,这意味着他们理解目标语言的所有细微差别.

There are a number of ways of tackling this. None of them "the best way" and all of them with problems in the short term or the long term. The very first thing to say is that multi lingual sites are not easy, translators and lovely people but hard to work with and most programmers see the problem as a technical one only. There is also another dimension, outside the scope of this answer, as to whether you are translating or localising. This involves looking at the target audiences cultural mores and then tailoring language, style, layout, colour, typeface etc., to that culture. Finally do not use MT, Machine Translation, for anything serious or if it needs to be accurate and when acquiring translators ensure that they are translating from a foreign language into their native language which means that they understand all the nuances of the target language.

没错.解决方案.在您不想重写站点的基础上,只需克隆您拥有的站点并将副本翻译成目标语言.假设代码库是稳定的,您可以使用 VCS 来管理任何代码更改.您可以调整站点的各个部分以适应目标语言,例如法语文本平均比等效的英语文本大 30%,因此使用一个站点来提供这意味着您可能(将)遇到格式问题并需要交换一个根据语言输入和输出不同的 css 文件.这似乎是一种笨拙的方法,但是这些网站将存在多长时间?这样做的管理开销可能比其他选项要少.

Right. Solutions. On the basis that you do not want to rewrite the site then simply clone the site you have and translate the copies to the target language. Assuming the code base is stable you can use a VCS to manage any code changes. You can tweak individual parts of the site to fit the target language, for example French text is on average 30% larger than the equivalent English text so using one site to deliver this means you may (will) have formatting problems and need to swap a different css file in and out depending on the language. It might seem a clunky way to do it but then how long are the sites going to exist? The management overhead of doing it this way may well be less than other options.

不重建的第二种方式.用标签替换当前站点中的所有内容,然后将不同的语言放入文件或数据库表中,嗅探用户所需的语言(您是否有注册用户可以进行偏好设置或者您是否想要获取浏览器语言标签,或者是它将是 URL dot-com dot-fr,dot-de 做出选择),然后用目标语言替换标签.然后,您需要分别解决尺寸问题和图像问题.当 Symfony 和 Zend 等框架实现 l10n 时,此解决方案有效.

Second way without rebuilding. Replace all content in the current site with tags and then put the different language in file or db tables, sniff the users desired language (do you have registered users who can make a preference or do you want to get the browser language tag, or is it going to be URL dot-com dot-fr, dot-de that make the choice) and then replace the tags with the target language. Then you need to address the sizing issues and the image issues separately. This solution is in effect when frameworks like Symfony and Zend do to implement l10n.

然后您可以使用框架或 gettext 进行重建,并且可能有更简洁的解决方案,但请记住框架旨在解决其他问题,而不是翻译,并且翻译组件已作为部分解决方案而不是完整解决方案进入框架.

Then you could rebuild with a framework or with gettext and possibly have a cleaner solution but remember frameworks were designed to solve other problems, not translation and the translation component has come into the framework as partial solution not the full one.

所有解决方案的最大问题是持续维护.因为您不仅有一个代码库,还有多个语言库需要维护.除非你们都在一个解决方案中非常聪明和有效,否则持续的任务将很困难.

The big problem with all the solutions is ongoing maintenance. Because not only do you have a code base but also multiple language bases to maintain. Unless you all in one solution is really clever and effective then to ongoing task will be difficult.

相关文章