php - .po 到 .mo 在 php 中的转换?

标签 php internationalization gettext

我想要一个可以将 .po(Portable Object) 转换为 .mo(Machine Object) 文件的 PHP 脚本? 是否有可用的 PHP 脚本?

             byte
              +------------------------------------------+
           0  | magic number = 0x950412de                |
              |                                          |
           4  | file format revision = 0                 |
              |                                          |
           8  | number of strings                        |  == N
              |                                          |
          12  | offset of table with original strings    |  == O
              |                                          |
          16  | offset of table with translation strings |  == T
              |                                          |
          20  | size of hashing table                    |  == S
              |                                          |
          24  | offset of hashing table                  |  == H
              |                                          |
              .                                          .
              .    (possibly more entries later)         .
              .                                          .
              |                                          |
           O  | length & offset 0th string  ----------------.
       O + 8  | length & offset 1st string  ------------------.
               ...                                    ...   | |
 O + ((N-1)*8)| length & offset (N-1)th string           |  | |
              |                                          |  | |
           T  | length & offset 0th translation  ---------------.
       T + 8  | length & offset 1st translation  -----------------.
               ...                                    ...   | | | |
 T + ((N-1)*8)| length & offset (N-1)th translation      |  | | | |
              |                                          |  | | | |
           H  | start hash table                         |  | | | |
               ...                                    ...   | | | |
   H + S * 4  | end hash table                           |  | | | |
              |                                          |  | | | |
              | NUL terminated 0th string  <----------------' | | |
              |                                          |    | | |
              | NUL terminated 1st string  <------------------' | |
              |                                          |      | |
               ...                                    ...       | |
              |                                          |      | |
              | NUL terminated 0th translation  <---------------' |
              |                                          |        |
              | NUL terminated 1st translation  <-----------------'
              |                                          |
               ...                                    ...
              |                                          |
              +------------------------------------------+

我可以根据这些信息制作一个 mo 文件吗?

最佳答案

您可以使用 exec() 运行 msgfmt或类似的。我不知道是否有仅 PHP 的方法可以做到这一点。

关于php - .po 到 .mo 在 php 中的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1181681/

相关文章:

internationalization - i18n 消息 : precedence of messages from multiple PO files

php - 如何获取当前语言环境一周的第一天? (PHP/L8N)

python - Django 用户名中的 Unicode 字符

html - 您如何处理带有标记的文本翻译?

PHP:HTML inside gettext 函数字符串

php - 在 ubuntu 16 中检查 php 版本时获取 2 个版本的 php

php - 如何使用 php 从表单插入自动填充数据

php获取 future 日期时间

php - 获取登录用户的 ID 以显示类别

python - 日期的默认格式