Drupal 7's new multilingual systems (part 6) - Blocks and the introduction of textgroups

With the basics of node and site settings translation behind us, we are getting to the more complex parts, at least in terms of the user interfaces involved. While with node translation you get a tab on each node to translate it (regardless of setting up translation sets or using translatable fields), and with settings translation, you get quick jump links, the subsystems that work with textgroups will require a better understanding of how the Drupal systems relate.

Three ways to think about language support

When people want to have language support for their site, they typically think of one of three things:

  1. Being able to mark an object as in one language. With node translation this was achieved by language enabling nodes.
  2. Being able to mark an object as in one language and relate it to others as being a translation set. For nodes, this is supported by Drupal core's content translation module.
  3. Finally, being able to translate pieces of the object that need translation and leave the rest alone. Load the right language variant of the object dynamically as needed. In the case of nodes, this is achieved with the contributed entity_translation module (formerly translation.module).

The first case is great when you don't need to translate the object, the second is great when you need to use translations in different contexts (for nodes, you can maintain a separate comment set, put in different menus, etc). The last is great when you want to maintain the object the same way regardless of language. This might be great for an e-commerce site. Read part 4 of my blog post series for exact details for nodes.

Applying this to blocks, the i18n module provides functionality (1) and (3), but not (2) at this point. Translation set support is being implemented for various objects (menus, paths, etc. are already covered by i18n), but not blocks yet. (1) is very simple to use, but (3) will be a real pain if you don't read this blog post...

Marking blocks with languages

Enable the Block languages module from the the Internationalization module suite. As the name suggests, this module only lets you specify languages for blocks in itself. It requires string translation module which we'll talk about later below. For now, we'll just concentrate on the language relation functionality.

Now when you go to Administration » Structure » Blocks » Add block (or edit an existing block), you'll see a new Languages vertical tab. That is where you can pick a number of languages to restrict the display of this block to. This is much like the other block visibility components, and yes, it should have been part of Drupal core. Those checkboxes will only manage hiding and showing the block on pages depending on language. You can use this to have different copies of blocks for different languages and treat them differently (eg. place them at different weights on pages if needed). You can also use this to have single language blocks only showing on certain language versions of the site. Such as when you have a discount only for certain audiences.

That said, you can kind of achieve (2) from above by using different copies of blocks for different languages, but relations between the blocks are not maintained. I think this would be a great feature for future versions of i18n.

You might have also noticed the "Make this block's title and content translatable." checkbox, which sounds like a very simple flip-switch to implement (3) for blocks, but to make that work, I need you to do some learning first about the underlying pieces.

Ok, what are these textgroups?

With node translation and path alias translation support included only in Drupal 6, there was a pressing need for providing some kind of API for contributed modules to translate other things. It was clear that those other things will mostly have tiny data structures. Think blocks have titles and body text, menu items have titles and descriptions. These cannot have additional fields, so the structure of the data to translate is well known. Many of these things did not become entities in Drupal 7 either, given they are structural or supplemental data, and not content per say.

So support for translating these values was needed. But Drupal core already had a translation system which let people store keys and translations for them. It just happens that Drupal core uses English text as keys for the UI translations. Location information was also possible to store with these, so we could reuse the interface translation system (and the user interface) to translate details of other objects. What's even better, you get import and export functionality for these translations for free.

Textgroups show up as a segmentation of translatable strings on the user interface translation screens. When you go to admin/config/regional/translate/translate (Administration » Configuration » Translate interface » Translate) even on a bare bones Drupal 7 core based site with locale module enabled, you'll see the usually little noticed "Limit search to" "All text groups" or "Built-in interface" dropdown. When more textgroups became available, such as with block translation, you'll find those here too.

This sounds like a brilliant idea in terms of reuse and the kind of functionality you get for free, but its a very confusing UI for anybody who does not want to understand all the underlying mechanics - that is most users. Translation of systems using textgroups happens at a totally different place to where you actually enter the data and it is fragmented to per-string items - you translate your block title and then look for your block body separately. It is also intermixed with permission issues discussed below. Don't get me wrong, I'm not dissing the work of anybody else, I was one of the proponents of this solution. Huh. Thankfully now we have experience with it and know better for the future. Some contributed modules emerged to build more intuitive UIs, catering for specific use cases, and as Jose Reyero usually says, the i18n module is merely a backend module for your needs, not a multilingual solution. People could possibly need different UIs based on their needs. So for now, I'll show the base i18n functionality here, which should help you understand the concept fully.

The string translation module and setting up permissions

