Results 1 to 1 of 1

Thread: PHP PO File Compiler for language translations

  1. #1
    Andy101's Avatar
    Andy101 is offline Code Otaku
    Join Date
    Aug 2009
    Thanked 313 Times in 240 Posts

    PHP PO File Compiler for language translations

    PO files are used on the web to provide translations from English to other languages for text used in software such as content management systems. They are text files that are easily edited by translators or by using software tools.

    But for efficient final usage by the software they may be compiled to a binary MO format. But I wanted to use a more PHP/JavaScript friendly format (rather than something suited to C or assembler), so coded this script to produce an array of the data. So by publishing it here, hopefully other developers will copy my idea for the array format to make it popular. And of course you can serialize the array to save it to a file or database.

    To enhance this further I will likely make the individual array entries into objects since this is better suited to JavaScript property checking.

    The main properties (array indexes) are:
    id (msgid): English word/phrase appearing in the source code
    cx (msgctxt): context e.g. "place name" or "item name" (optional)
    pl (msgid_plural): English plural version (optional)
    tr (msgstr): translation array of strings (the first one is singular and any following on are used for plurals depending on a number passed by the look-up function).
    Last edited by Andy101; 9 March, 2014 at 11:03 AM. Reason: The PHP formatting was all messed up

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts