[gnomeweb-wp] added initial support to replace template content with translated versions
- From: Vinicius Scopel Depizzol <vdepizzol src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnomeweb-wp] added initial support to replace template content with translated versions
- Date: Thu, 3 Feb 2011 02:11:31 +0000 (UTC)
commit 2eb596ad624dd8152807eb0b156c0b06a379769b
Author: Vinicius Depizzol <vdepizzol gmail com>
Date: Wed Feb 2 23:37:32 2011 -0200
added initial support to replace template content with translated versions
wp-content/plugins/wppo/wppo.php | 51 ++++++++++++++++++++++++++++++++
wp-content/themes/gnome-grass/news.php | 4 +-
2 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/wp-content/plugins/wppo/wppo.php b/wp-content/plugins/wppo/wppo.php
index 0c5731e..815aad2 100644
--- a/wp-content/plugins/wppo/wppo.php
+++ b/wp-content/plugins/wppo/wppo.php
@@ -29,6 +29,8 @@ require_once ("wppo.genxml.php");
define (PO_DIR, ABSPATH . "po/");
define (POT_FILE, PO_DIR . "gnomesite.pot");
+$wppo_cache = array();
+
/* Setting up where compiled po files are located and which translation
* domain to use. */
bindtextdomain ('gnomesite', PO_DIR);
@@ -166,7 +168,56 @@ function wppo_receive_po_file () {
}
}
+
+/* Get all the translated data from the current post */
+function wppo_get_translated_data ($string) {
+ global $post, $wpdb, $wppo_cache;
+
+ $lang = isset ($_REQUEST['lang']) ? $_REQUEST['lang'] : $_COOKIE['lang'];
+
+ if (!$lang)
+ return false;
+
+ if(!isset ($wppo_cache[$post->ID])) {
+ $wppo_cache[$post->ID] = $wpdb->get_row ("SELECT * FROM " . $wpdb->prefix . "wppo WHERE post_id = '" . $post->ID . "' AND lang = '" . $lang . "'", ARRAY_A);
+ }
+
+ if(isset ($wppo_cache[$post->ID][$string]))
+ return $wppo_cache[$post->ID][$string];
+ else
+ return false;
+}
+
+
+function wppo_get_the_title () {
+ global $post, $wpdb;
+
+ $title = wppo_get_translated_data ('translated_title');
+
+ if ($title != false) {
+ return $title;
+ } else {
+ return $post->post_title;
+ }
+
+}
+
+function wppo_get_the_content () {
+ global $post, $wpdb;
+
+ $content = wppo_get_translated_data ('translated_content');
+
+ if ($content != false) {
+ return $content;
+ } else {
+ return wpautop ($post->post_content);
+ }
+
+}
+
+
/* Using gettext to get the translated version of received strings */
+/* This function won't be used anymore. FIXME */
function wppo_get_translated_string ($content) {
$lang = isset ($_REQUEST['lang']) ? $_REQUEST['lang'] : $_COOKIE['lang'];
if (!$lang)
diff --git a/wp-content/themes/gnome-grass/news.php b/wp-content/themes/gnome-grass/news.php
index 85a483b..ff74c77 100644
--- a/wp-content/themes/gnome-grass/news.php
+++ b/wp-content/themes/gnome-grass/news.php
@@ -18,9 +18,9 @@ require_once("header.php"); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="news_title">
<p class="date"><?php the_date(); ?></p>
- <h1><?php the_title(); ?></h1>
+ <h1><?php echo wppo_get_the_title(); ?></h1>
</div>
- <?php the_content(); ?>
+ <?php echo wppo_get_the_content(); ?>
<?php endwhile; // End the loop. Whew. ?>
<br />
<div class="clear"></div>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]