Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Working with Content > Non-node entities

Non-node entities

Non-node entities Although translating nodes is usually the bulk of the content translation burden, there might be "content" from other entities as well. This section walks us through the configuration for these non-node core entities, namely, comments, users, and taxonomy terms. Comments For each content type, you will need to decide if it makes sense to translate comments. If comments are coming from the general public, then it's unlikely that they should be translated. But, if there are comments that you control, then translating them might make sense. For example, if you have a company blog where only employees make comments and the blog posts will be translated, you might decide to translate the comments as well. Unlike nodes, comments can only be handled using field translation as follows: Navigate to Configuration | Regional and language | Entity translation.Select the Comment checkbox and click on Save configuration.Now we can enable field translation for any of our comment fields. To do this, we need to choose a content type, so we can get to the correct configuration page. I'll start with the Blog entry content type at Structure | Content types | Blog entry | Edit.Navigate to your content type config page and then click on the Comment fields tab. Since the Title module is installed, we have a replace link available for the Subject field. Click on replace.Select the Replace subject with a field instance checkbox.Click Save settings. Your comment fields should look similar to the following screenshot: You now need to hide the new Subject field from the display, so that you don't have two subject lines showing up in the comments: Click on the Comment display tab.Choose<Hidden> for the Subject.Click on Save. Note You need to repeat the Subject field replacement process for all content type comment entities that will be translated. Translation for the Subject field is enabled by the Title module, so you just need to configure the Comment field using the following steps: Go back to the Comment fields tab.Click on the Comment field's edit link and scroll down the form. Click on the Enable translation link if you have existing content (otherwise, check the Users may translate this field checkbox and save the settings).Edit a node comment (or add a new one and save it) and you will see a Translate tab. Click on the Translate tab and you will find a familiar translation overview page: The process for translating comments is the same as the process for translating nodes. Click on the add translation link, translate the content, and click on Save translation. Repeat for each language. Language assignment When creating a comment, the language assigned is based on the interface language. If I'm viewing the site in German and create a comment, then the language for the comment will be German as well. This is true whether the node being commented on was translated using node translation or field translation. Comment display When viewing comments on nodes that use node translation, you will see only the comments associated with the particular node. If there is an English node and an associated German node, then you will see different comments for each since the comments are not shared. For field-translated nodes this is different since there is only one node. By default, you see all comments, and comments show up in the selected language when possible. For example, if you are viewing German content, a comment will show up in German if there is a German translation or the comment's source language is German. If German is not available, the source comment will be shown (in whatever language). If you prefer that only comments with the selected language be displayed, then follow the given steps: Edit the content type for the comments (for example, Structure | Content types | Blog entry | Edit).Click on the Comment settings tab.Select the Filter comments per language checkbox.Click on Save content type. Users Although it is a bit strange to think of users as content, users can have fields just like nodes and comments. So, just like for node and comment fields, we can enable translation for any of the user fields. When might this make sense? For general users, it probably doesn't. But, if your site showcases your employees, you might want to translate profile information for your employee users. First, enable field translation for users by going to Configuration | Regional and language | Entity translation.Select User and click on Save configuration.Now navigate to Configuration | People | Account settings | Manage fields and you'll see the default user fields, namely User name and password and Timezone. These aren't actually real "fields" (they are usually referred to as "properties"), so we can't enable translation for any of them.Add a new Long text field called Bio.Enable the Users may translate this field checkbox when saving the field settings. This new Bio field is now translatable.Create a new user or edit an existing one and fill in the Bio text.Now when you view a user, you will see a Translate tab. Click on the tab to get to the translation overview page: Translating user information follows familiar steps: Click on the add translation link.Translate content and click on the Save translation button.Repeat for all languages. Taxonomy terms Taxonomy terms can be associated with nodes (or other entities) by using a Term reference field. For example, the demo site has a Blog entry content type with a Blog Tags term reference field. One way to deal with different translations having different taxonomy terms is to configure the term reference field itself to be translatable. When using node translation, this will be the default behavior unless the field is configured with the Synchronize Translations module as discussed previously. For nodes using field translation, use the process explained earlier for content type fields. This approach makes the most sense when you are using completely different and unrelated terms for each translation. The other approach, which is more typical, is to configure the taxonomy term entities. One complication is that we have different ways to handle this configuration. First, we can use the field translation method for term fields similar to what we did for node, comment, and user fields. Second, the Internationalization package provides a flexible Taxonomy Translation module for translating vocabularies and terms in a variety of ways. Field translation will be addressed here but the Taxonomy Translation module will be covered in Chapter 4, Configuring Blocks, Menus, Taxonomy, and Views, since it is a very different approach. These two methods can be used in parallel (for different vocabularies). Field translation is useful when you have custom fields for your taxonomy terms because the Taxonomy Translation module only handles the term name and description. For example, if you have a "Slang" vocabulary and decide to add an "Example Usage" field, then it would make sense to use field translation, so that all term fields (Name, Description, Example Usage, and so on) are translatable. Another reason you might choose field translation instead of taxonomy translation is just for simplicity (there are fewer modules to deal with). Configuring field translation for the taxonomy term entities is similar to what we did for nodes, comments, and users: First, enable the Taxonomy term entity type at Configuration | Regional and language | Entity translation and save the settings.Now you need to choose a vocabulary and navigate to its Manage fields page (for example, Structure | Taxonomy | Tags | Manage fields).You will see replace links for both the Name and Description fields because the Title module is installed.Click on replace for the Name field, select the Replace name with a field instance checkbox, and click on Save settings.Repeat this process for the Description field. Tip If you have custom taxonomy term fields, you can enable translation for those, in the way the user Bio field was configured previously. With field translation configured, you can now edit any of your terms in the vocabulary and find a Translate tab. On the Translate tab page, you'll see the translation overview where you can do the usual, that is, click on the add translation link, translate Name and Description, save the translation, and repeat for your languages. Once the terms are translated, the way they are used depends on the content they are associated with. If the node's term reference field is shared for all node translations, then just choose your terms for one node translation and, when you view a different node translation, the translated terms will show up. If the node's term reference field is not shared, then just choose the correct language-specific terms when editing each translation. Custom entities Drupal core provides node, comment, user, and taxonomy term entities, but contributed modules can also define custom entities in their code. For example, the Commerce module defines entities for products, payments, and customers, and the Organic Groups module has entities for groups and memberships. In theory, by using the Entity Translation module, you can configure field translation for any entity type with fields. The process would be similar to what we did previously. But, in practice, it might not work depending on the entity. For example, translating Commerce Product fields (from the Commerce module) does work (check out kristen.org/drupal7-i18n-commerce for a tutorial). For other custom entities, check the module's project page or issue queue to see if field translation is fully supported.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint