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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