douye4051 2013-11-30 20:30
浏览 37

双语网站CMS结构 - mysql,php数组,会话,效率?

I have created and manage a bilingual website. To date, I have used a session using a GET lang variable and included a lang file based on that. My lang file is a simple php array with keys of home_h1, home_p1 for example and then the text as the values.

It makes my actual pages look very clean and short, and I have had no problems maintaining it, as I can typically translate the English into Spanish myself, and just change the other lang file. (The keys are obviously the same in both files)

I don't have time to maintain this anymore. So I want to build a CMS for a translator to work with. They will be editing both languages at once hopefully. The plan is to have a database table with keys: id, description, page, paragraph_no, English, Spanish. How can I keep my current system but use the new DB table with my CMS? Can I use php to write a new php file that contains an array with the description key (must the description be the primary key?) and the English/Spanish translation, and so matches my current format?

All I would have to do is replace the new lang files in the appropriate directory. I have never written files using php so this is new to me. I am totally open to other suggestions too this is just what I thought would be fastest (And by the way I don't want to use queries to get the texts I think there are too many on my site, and I would assume an array in an included file is much faster.

-- edit --

I have been researching this on stackoverflow, and someone mentioned using the method I have just outlined, writing php files and then including them, but the answer lacked how, which is what I don't know. I am learning php on an as needed basis and stack overflow is my library, along with the php library of course. Thanks!

  • 写回答

1条回答 默认 最新

  • dtlhy0771 2013-11-30 20:54

    I wouldn’t have a PHP read and write to files, it’s inefficient and can cause all sorts of problems. What if the server crashes when half a text file is written? Your site’s broken.

    If you’re building a CMS, then you may as well go forth and use a MySQL database in anger. If you have text files containing your strings, then you can just do one mass-import of them into your database once you’ve created its structure.

    As for the database structure, I’d advise something like this:

    • A pages table, with a auto-incrementing primary key column
    • A languages table that contains the languages your site is translated into (initially being English and Spanish)
    • A pages_languages table that’s a look-up table. You would have one record per language per page. So if there are two languages, then you would have two records per page.

    The reason I’d have a look-up table is, so that your site is scalable. You may only have two languages today, but say if your site grows in popularity and you then decide you want to translate your site into additional languages (such as French and German) then all you need to do is add a record into your languages table, and then records for each page.

    As for the CMS, simply have a textarea or rich text field per language when editing a page. When you’re saving, you have two options:

    1. Delete each record in the pages_languages table for that page, and insert the new ones;
    2. Or if you want to maintain “revisions” of page content just insert the new values, and when viewing the page on the front-end just pull the latest record that matches the requested page and specified language

    Hope this helps. Let me know if you have any questions of the above, as I realise it’s quite a high-level view and I’ve just quickly written it off the cuff.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥20 powerbulider 导入excel文件,显示不完整
    • ¥20 #关于multisim绘图遇到的问题
    • ¥15 用keil调试程序保证结果进行led相关闪烁
    • ¥15 paddle训练自己的数据loss降不下去
    • ¥20 用matlab的pdetool解决以下三个问题
    • ¥15 单个福来轮的平衡与侧向滑动是如何做到的?
    • ¥15 嵌入式Linux固件,能直接告诉我crc32校验的区域在哪不,内核的校验我已经找到了,uboot没有
    • ¥20 h3c静态路要求有详细过程
    • ¥15 调制识别中输入为时频图,星座图,眼图等
    • ¥15 数据结构C++的循环、随机数问题