1

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'
mysite.com/en
mysite.com/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?

1

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.

0

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';
        break;
    default :
        return 'fr';
        break;
}

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 '13 at 15:32
  • global $language is the recommanded way indeed. – Gregory Kapustin Aug 22 '13 at 15:16
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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