The string translation module that was turned on with block languages is key to providing the backend for the textgroups functionality. While Drupal core itself supports textgroups in the database and editing UI, a data submission API was not provided, so this module fills in the gap. Now that you have both block languages module and string translation enabled, you should see a "Block" textgroup on Administration » Configuration » Translate interface » Translate, but it will be empty for now.

Translators need to be able to translate all kinds of text on your site. These strings however can use a wide range of input formats and especially if your site uses fragile input formats such as PHP input, you don't want your translators to fiddle with those strings. So you'll need to set up permissions for translators to certain input formats to let them translate those. The Administration » Configuration » Regional and language » Multilingual settings page has a Strings tab to configure that. By default, only plain text strings are enabled, so your regural blocks (submitted with Filtered HTML by default) would not be properly translatable. Let's grant the Filtered HTML format for translators!

Unfortunately this is needed because the textgroup system does not keep track of input formats, so only text in allowed input formats are saved and made available for translation. The system cannot use the format allowed for the account when the source text is saved, since that might be above the permissions allowed for translators. (A more complex but maybe more standard implementation would be to require a translator role, and apply the input format permissons from that role. I think this is complex enough to not to try to put in even more code reuse...).

Now you can translate your blocks

Now that we set up the string translation permissions proper, we can go back and add a block with translation support. Now let's check "Make this block's title and content translatable.". You can combine this with language visibility (ie. translate and only show for some languages), but I'll keep it to show for all languages here. I've created a block titled "Today's specials" and with the text "Today, we are serving delicious latte with ....". When saving the block, I'll be told that both strings are saved for translation with the location keys "blocks:block:1:title" and "blocks:block:1:body". This is how textgroup locations keep track of where strings came from. If you did not do the previous step, you are told that the body is not saved due to a disallowed input format. Look out for this feedback to make sure you do save the block right.

Now because you've read all the above, it will almost feel natural to you to go to Administration » Configuration » Translate interface » Translate, pick the Block textgroup from the dropdown and see the two translatable strings there. One you save your translations and go back to your site you'll quickly see the results.

My English block looks like this:

When switching to Hungarian:

We have covered this in previous pieces, but for this to work consistently, you'll need a language selection mode that you can trigger from the browser. I've set up URL based language negotiations with 'en' and 'hu' as path prefixes for English and Hungarian on this demo site. I've also enabled and placed my custom block and the language switcher block to show how this works. Now when I switch to English or Hungarian, the right translation of the block will show. Because translations use the same block object, the placement is consistent in all languages and I don't need to juggle multiple copies of the block. If I'll ever need blocks just for one specific language, I'll still be able to add a new block without translation, and limit it to one language with the method explained above.

Internationalization sprint coming up!

To spread multilingual functionality and improve on usability and fix bugs 5 days of internationalization sprinting is planned for mid-May 2011. If you are interested in joining don't hesitate to sign up!

Menus planned for next

Block translation provides a great segway to menu translation (which in some ways depends on block translation for certain tricks). I plan to cover that in the next part.

In the meantime, you can still check out part 5, read part 4, part 3 and grab part 2 and part 1 of my series.

Thanks for reading!

Tags: 

Comments

mandy's picture

Nice

Its important to make people feel comfort near us. We are need other people in our life. We cant live alone in this life. That is why we need to make a good relation to all the people around us.
stamped concrete ma

sharlin's picture

This is excellent post.

gulesider
Very good post with informative information. I really appreciate the fact that you approach these topics from a stand point of knowledge and information. This is the first time, I visited at your site and became your fan. You are bookmarked. Please keep on posting.

jaime123's picture

This really is generally is a

This really is generally is a great post and I joy to read this kind of submit. Your site obtaining outstanding data and that he will deliver me personally real great cognition you’re also many document is definitely superb and I casual stop by at your websites as well as sign up to completely new update to this website. You can visit this site Free Flash Games and snow bros game is good site for online flash games.

Raoul's picture

Thanks for sharing lots.

where to get backlinks
The Block languages module, part of the Internationalization (i18n) package, allows you to configure for which languages each block is visible. The settings for visibility per language are provided under Visibility Settings via the Languages tab when configuring a block.

Calvin's picture

Lots of thanks for this post.

best deals delhi
With the basics of node and site settings translation behind us, we are getting to the more complex parts, at least in terms of the user interfaces involved. While with node translation you get a tab on each node to translate it (regardless of setting up translation sets or using translatable fields), and with settings translation, you get quick jump links, the subsystems that work with textgroups will require a better understanding of how the Drupal systems relate.

Olivier's picture

Very good post with informative information.

