Drupal custom query with localization (how to get user language)

I have a block that queries the database for node, however node can be translated into English / Spanish / ...

Is there a way to get the language selected by the user so that I can update the request to the type "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);
}
?>
+3
source share
1 answer

I think you can get the current user language in Drupal with this:

global $language;

$ lang_name = $ language-> language;

This should work on both Drupal 6 and Drupal 7.

Link: Drupal API docs

+6
source

Source: https://habr.com/ru/post/1792562/


All Articles