Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
54
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 19 LOCALIZATION AND TRANSLATION

Content Translation

So far, we’ve been focusing on the translation of Drupal’s user interface. But what about the content? Once the current language setting has been determined, there’s a good chance that the user wants to see the site content in that language! Let’s find out how content translation works.

Introducing the Content Translation Module

Drupal comes with a built-in way to manage translation of content: the content translation module. This module adds additional multilingual support and translation management options to Drupal content types.

Multilingual Support

After going to the Modules page and enabling the Locale and Content translation modules, “Multilingual support” options will show up in the “Publishing options” fieldset of each content type. To see the settings, go to Structure -> Content types, and click the “edit” link for the Basic page content type. Expanding the “Publishing options” fieldset should reveal the new settings for “Multilingual support,” as shown in Figure 19-24.

Figure 19-24. The multilingual settings for a content type

442

CHAPTER 19 LOCALIZATION AND TRANSLATION

Click the Enabled radio button and save the content type. Now if you go to Create content -> Page, you will see a new drop-down field on the content creation form that allows you to select which language the content will be written in or whether the content is “Language neutral.” The field is shown in Figure 19-25.

Figure 19-25. The language selection field on the content creation form

After creating a few pages in different languages, you can see that the administration page for content at Administer -> Content management -> Content has changed to display the language of the post. Also, an option to filter content by language has been added, as shown in Figure 19-26.

Figure 19-26. The content administration page with multilingual support enabled

443

CHAPTER 19 LOCALIZATION AND TRANSLATION

Multilingual Support with Translation

Having the ability to create content in multiple languages is good. However, most sites do not have one piece of content in English and another unrelated piece of content in French. Instead, the French content is usually a translation of the English content (or vice versa). When “Multilingual support” for a content type is set to “Enabled, with translation” (see Figure 19-24), that becomes possible. It involves the following approach:

1.A post is created in one language. This is the source post.

2.Translations of the post are created.

Let’s step through these tasks with an example. First, make sure that the current “Multilingual support” setting for the Page content type is set to “Enabled.” Next, we’ll create a simple page in English. Go to Create content -> Page, and type Hello for the title and Hello my friends for the body. Set the language selection to English, and click the Save button. You should now see a Translate tab in addition to the usual View and Edit tabs (see Figure 19-27).

Figure 19-27. The node now has a tab for translation.

Clicking the Translate tab reveals a summary of the post’s translation status. As shown in Figure 1928, a source post exists in English, but that’s all. Let’s create a French translation by clicking the “add translation” link.

Figure 19-28. Clicking the Translate tab shows a summary of the translation status.

444

CHAPTER 19 LOCALIZATION AND TRANSLATION

Clicking the “add translation” link brings up the node editing form again, but this time, the language selection is set to French. Type Bonjour for the title and Ayez un beau jour for the body. When the Save button is clicked, a new node will be added. Drupal will automatically create links between the source node and the translations, labeled with the language. Figure 19-29 shows how the French translation of the source node looks when the source node is in English and an additional translation exists in French.

Figure 19-29. The French translation of the source node has links to English and Hebrew versions.

The links are built by the implementation of hook_node_view() in modules/translation/translation.module:

/**

*Implements hook_node_view().

*Display translation links with native language names, if this node

*is part of a translation set.

*/

function translation_node_view($node, $view_mode) {

if (isset($node->tnid) && $translations = translation_node_get_translations($node->tnid))

{

$path = 'node/' . $node->nid;

$links = language_negotiation_get_switch_links(LANGUAGE_TYPE_INTERFACE, $path); if (is_object($links)) {

$links = $links->links;

// Do not show link to the same node. unset($links[$node->language]); $node->content['links']['translation'] = array(

'#theme' => 'links__translation_node', '#links' => $links,

'#attributes' => array('class' => array('links', 'inline')),

);

}

}

}

445

CHAPTER 19 LOCALIZATION AND TRANSLATION

In addition to the links that are generated, the locale module provides a language switcher block that can be enabled under Structure -> Blocks. The language switcher block will show up only if multiple languages are enabled and the “Detection and Selection” setting is set to something other than Default. The language switcher block is shown in Figure 19-30.

Figure 19-30. The language switcher block

Let’s get back to our discussion of source nodes and their translations. If a node is a source node, editing it will show an additional fieldset called “Translation settings” in the node editing form. This fieldset contains a single check box labeled “Flag translations as outdated,” as shown in Figure 19-31.

Figure 19-31. The “Translation settings” fieldset in the node editing form of a source node

The check box is used to indicate that edits to the source node have been major enough to require retranslation. Checking the box to flag translations as outdated simply causes the word “outdated” to be displayed when viewing the translation status of a node. Compare Figure 19-28 with Figure 19-32.

446

k

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]