3

我想要一个可以将.po(便携式对象)转换为.mo(机器对象)文件的 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 文件吗?

4

2 回答 2

4

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

于 2009-07-25T09:16:04.733 回答
2

我还没有尝试过,但看起来这个PEAR 包可能会对你有所帮助。它是无人维护的,但也许你可以成为新的维护者?

如果您可以阅读 Python,那么您可以尝试将他们的msgfmt.py脚本转换为 PHP。它只有200行左右。

于 2009-07-25T10:19:49.973 回答