douxi3432 2013-06-06 23:34
浏览 31

同时使用gettext和数据库驱动的翻译

I am currently developing a website in PHP and I decided to go with gettext to manage the translations. I set up a nice Pootle server so that I can easily manage the translations and a bash script that runs with cron that extracts all of the values from the PHP files to be translated and creates the .pot translation template file.

So far, so good. However, I just remembered that part of the text of the site is stored in a database. Let's call it "products" for simplicity. I want the product description, name, and a few other fields to be translatable, but it would be great if I could have a centralized way to translate them without having to create a separate interface just to translate the database entries. Since Pootle is already set up, it would be nice to be able to use that.

I thought of two solutions:

  1. Forget using a database and use only PHP arrays
  2. Write a script that will extract all of the values from the database and generate a file that will then be scanned by the aforementioned bash script and add the values to the pot file, and another script that will run just after the bash script to re-update all of the values in the DB.

Neither of these solutions really seem to be ideal. The first one would be easy to set up and easy to use with Pootle, but I lose all flexibility that comes with using a DBMS and I would have to import the entire array every time I want to use it. Loss of functionality isn't really that bad, because I (currently) am not performing any advanced calculations on the rows, basically just SELECTs and that's it. The second one, could work, but would take significantly more planning (and coding) to set up correctly.

Are there any other ways that I'm missing that would give me the flexibility of a database, but allow me to easily translate it in a centralized place along with the rest of the site, like Pootle?

  • 写回答

1条回答 默认 最新

  • dongzang7182 2013-06-07 07:22
    关注

    You can generate pot/po files directly from the database and feed them into Pootle then. Then you would be able to use gettext functions directly on values returned from database.

    As an example, you can look at phpMyAdmin, where we use similar approach to translate structured text file.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