0

I am trying to add a the language being displayed in the html body class. Drupal 7 for example, when i open firebug it displays the body class with these values

body class=html not-front logged-in no-sidebars page-node page-node- page-node-187 node-type-page toolbar toolbar-drawer i18n-el show-grid no-rgba

Is it possibe to add the language as lang-el instead of il8n-el? Which file is it responsible for outputting these values?

1
sites/all/modules/i18n/i18n.module

Line:267:  $variables['classes_array'][] = 'i18n-' . $language->language;

You can create your own small module mysmallmodule.module and put this in it:

/**
 * Implements hook_preprocess_html().
 */
function mysmallmodule_preprocess_html(&$variables) {
  global $language;
  $variables['classes_array'][] = 'lang-' . $language->language;
}

Which wont get rid of the i18n class but will just add your own version :)

EDIT: Step by step to create a small custom module.

  1. Create a new folder in the sites/all/modules folder called custom, in here you can keep any custom modules you may need.
  2. Create another folder in the custom folder and call it something suitable like customclasses.
  3. In the customclasses folder create two files, customclasses.module and customclasses.info.
  4. In the customclasses.module file paste the code above but call it "function customclasses_preprocess_html" instead of "mysmallmodule".
  5. In the customclasses.info file paste

    name = Custom Classes

    package = Custom Stuff

    description = Custom class to get "lang-" in the body class.

    core = 7.x

  6. Finally, go to the modules page and enable your first custom module.

4
  • :) thank you so much for your quick reply. I just changed this line from Line:267: $variables['classes_array'][] = 'i18n-' . $language->language; to Line:267: $variables['classes_array'][] = 'lang-' . $language->language; and it worked. :) – paranod Jun 13 '12 at 14:51
  • Noooo, dont do that! But seriously, dont. Its really bad practice to mess with modules, and you will regret it in the future when you update that module. I will update my answer with what you need to do exactly to get the exact same effect and it will only take you 2 more minutes. Plus, if you think my answer is the right answer, you should click to accept that its the right answer. – 7wonders Jun 13 '12 at 15:05
  • ok you are right. This is bad practice. I have changed it back to il8n- and created the module as your edited comment. But insted of having the body class tag lang-en i have the code from inside my customclasses.module appeared on my screen along with the comment which is weird. – paranod Jun 14 '12 at 7:30
  • 0 down vote accept Is working thank you very much for your help:) Ignore my last comment. Forgot to add the tags. Thank you once again. – paranod Jun 14 '12 at 14:06

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.