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.

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

报告相同问题?

悬赏问题

  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 MATLAB数据处理
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)
  • ¥20 QAxWidget上显示一个word文档后,如何直接在该QAxWidget上修改和保存word文档
  • ¥15 Simulink仿真报错,请问如何解决