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.

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



  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理