简体   繁体   English

您对非结构化 html 内容的多语言数据库模型有何想法?

[英]your idea for a multilingual database model for non-structured html content?

i code a small very specific cms in php/mysql/jquery right now.我现在在 php/mysql/jquery 中编写了一个很小的非常具体的 cms。 the project have to be in german+english - so store these informations in separate fields : title_de, title_en ..., category_de, category_en and so on.项目必须是德语+英语 - 所以将这些信息存储在单独的字段中:title_de、title_en ...、category_de、category_en 等等。 pretty easy.挺容易。

now there will be some fields for html content where i have to store a combination of unordered image + text combinations.现在将有一些用于 html 内容的字段,我必须在其中存储无序图像 + 文本组合的组合。 i do it like this right now :我现在就这样做:

<img>text<img><img>text<img><img>text<img>text<div>otherstuff</div>text<img>

so pretty random html elements no structure ...非常随机的html元素没有结构......

so a user will have to copy this structure after creating it to another text-area for another language and translate it.因此,用户必须在创建此结构后将其复制到另一种语言的另一个文本区域并进行翻译。

i dont like the idea to store the "structure" and the "double parts eg the images" twice .我不喜欢将“结构”和“双部分,例如图像”存储两次的想法。 this would work for 2 languages - but what if its 10 languages.这适用于 2 种语言 - 但如果是 10 种语言呢?

is there an logic and easy way to separate the structure and how would you model that in a database ?是否有一种逻辑和简单的方法来分离结构,您将如何在数据库中对其进行建模?

I think what your looking for is called as internationalisation and localisation.我认为您要寻找的是国际化和本地化。

For that you may not create any new column or any other tables in database.为此,您不能在数据库中创建任何新列或任何其他表。 Even you can handle with language file.即使你可以处理语言文件。 Since you told that yours is small project it will work fine.既然你说你的项目是小项目,它就可以正常工作。

You should really use any good library like https://github.com/Philipp15b/php-i18n which is having good attention in git hub.你真的应该使用任何好的库,比如https://github.com/Philipp15b/php-i18n ,它在 git hub 中受到了很好的关注。

Even I have a solution of using basic one.即使我有一个使用基本的解决方案。

NOTE : Since I wont be using any caching technique to save the languages there may be performance issues.注意:由于我不会使用任何缓存技术来保存语言,因此可能会出现性能问题。 Please note I will recommend using any good library.请注意,我会推荐使用任何好的库。 Mine is just an idea for the sake of implementation.我的只是为了实现的想法。 You can enhance based on it.您可以在此基础上进行增强。

en.php php

$language = array(
    'Hello' => 'Hello!',
    'HtmlText' => '<h1> HTML </h1>'
);

fr.php php文件

$language = array(
    'Hello' => 'Bonjor'
    'HtmlText' => '<h1> HTML </h1>'
);

In your page now you can implement the following way现在在您的页面中,您可以实现以下方式

Eg:例如:

Advice : Make sure you handle your HTML encoding while displaying.建议:确保在显示时处理 HTML 编码。

/* Validate whether $_GET['lang'] is set or not. 
Whether your havig any language of that specif or not
Then use the following way to implement
 */

URL : http://127.0.0.1/project/?lang=en

include_once $_GET['lang'].'php'

echo $language['Hello']; //Irrespective which ever language you use it will load

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

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