PHP 数组还是 MySQL 翻译?怎样做?
我想创建一个仅包含文本区域和输出文本占位符的页面。用户将文本输入到文本区域,当他们键入时(或按下输入按钮时),文本将被翻译(或更重要的是 - 被交换)。例如,我可能会写一些类似“以我诚实的观点”或“说实话”之类的内容,这会将文本转换为其缩写形式,恕我直言,TBH,我考虑过用数组来做到这一点。可以首先搜索文本中的较长字符串,即我想到有一个由四个单词短语、三个单词短语、两个单词短语和一个可以缩写的单词组成的数组,它们可以在“key”=> ; “值”形式。这会工作吗,或者 mysql 会工作得更好吗?
I would like to create a page that contains just a textarea and placeholder for the output text. The user would enter text into the textarea and while they type (or when the enter button is pressed) the text is translated (or more to the point - swapped out). For example, I might write something like "In my honest opinion", or "to be honest" and that would convert the text to its abbreviated form IMHO and TBH, I thought about doing this with arrays. The text could be searched for the longer strings first, i.e. I thought about have an array of four word phrases, three word phrases, two word ones and a single array of words that can be abbreviated, they could be in "key" => "value" form. Would this work, or would mysql work better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在寻求将全文映射为缩写文本。这应该像实际的 i18n 翻译一样工作,因此任何翻译实现都适合。
即使您不使用 Zend Framework,您也可以查看
Zend_Translate
适配器 查看其支持的适合候选者的映射解决方案。实际上,除了告诉您映射
key => 之外, value
绝对是正确的选择;如何存储地图完全取决于您。更新
这显示了一个非常简单的搜索/替换,但是替换的复杂性将取决于输入的类型和您期望的替换类型
It sounds like you're looking to map full text into abbreviated text. This should work just like actual i18n translation, so any translation implementation would suit.
Even if you don't use Zend Framework, you could look at
Zend_Translate
adapters to see their supported mapping solutions for a suitable candidate.Really though, beyond telling you that mapping that
key => value
is definitely the way to go; how you store the map is entirely up to you.Updated
This shows a really simple search/replace, but the complexity of your replacing will depend on the type of input and the type of replacement you expect