翻译网站的简便方法 [英] Easy way to translate a website

查看:96
本文介绍了翻译网站的简便方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当静态的网站,仅使用了一些基本的PHP用法.现在,客户希望翻译该网站.我有解决方案,但是它很麻烦,我想知道其他人是如何做到的,以及标准是什么(在框架等方面).

I have a fairly static website with just a few basic PHP usage. Now the customer would like to have this website translated. I do have a solution, but it's cumbersome and I was wondering how others are doing it and what is the standard (in frameworks, etc.).

我的方式(为了便于理解,我做了一些简化):我从数据库中为每种语言生成一个PHP数组,并将该数组存储在语言文件中,例如es.php(西班牙语).

My way (I have simplified it a bit for the sake of easier understanding): I generate a PHP array for each language from the database and store this array in a language file, like es.php for Spanish.

然后我使用tr函数将HTML中的字符串转换为:
之前:<h1>Hello World</h1>
之后:<h1><?php echo tr('Hello World'); ?></h1>,为西班牙语提供<h1>Hola Mundo</h1>.

I then translate a string in HTML using a tr function like this:
Before:<h1>Hello World</h1>
After: <h1><?php echo tr('Hello World'); ?></h1> which gives <h1>Hola Mundo</h1> for Spanish.

这很麻烦且容易出错.我必须遍历每个.php文件,并将所有硬编码的字符串替换为带有echo的PHP标记.
有没有更好的办法?别人如何做?如果需要,我可以详细说明实现方式.

This is cumbersome and error prone. I have to go through each .php file and replace all the hardcoded strings with this PHP tag with echo.
Is there a better way? How are others doing it? If needed, I can elaborate on my implementation.

推荐答案

我想对您来说有点晚了,但是万一像我这样的人偶然发现了这个线程...因为我目前也遇到了同样的问题. 不幸的是,用PHP似乎没有不麻烦的方式"来做到这一点.一切似乎都涉及很多函数调用(如果您有很多文字的话).

A little late for you, I suppose but in case someone like me stumbles across this thread... Because I currently have the same problem you do. Unfortunately, there doesn't appear to be a "non-cumbersome way" to do this with PHP. Everything seems to involve lots of function-calls (if you have a lot of text).

嗯,有一种方便的方法.虽然不完全安全.在将输出缓冲区发送给用户之前对其进行操作: => http://dev-tips.com /featured/output-buffering-for-web-developers-a-beginners-guide

Well... there is ONE convenient way. Not exactly safe though. Manipulating the output buffer before it's sent to the user: => http://dev-tips.com/featured/output-buffering-for-web-developers-a-beginners-guide

因此,您可以根据所选择的语言,只定义一个填充"from-> to"数据的数组,并通过循环遍历替换缓冲区中所有可读的文本.

So you could depending on the language chosen just define an array filled with "from->to"-data and replace all the readable text in your buffer by looping through that.

但是,当然...如果您用"senden"(德语)替换"send"(英语),然后链接到"send.html",则会断开该链接.

But of course... if you e.g. replace "send" (English) with "senden" (German) and you link to a "send.html", it would break that link.

因此,如果不仅必须翻译长的,绝对唯一的字符串,而且还要翻译较短的字符串,则必须只操作用户可读的文本.也有一个解决方案-但是,这是基于JavaScript的: => http://www.isogenicengine.com/documentation/jquery-多语言站点插件/

So if one has to translate not only long, definitely unique strings but also shorter ones, one would have to manipulate only the text that is readable to the user. There is a solution for that too - however, that is JavaScript based: => http://www.isogenicengine.com/documentation/jquery-multi-language-site-plugin/

这篇关于翻译网站的简便方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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