[gnomeweb-wp: 2/5] improved method of choosing language, since it tries to guess what is the user language if none is s
- From: Vinicius Scopel Depizzol <vdepizzol src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnomeweb-wp: 2/5] improved method of choosing language, since it tries to guess what is the user language if none is s
- Date: Fri, 11 Feb 2011 02:48:54 +0000 (UTC)
commit f5895072fba319305447696faeeeede829f88d96
Author: Vinicius Depizzol <vdepizzol gmail com>
Date: Fri Feb 11 00:29:54 2011 -0200
improved method of choosing language, since it tries to guess what is the user language if none is set.
wp-content/plugins/wppo/wppo.php | 40 ++++++++++++++++++++++++++++++++++---
1 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/wp-content/plugins/wppo/wppo.php b/wp-content/plugins/wppo/wppo.php
index cd40255..489211c 100644
--- a/wp-content/plugins/wppo/wppo.php
+++ b/wp-content/plugins/wppo/wppo.php
@@ -180,17 +180,49 @@ function wppo_receive_po_file () {
}
+
+function wppo_get_lang () {
+
+ if(isset ($_REQUEST['lang'])) {
+ $lang = $_REQUEST['lang'];
+ } elseif (isset ($_SESSION['lang'])) {
+ $lang = $_SESSION['lang'];
+ } else {
+
+ $user_lang = explode (',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+ foreach($user_lang as $k => $value) {
+ $user_lang[$k] = explode(';', $value);
+ $user_lang[$k] = str_replace('-', '_', $user_lang[$k][0]);
+ }
+
+ /* FIXME
+ * Before this, we need to check if the user language exists,
+ * and if not, try the following languages.
+ */
+ $lang = $user_lang[0];
+ }
+
+ return $lang;
+
+}
+
+
/* 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'];
+ $lang = wppo_get_lang ();
+
+ if(strpos ($lang, '_') !== false) {
+ $fallback_lang = explode ('_', $lang);
+ $fallback_lang = $fallback_lang[0];
+ } else {
+ $fallback_lang = $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);
+ $wppo_cache[$post->ID] = $wpdb->get_row ("SELECT * FROM " . $wpdb->prefix . "wppo WHERE post_id = '" . $post->ID . "' AND (lang = '" . $lang . "' OR lang = '" . $fallback_lang . "')", ARRAY_A);
}
if(isset ($wppo_cache[$post->ID][$string]))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]