2011-02-16 40 views
3

我有querys某一節點的數據庫塊,但是該節點可以被翻譯成英語/西班牙語/ ...本地化Drupal的自定義查詢(如何獲得用戶語言)

有沒有一種辦法獲取用戶選擇的語言,以便我可以將查詢更新爲「AND node.language ='x'」(en/sp/..)?

<?php 
$args = explode("/",$_GET['q']); 
$result = db_query(" 
SELECT node_revisions.body AS body FROM 
{node} AS node 
INNER JOIN {node_revisions} AS node_revisions ON node.vid = node_revisions.vid 
INNER JOIN {term_node} AS term_node ON term_node.nid = node.nid 
INNER JOIN {term_data} AS term_data ON term_data.tid = term_node.tid 
WHERE term_data.name = '".$args[1]."' AND node.type = 'country_page' 
LIMIT 1 
", $user->uid); 
while($row = db_fetch_object($result)){ 
    echo($row->body); 
} 
?> 

回答

6

我認爲你可以得到用戶的當前語言的Drupal這樣的:

global $language;

$lang_name = $language->language;

這應該在兩者的Drupal 6和Drupal 7.

參考工作: Drupal API docs

+0

太棒了,謝謝! – kilrizzy 2011-02-16 15:56:47