.PO到.MO-程序转换(PHP) [英] .PO to .MO - Programmatic Conversion (PHP)

查看:74
本文介绍了.PO到.MO-程序转换(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为CMS解决方案的一部分,我正计划允许用户通过PHP用户界面生成.POT文件/.PO文件.一旦生成了这些文件(简单易用),我想允许系统自动将这些文件转换为.MO文件,以响应用户(POST)请求.

I am planning to allow users to generate .POT files/.PO files through a PHP user interface as part of CMS solution. Once these files have been generated (the easy bit) I would like to allow my system to automatically convert these files into .MO files in response to a user (POST) request.

我在SO上看到了以下问题:

I have seen the following question on SO:

.po到php中的.mo转换器?

我知道我可以使用PHP的exec()函数运行msgfmt,但是,如果我正确的话,那似乎是仅Linux的解决方案?我将如何在其他操作系统上执行此操作?如果有人愿意演示的话,一些在实践中如何执行的示例代码也将非常有用.这与我通常所做的工作完全不同!

I understand that I could run msgfmt by using PHP's exec() function, but that seems to be a Linux only solution, if I am correct? How would I do this on other operating systems? Some example code of how this may be done in practice would also be really useful, if anybody would be kind enough to demonstrate. This is quite different from the work I usually do!

目前,这只是一个概念,但我希望我遵循正确的思路.如果您对此方法还有其他想法/建议,我将很高兴听到他们的意见.背景信息如下.

This is only a concept at the moment but I hope I'm going along the right lines. If there are any additional thoughts/suggestions you have regarding this method, I'd be glad to hear them. Background information follows.

其他背景信息-不需要

我通过解析简单的模板文件来检索原始英文文本,这些模板文件只包含基本HTML和对<?php _('the gettext method'); ?>的调用.编辑/保存并解析语言条目时将解析这些模板.然后将生成.POT文件.用户现在必须手动编辑翻译(通过简单的界面,而不是直接编辑)以更新/准备所有.PO文件.完成此操作后,我将需要将它们转换为.MO文件,就像我的问题的标题一样.

I am retrieving the original English text by parsing simple template files that consist of nothing more than basic HTML and calls to <?php _('the gettext method'); ?>. These templates are parsed when edited/saved and the language entries are retrieved. The .POT file will then be generated. The user would now have to edit translations manually (through a simple interface, not directly) to update/prepare all the .PO files. Once this is done, I would need to be able to convert them to .MO files, as is the title of my question.

推荐答案

如果您要查找msgfmt,则还有PHP的仅重新实现:

There are also PHP-only reimplementations of msgfmt if that is what you are looking for:

  • php-msgfmt
  • php.mo/gh

作为替代方案,也可以使用翻译/注册网络应用程序,其

As alternative there would also be the Translate/Pootle webapp, with its php2po script, but there must also be some .mo conversion functions in it... (Ooops no, it's in Python.)

这篇关于.PO到.MO-程序转换(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