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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。