How Drupal implements multilingual sites

Source: Internet
Author: User
Tags drupal

Javascript implementation

Drupal's architecture is fully multilingual, with Javascript exceptions.

First, let's take a look at how Javascript is used in Drupal.

Drupal. t ('string ')
Here, string is the multilingual string that Drupal needs to translate.

Drupal Javascript multi-language mechanism
Step 1: All Javascript files in Drupal will be loaded through drupal_add_js () function. Only JS files whose type is file can be loaded.

Step 2: After Drupal loads all Javascript files, you can use the hook_js_alter hook to view Javascript and traverse Drupal. t and Drupal. formatPlural in JS before render.

Step 3: After parsing the variables in the JS file, directly insert them into the locales_source Database. You can perform translation in the background.

Step 4: save all parsed JS file variables to the variables variable javascript_parsed, generate the Drupal language JS file in the public folder, and add it to the header.

Step 5: after modifying the multilingual variables in any JS file, you need to rebuilt the entire JS cache, find the new variables again, and insert them into the database.

Note:

For Drupal performance reasons, Drupal parses JS files and generates caches. Therefore, when you add or modify a string in a js file, you must clear the cached Drupal to find the new string again and make it available for translation.
Drupal does not automatically extract encrypted JS files. For this reason, the module author should only include the decompressed version of its JS file. Drupal's JS compression function compresses these files and generates a version.
The multilingual strings defined in the JS file can be automatically found through the background translate translation (clear all the caches in advance), and then manually import the strings into other languages through the po file or translate them into other languages in the background.
Examples of using Drupal Javascript in multiple languages

Var comments = Drupal. t ('comments ');
Var commentsOnType = Drupal. t ('comments to @ type posts', {'@ type': typeName });
Var commentCount = Drupal. formatPlural (count, '1 comment', '@ count comments ');
Var commentCountOnType = Drupal. formatPlural (count, '1 comment on @ type posts', '@ count comments on @ type posts', {' @ type': typeName });

OK. Now, I hope you can smoothly implement the multi-language website of JS.

In addition, it is best to configure the Drush tool when clearing the cache. drush cc all is done directly.

The technical scope of this article can be implemented in Drupal6, Drupal7, and drupal8.

Method 2: Use webmaster configuration

Drupal 6 contains the Content Translation module, which allows the website Content to be translated into different languages. It is also a localization module (Locale module, which manages multiple languages and provides multilingual website Translation interfaces) collaboration is the key to creating and maintaining multilingual content sites. Drupal does not enable this module by default. To enable this module correctly, perform the following operations:

  1. Enable the "Content translation" module in the module management of site building. If the column i18n module is installed, we recommend that you enable the "Content type translation" module at the same time;
  2. On the "permission" configuration page, assign "translation content" permissions to appropriate user roles;
  3. The required language added and enabled on the "language" configuration page;
  4. On the "manage"> "Content Management"> "content type" Page, click the "Edit" button on the right of the content type (such as Page and Story) to support multilingual functions, in the "process settings" dialog box, select "enable" in the "multi-language support" dialog box ".

In this way, a language drop-down box and translation link will appear when you create or edit an article, as shown in the following figure:

Click the "translation" link to go to the translation page. The following page is displayed:

Click the "add translation" link or "edit" page next to it to go to the content editing page for other languages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.