Multi-language functions in Orchard

Source: Internet
Author: User
ArticleDirectory
    • Localized orchard applications and modules
    • Localized website content
    • References
Orchard supports two Localization Methods: 1. orchard Application Program And some text strings in the module for localization. This is equivalent to the multi-language support of the program itself. Most CMS systems support this function, such as dotnetnuke. 2. Localization of website content. For example, you can enter both Chinese and English versions when entering a news article.

 

Localized orchard applications and modules all text strings in Orchard applications are output using a separate T () method. This method can be used to find the localized translation of the corresponding string based on the language region of the current site. By default, orchard provides English (En-US) strings, but you can also provide other language regions. You can translate all static strings in the admin background and the foreground website by adding a Language Pack file (. Po format. The following describes how to download and install a Language Pack file and set it to use.

 

Remarks

In. NET applications, localization is usually implemented by using resource files (. resx) and ancillary assembly. Orchard requires a more lightweight method, which is to use the. Po file. In orchard, the number of Language Pack files equals to the number of modules multiplied by the supported language. This number may continue to grow, so that the design of the ancillary Assembly will no longer apply to this requirement. On the other hand, the. Po file is loaded or uninstalled as needed, just like the. resx file, and in many tools, the. Po file is in a standard storage format.

Install the Language Pack

As an example, we download and set a Language Pack for simplified Chinese (zh-CN. You can download the required language package from the address below: http://orchardproject.net/localize/zh-cnclick to download the Po filesand Save the downloaded .zip file to your computer.

Method 1: directly decompress the Language Pack File

Decompress the downloaded Language Pack to the root directory of the website. Make sure that the extracted content is extracted to the root directory of the website, instead of the subdirectory named after the ZIP file name. In this way, copy the Po file to your website directory by extracting the Language Pack file. This is a very simple method, but if the module in the Language Pack does not exist on your website. In this way, there will be more directories. If you don't want to see such results, the next method may be more suitable for you.

Method 2: Use the Translation Manager module to install the Language Pack.

First, you need to download and install the Translation Manager module from the orchard software store. Once this module is installed, you can use the following command in the command line tool to install the Language Pack. Install translation c: \ temp \ zh-CN.zip C: \ temp \ zh-CN.zip is the location where you just downloaded the file to save, and the command line tool usage can be viewed here. After running this command, an existing module will install the corresponding Po file. If there is no module, no redundant directories will be created to install the Po file. If you install a new module later, run the command again.

Set site language

To set the default language of the current site, click "Settings => General" in the background management ". Under the default site culture, click add or remove supported cultures for the site. On the cultures page, select a language region from the available language region list. If you want to remove a language area, just click X next to the added language area. After you add one or more language regions, click the general menu to return to the manage settings page. Select the default language of the site from the default site culture. After you set the language area of the Language Pack you just installed, the background interface of the WebSite becomes a simplified Chinese interface. Of course, the content on the interface is not completely translated, because some content is not included in the Language Pack, and some content is dynamic content. Next we will introduce how to improve the remaining two translation tasks.

Setting the default language area to a language area does not affect the language unless you have installed the corresponding language pack. Orchard searches for the following path to obtain the corresponding language pack file.


local file path of the core module ~ /CORE/app_data/localization/ /orchard. Core. Po
common module local file path ~ /Modules/ /app_data/localization/ /orchard. Module. Po
path of the localized topic file ~ /Themes/ /app_data/localization/ /orchard. theme. Po
General localized file paths for global sites ~ /App_data/localization/ /orchard. Root. Po
Common localized file path for virtual sub-sites ~ /App_data/sites/<tenant name>/localization/<culture-code>/orchard. Po

Available Language Pack files

You can download existing Language Pack files in your http://orchardproject.net/localize, which are provided by everyone. If you cannot find the corresponding language pack file, please translate it. It only takes you a few hours, but it will benefit the whole society.

Contribute new Language Pack files

When you cannot find the available Language Pack file, or the available Language Pack contains errors or Missing errors. You can use the following introduction to create and improve Language Pack files and provide them to orchard for the benefit of everyone.

Use NotePad to modify the Language Pack File

In http://orchardproject.net/localize, you can create a language package template to be translated. Find the Create a New Translation Section, select the language you want to translate, and click "CREATE ". Next, you will jump to a new page and click "download the Po Files" to download the template file.

Decompress the downloaded Language Pack template file, find the. Po file, and open it with notepad. Then translate the corresponding content inside, translate all the Po files and re-compress this folder, and you will be able to translate the content of the mail join-orchard-localization@lists.outercurve.org. They will put the translation content in the list of available language packs.

When saving the. Po file, you need to set the file encoding format to UTF-8. Generally, when saving the file as a file, select the encoding drop-down box next to the keep button.

Language Pack File Format

The following describes how to translate a Language Pack file. The following table lists the elements of a translation entry in the Language Pack:


use location, indicating where to use this translation entry #: reference-string
entry ID, which is usually the original untranslated string. This string cannot be modified after this ID is set.

even if the English string is changed, the current translation in some other languages can continue to work without being updated.

#| msgid" ID-string "
the current English string, which can be used as the basis for our translation. msgid" English-string "
Content to be translated Msgstr "translated-string"

 

 

Reference position of a translation entry The reference position of translation entries in A. Po file is optional. If no reference position is specified for a translation entry, it serves as a backup resource when a translation entry with the same ID and no reference position is found. This method can be used for a common string in an application, such as Save. In this way, only one translation entry is used when Save appears multiple times in the application. The reference location of a translation entry can be different, depending on how the translation entry is used in the application. The reference location is usually as follows:
    • Used in the View:The reference location is the virtual path of the View File, for example :~ /Themes/thethememachine/views/user. cshtml
    • In the. CS file:The reference location is the fully qualified type name of the corresponding class, such as orchard. Packaging. adminmenu.
    • Used in the module and topic list file:The reference location is the virtual path of the list file, for example :~ Themes/thethememachine/theme.txt. Note that the msgid of the module and topic list is the name of the corresponding field. For example, the msgid used for translation is author.

Online modification of Language Pack files

This requires an email to orchard to register the corresponding account, so I have not tried it. You can click here to learn more.

Provide Language Pack files for third-party modules

The available Language Pack files provided by orchard only contain some common modules. If we develop our own modules, we need to provide our own Language Pack files. After installing the Translation Manager, you can use the following command in the command line tool to create a Language Pack file for your module, for example: Extract default translation/extensions: Bing. Maps/output: \ Temp Upload to the directory you specified. You can also send this file to the orchardfeedback@outercurve.org, orchard will add your module's Language Pack file to the online translation database and provide it for everyone to download. In addition to static strings in localized websites and modules, orchard also provides localized website content functions. First, you need to enable the localization function. In the orchard management background, click the modules menu, find the localization function, and click Enable. The localization component is automatically added to the default page type and blog post type. You can also add the localization component to other content types you need to translate. Click the content menu in the background management system. You can see a link of + new translation under some content. Note: This link is only displayed when your site settings support multiple languages. For the setting method, see the preceding description. After you click the + new translation link, a page for translation content appears. It is used to translate the parent content you want to translate (that is, the content in the default language of the website). Each translation content will exist as an independent content item in Orchard. On the Translation content page, you can select the language to be translated. The link to the content also adds the language name as the suffix. After the translation is complete, click Save and return to the front-end website to find the translated content. You will find that there is another translation version area on the page. For example, click the corresponding language version to go To the content page of the corresponding language version.

Remarks

The localization feature is a comprehensive feature, not all functions in Orchard support localization. For example, orchard cannot display the available translation content by Automatically Obtaining the default language region of the current browser. This function will be implemented in future versions. Before that, you can use the icultureselector interface in the module to achieve this requirement. If you have other methods or requirements for localization implementation, you can mail them to the join-orchard-localization@lists.codeplex.org.

Reference http://orchardproject.net/docs/Creating-global-ready-applications.ashx

 

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.