2009-07-25 87 views
3

我想要一个PHP脚本,它可以将.po(便携式对象)转换为.mo(机器对象)文件? 是PHP中的任何脚本?.po到.mo转换器在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文件吗?

回答

2

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

如果您可以阅读Python,那么您可以在将their msgfmt.py脚本转换为PHP时采取刺探措施。它只有200行左右。

+0

伟大的人,其真正有用的... 谢谢你让我检查。 – coderex 2009-07-25 10:28:05

4

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

+1

我认为这应该是最好的方法,如果你想确保你做的是正确的事情。其他解决方案可能会为您带来新的错误,从而降低您的生产力。 – sorin 2009-12-12 16:59:48