翻译文本部分,包括 HTML
翻译大量文本/网页(包括 HTML)时,方法是最有效的吗?我想翻译文本,但保留 HTML。
另外,我应该将这些单词保存在数据库还是数组中?
method is the most efficient when translating bunches of text/web pages including HTML? I want to translate the text, but keep the HTML.
Also, should I keep the words in a database or an array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您说“翻译”时,您是指从一种语言翻译成另一种语言吗?如果是这样,您可以使用正则表达式来捕获 HTML 的开始标记和结束标记之间的数据,而不会丢失标记。但是,我不确定为什么您要将数据存储在数据库中,除非您稍后要检索它?
如果这是为了动态翻译,那么将数据存储在内存中总是会更快 - 您的数组或只需在循环数据时更新 HTML 并消除对数组的需要共。
When you say "translating", do you mean from one language to another? If so, you can use regular expressions to capture the data between open and closing tags of your HTML without losing the markup. I'm not sure however why you would want to store your data in a database, unless you were going to retrieve it at a later point?
If this is for a translation on the fly, it will always be faster to store your data in memory -- your Array or simply update the HTML while you loop through the data and eliminate the need for an Array altogether.