deals on food in delhi
The first case is great when you don't need to translate the object, the second is great when you need to use translations in different contexts (for nodes, you can maintain a separate comment set, put in different menus, etc). The last is great when you want to maintain the object the same way regardless of language. This might be great for an e-commerce site.

janifer's picture

Fascinating blog!

jesolo
Drupal's default installation is in English. But, as you'll soon see, it can be configured to handle other languages as well. Creating a multilingual website expands your audience, and studies have shown that users are more likely to buy products and services on a website when content is presented in their native language.

janifer's picture

Thanks to a brilliant effort .

Voyeur Videos
Drupal's default installation is in English. But, as you'll soon see, it can be configured to handle other languages as well. Creating a multilingual website expands your audience, and studies have shown that users are more likely to buy products and services on a website when content is presented in their native language.

jones56's picture

nice

I don't consider myself a big thinker, but your article has triggered my thought processes. Thank you for your great content. I truly appreciate it.
Wine Gifts

Aram's picture

Thanks for sharing lots

Produtos Importados
Drupal is a great system to run foreign language websites on. The core itself is written in English and modules and themes are expected to follow suit. For developers, very simple wrapper functions are available to mark your translatable strings and let Drupal translate them to whatever language needed.

Benjamin's picture

Thanks for the nice post.

Lloyd Irvin
The way that Drupal manages translations has been evolving over several versions of Drupal. It has always been somewhat daunting to figure out how to set up a multilingual site in Drupal, and it requires a combination of core and contributed modules to make it work well. In Drupal 7 we have some great new features, but we also ended up with two different systems of managing content translation, so there are also lots of new questions and options.

bruno's picture

Translating using Views or Pages?

Hi Gábor,

Very nice articles. I'm trying to setup a multi-language website in 3 or 4 languages (multiple translators) but it seems I have to create one view for each language which becomes cumbersome and insane as the amount of content types increases as well as if you decide to do some changes as well as from CSS layout.

Basically, articles need to have small words that change depending of the language. What would be the most efficient way to implement this? Basically, it's just simple stuff like "by" to por (portuguese) as well as words like comments, etc. I have been googling but since i'm no drupal expert i think I may have to do just multiple views for now...

bruno's picture

Hi Gabor,

Hi Gabor,

thanks for getting back to me. I have setup a new content type with subject, body, etc. I get this data using views since this content type is supposed to be like a blog/article post. So I extract comment numbers, author, etc but I need to translate part of it since different languages use different words for comment, "by author", etc. So far I'm doing this as different Views pages but then in Panels I need to setup conditionally which View page to use depending on language of the site. This is not terrible but it implies maintaining 4 versions of Views as opposed to one with translatable "fields/variables", which is the most elegant solution. Any ideas?

Cheers!
bruno

WATSON's picture

good comment

That is genuinely helpful. I would like to ask if it would be Okay if I mentioned some of that on my own blog.Thank You for the post, I was looking for the post for a long time. And now find it very concretely.I've been looking for this kind of info, so thanks for your post. Cladding Redcliffe I agree it probably needs a bit of tweaking but I have some good insights now on what I need to do with some customisation.I must acknowledged you for the information you shared. I like the services that amazingly surprised me that this kind of work should be done in the proper way and also thanks for the information you shared.

jimi's picture

I wanted to thank you for

I wanted to thank you for this unique read. Tradzik I definitely savoured all bits and pieces of it including all the comments and I have added you to my bookmark list to check out new articles you post.Creating an unfunded PhD tier could have dire consequences for the accessibility and diversity of the graduate school,.

aashu's picture

use full

austech A reliable blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that characterize a blog to be a best one.

aashu's picture

hello.

termite I have explain so many article of this site in which some of them were very intresting and inspiring.This article has good title with good description.

Jack Scada's picture

You appear to know so much

You appear to know so much about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit, but other than that, this is great blog. A great read. I will certainly be back. somanabolic muscle maximizer I love what you guys are up too. This type of clever work and coverage!

kavya's picture

nice one

I cannot get the sock down to forty stitches. I have taken to decreasing my stitches instead. I have ripped out the sock at least three times I have found the gradient tool but the cross does not look the same as your doing. Its diffrent strength in the shades. Like the are overlaying eachother. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. I really loved reading your blog. It was very well authored and easy to undertand. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. Rockford Poetry

febrication's picture

automaten kostenlos spielen

race car fabricationStandard Slots could constantly be around and there is almost no that you can do with the aforementioned. Then we take a venture up to the more propelled Video Slots. These diversions incorporated diffuse images, wild images, unlimited rotations and reward adjusts. The aforementioned spaces quite electrified the players when they hit the scene and ended up being substantially accessible, immediately drawing in a colossal fan base.

bruno's picture

Sorry, to directly reply to

Sorry, to directly reply to your question, they come from "rewriting output" in Views since I'm not relying on the default Content output. Would this be a better approach? I don't want to have all the info it outputs.

Tommy's picture

Menus next

I second this! I have read all articles in this series and it has helped me every step on the way to make a multilingual site. Now only the menu remains. Really looking forward to that article!

Thanks for the great work done!

Robert Le Maout's picture

Translate block title

Gabor,

First of all congratulations for your tutorials: clear, efficient and easy to follow.

I still have the following issue : "strings are saved for translation with the location keys "blocks:block:1:title" and "blocks:block:1:body". Going to Administration » Configuration » Translate interface » Translate, pick the Block textgroup from the dropdown and see the two translatable strings there". Translation for the title is displayed, inputing the translation is OK, but still having the block title as Translation + context. Not able to figure out how to get rid off context in both title and body. Thanks in advance for your support. P.S.: I'm running on the latest Drupal releases.

Kevin Mahoney's picture

Thanks for the article! Very

Thanks for the article! Very informative!

I have one question when it comes to being able to translate custom block data. If I create blocks through a custom module, I want the translation process to behave much like nodes do (creating different versions). I have image upload fields in hook_block_configure() that I want to be able to be swapped out for different languages (to give culturally-relavent images). I'm beginning to think there's not really an infrastructure for this... am I missing anything? Would the best solution just to create redundant blocks for each language? Thanks!

haclong's picture

Views with terms not translated

Hello

I've got a view with type = Term. my Vocabulary is localized and there's translation for some terms.
When i build the view (select taxonomy terms name, order by name ascendant), i can't get the translated terms but only the original language. There's a Field language option in the advanced items but i can't manage to get the translated terms. What have i done wrong ?

haclong's picture

Which formatter ?

Hello Gábor

Thank you for your answer.

I'm sorry, i check anything which sounds like "formatter" but... Maybe i'm missing something.
I created a view with a type = Term.
This view has only one display : the block one.
In Format area > Format, I've chosen HTML list. Other options are Grid | Jump menu | Table | Unformatted list. Settings for HTML list : No groupe field #1 - List type : unordered - Row class remains empty - Wrapper class = item-list - List class remains empty.
In Format area > Show, I've chosen Fields. Other option is Rendered entity. I've changed this but it looks like there's no improvement either. Settings for Fields : Provide default field wrapper elements, No inline field, no separator defined, do not hide empty fields.
Fields Area > Taxonomy term : name. Other fields available : There's File usage (Entity type | Module | Use count) - Global (Contextual links | Custom text | Math expression | View result counter) - Taxonomy term (Name | Rendered Taxonomy term | Term description | Term edit link | Term ID | Weight) - Taxonomy vocabulary (Description | Machine name | Name | Vocabulary ID) that's all.. There's no translated option. I was thinking a while at Rendered Taxonomy term but i don't know how to get it working.
Settings for Taxonomy term : name = no label - include in display - link this field to its page - do not convert space to hyphens - no particular style settings defined - no result behavior defined : number 0 is not empty - not hide if empty - hide rewriting if empty - no rewrite results defined.
Filter criteria select only one vocabulary as expected
Sort criteria sort by taxonomy name ascending
Block settings : no particular name - Access by permission / View published content
Nothing defined for header and footer, no pager either, display all items and there's no more link
There's no Contextual filters, no relationship defined, no results behavior defined, exposed form is set by default to Basic but since there is nothing exposed, it shouldn't be used
As for the Other area : no comment - no ajax - do not hide attachements in summary - do not use aggregation - no particular query settings defined - field language should be current user's language and when needed, add the field language condition to the query, no caching, no link display, no css et do not cache block.
I've refreshed the view cache but to no avail. You sound really confident so i think that i definitely do something wrong but i'm out of idea...

kamcvi's picture

Ship ltl freight

Ship ltl freight with ease. cheap quotes. we partner with reputable carriers to offer the lowest estimate. LTL freight Center negotiates for you! LTL Freight Center arranges shipment for diverse loads including: Less than Truckload, Full Truckload, Van Flatbed, Airfreight, and Local and National Hotshot Services.

cheap nike shoes's picture

cheap nike shoes

I really wanted to write down a quick message so as to appreciate you for those fantastic techniques you are giving here. My long internet research has at the end been paid with awesome facts and strategies to exchange with my partners. I would assume that many of us readers actually are very blessed to be in a fantastic site with so many special individuals with great tactics. I feel pretty blessed to have used your web site and look forward to some more excellent times reading here. Thank you again for a lot of things.

kamcvi's picture

