In Drupal 7, I have a block that shows recent posts which created with views.

I want it to show the translated posts of each language when I click the language switcher to switch the language.

I have two language prefixes (url code):
'en' and 'fa'

I set in a contexual filter of that block view to show just the nodes of the specific language by raw value from url set to 1, but it considers the next value of language code as the first parameter.

What should I do to make Drupal consider the language code as the first value?

3 Answers 3


In Views with i18n there is also a filter available for that matter:

Content: Language

You can set this to 'Current user's language' in order to filter your content based on the selected language.


You can have access to the prefix code of the current language as:

global $language;
$prefix_code = $language->prefix;

I made it with that function (in your "Content: language" contextual filter -> provide default value -> PhP code) :

$uri = explode('/', request_uri());
switch($uri[1]) {
    case 'en':
        return 'en';
    default :
        return 'fr';

Obviously, adapt it your languages ; for my part, french is the default (no prefix) state and english is my only other language.

  • Why not using the global $language->language ?
    – rreiss
    Aug 21, 2013 at 15:32
  • global $language is the recommanded way indeed. Aug 22, 2013 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.