[gnomeweb-wp: 8/13] added initial support to receive translated po files and create translated xml versions



commit 0f6dfc2c55b118b0b245039462d4c74fe357ea00
Author: Vinicius Depizzol <vdepizzol gmail com>
Date:   Wed Jan 26 01:54:36 2011 -0200

    added initial support to receive translated po files and create translated xml versions

 wp-content/plugins/wppo/wppo.php |   41 ++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/wp-content/plugins/wppo/wppo.php b/wp-content/plugins/wppo/wppo.php
index 3321e6e..1a50f78 100644
--- a/wp-content/plugins/wppo/wppo.php
+++ b/wp-content/plugins/wppo/wppo.php
@@ -27,6 +27,7 @@ License: AGPLv3
 require_once ("wppo.genxml.php");
 
 define (PO_DIR, ABSPATH . "po/");
+define (POT_FILE, PO_DIR . "gnomesite.pot");
 
 /* Setting up where compiled po files are located and which translation
  * domain to use. */
@@ -38,14 +39,46 @@ textdomain ('gnomesite');
  * update (regenerate, actually) the pot file with all translatable
  * strings of the gnome.org website. */
 function wppo_update_pot_file ($post) {
-  $xml_file = PO_DIR . ".tmp.xml";
-  $pot_file = PO_DIR . "gnomesite.pot";
+  $xml_file = PO_DIR . "gnomesite.xml";
   file_put_contents ($xml_file, wppo_generate_po_xml ());
-  exec ("/usr/bin/xml2po -o $pot_file $xml_file");
-  unlink ($xml_file);
+  exec ("/usr/bin/xml2po -o " . POT_FILE . " $xml_file");
 }
 add_action ('post_updated', 'wppo_update_pot_file');
 
+
+/* this action will be fired when damned lies system send an updated version of
+ * a po file. This function needs to take care of creating the translated
+ * xml file and separate its content to the wordpress database */
+function wppo_receive_po_file () {
+  if ($handle = opendir (PO_DIR)) {
+    while (false !== ($po_file = readdir ($handle))) {
+    
+      /* Gets all the .po files from PO_DIR. Then it will generate a translated
+       * XML for each language.
+       */
+      if (strpos ($po_file, '.po', 1) !== false && strpos ($po_file, '.pot', 1) === false) {
+        $po_file_array = explode ('.', $po_file);
+        
+        /* Arranging the name of the translated xml to something like
+         * "gnomesite.pt-br.xml".
+         */
+        $translated_xml_file = PO_DIR . 'gnomesite.' . implode ('.', array_pop ($po_file_array)) . '.xml';
+        
+        exec ("/usr/bin/xml2po -p $po_file -o $translated_xml_file " . POT_FILE);
+        
+        $translated_xml = file_get_contents ($translated_xml_file);
+        
+        /* TODO
+         * We still don't do anything other than generating the translated XML.
+         * We have to store this in a database table, separating the posts.
+         */
+      }
+    }
+  
+  }
+
+}
+
 /* Using gettext to get the translated version of received strings */
 function wppo_get_translated_string ($content) {
   $lang = isset ($_REQUEST['lang']) ? $_REQUEST['lang'] : $_COOKIE['lang'];



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]