Ship ltl freight with ease. cheap quotes.

Ship ltl freight with ease. cheap quotes. we partner with reputable carriers to offer the lowest estimate. LTL freight Center negotiates for you! LTL Freight Center arranges shipment for diverse loads including: Less than Truckload, Full Truckload, Van Flatbed, Airfreight, and Local and National Hotshot Services.

nike free run's picture

nike free run

I am just writing to make you know what a impressive experience my wife's daughter obtained browsing yuor web blog. She came to find a good number of details, which included what it's like to have an excellent helping heart to get certain people clearly know just exactly selected complex matters. You actually exceeded her expectations. I appreciate you for supplying those important, trusted, revealing not to mention cool guidance on the topic to Emily.

Amy's picture

I really thank you for the

I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! perruques

Michael Frank's picture

Great post!!

cuba travel I have explain a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…

nike free run's picture

nike free run

I am commenting to let you understand what a impressive encounter my wife's child enjoyed reading through your blog. She even learned such a lot of details, with the inclusion of how it is like to have a wonderful teaching spirit to have many more completely fully understand chosen tortuous topics. You undoubtedly surpassed our own expectations. Thank you for giving the productive, dependable, educational and as well as easy tips about this topic to Kate.

Ashton4's picture

This is a nice blog.The

This is a nice blog.The detailed information about steps you can take to ensure a safe trip, see How to Have a Safe Trip. Meanwhile, here are some quick tips to make your travel easier. Roofing Brisbane This travel tips help you schedule your time and money.

Brian jack's picture

I was just seeking this

I was just seeking this information for a while. After 6 hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that don't rank this kind of informative websites in top of the list. Normally the top web sites are full of garbage. How to last longer in bed

febrication's picture

febrication

pest controlIt is not essential that it may as well show up in the winning line, yet it might be anyplace on the reels. 3 or more wins of the 'book' gives 10 unlimited rotations. Getting one of the images i.e. Specialist, 10, A, J, Q, K, scarab, figure or Pharaoh on each of the 5 chambers in the winning line without images being disturbed by each one in turn is the last objective or win. Depending on if the player decides on greatest number of lines.

Brian jack's picture

Have you ever thought about

Have you ever thought about adding a little bit more than just your articles? I mean, what you say is important and all. Nevertheless imagine if you added some great photos or video clips to give your posts more, "pop"! Your content is excellent but with pics and videos, this blog could definitely be one of the very best in its niche. Excellent blog! agen bola

Steve's picture

thanks

Hi there! This blog post could not be written any better! Looking at this post reminds me of my previous roommate! He always kept preaching about this. I will send this information to him. Pretty sure he's going to have a great read. pregnancy miracle review Thank you for sharing!

www.10starsfoods.com's picture

thank

I have been waiting for someone to share these post. This has really made me think and I hope to read more. Thank you very much for writing such an interesting article on this topic www.needlawyerforus.com

rabby's picture

Datacenter IndiaOutline

Datacenter IndiaOutline Support of multilingual content in Drupal: an overview New multilingual features in D7 core New multilingual features in D7 versions of contributed modules (i18n etc.) Summary of most important improvements in multilingual functionality Problems and prospects

calvinbrock735's picture

I simply want to tell you

I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. Flowers

epicroom's picture

This was a noncontroversial

This was a noncontroversial statement similar to statements made by many others. But what struck me that here, as in many other issues i write in my personal. This is very interesting article.
Your article affects a lot of "burning" issues in our society.
It is impossible to be indifferent to these challenges. www.obatkuatmantap.com
There are many articles on the web on this particular point,
but you have captured another side of the topic.
This post gives the light in which we are able to observe the reality.
Very professional. After all I will be subscribing for your rss feed and I hope you write once more very soon !

snoring mouthpiece's picture

The carcinogen NNK [4-

The carcinogen NNK [4-(methylnirosamino)-1-(3-pyridyl)-1-butanone] was seen to become found in a energy of .008 micrograms per patch in NicoDerm CQ and NNN [N'-nitrosonornicotine] was seen to become found in a energy of .002 micrograms per piece in Nicorette.

Because of the discovering that nicotine alternative items and electric cigarettes both contain cancer resulting in cancer leading to cancer causing carcinogens, greenavis e cigs how come the American Lung Association is just while using recall of electrical cigarettes, not other nicotine alternative items? Should not the ALA also express concern yourself with nicotine alternative medicines because of the very fact they've created recorded reference to cancer resulting in cancer leading to cancer causing carcinogens which there's therefore no safe quantity of reference to nicotine alternative items?

ymous's picture

Easily, the article is

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. sports broadcast

Add new comment