2009-07-25 98 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