How to implement multi-language content switching and frontend display in AnQiCMS?

AnQiCMS demonstrates its powerful and flexible multilingual support capabilities in global content promotion.Whether it is to provide customized content for users in different regions or to optimize the crawling and ranking of search engines, AnQiCMS provides intuitive and efficient solutions.Below, we will delve into how to use AnQiCMS to switch between multi-language content and front-end display.

I. Basic of multi-language content switching and display

One of the core advantages of AnQiCMS is its excellent support for multilingual content.This means you can easily adapt your website content to meet the needs of different language user groups, thereby effectively expanding into the international market.This support is not only reflected in the display of the front-end page, but also runs through the background management and configuration process.

II. Implementing multi-language content: Customizing sites for different languages

For websites with content in different languages, AnQiCMS recommends and supports usingMulti-site managementFunction to implement.This approach allows you to create a relatively independent site instance for each target language, with each site having its own content, categories, and even independent domain names or subdomains, thereby achieving true localized content management.

When you want users to be able to switch between different language versions, AnQiCMS provideslanguagesTemplate tag. This tag can retrieve all configured multilingual site information and display it on the front end, making it convenient for users to click and switch.

PasslanguagesLabel, you can easily build a language switcher. Here is a common code example:

{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" class="language-link">
        {%- if item.LanguageIcon %}
        <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}} icon" class="language-icon" />
        {%- else %}
        {{item.LanguageEmoji}}
        {% endif %}
        {{item.LanguageName}}
    </a>
    {%- endfor %}
</div>
{%- endif %}
{%- endLanguages %}

In this code block:

  • websitesVariable contains all the details of language sites.
  • item.LinkPoints to the link of the corresponding language site.
  • item.LanguageName显示了语言的名称(如“简体中文”、“English”)。
  • item.LanguageEmojianditem.LanguageIconThen a variety of language identification options are provided, you can choose to display national flag icons or emoticons, making the switcher more intuitive.

In order to better support search engine optimization (SEO), especially in internationalized websites, it is crucial to add pages for each language version.hreflangProperties are essential.hreflangTags inform search engines of the corresponding relationships between different language versions of pages, avoiding content duplication issues, and ensuring that search engines display the correct pages to users of different languages. You can in<head>Area addition similar to the followinghreflangTags:

{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endLanguages %}

Here are theitem.LanguageWill output the corresponding language code (such aszh-CN/en-US) Search engines will judge based on this information.

III. Template and multilingual system interface: a more fluent user experience

In addition to creating independent content sites for different languages, AnQiCMS also provides localization support for static text in templates and the language of the backend management interface.This ensures that users get an experience that fits their language habits when using the system, whether it's frontend browsing or backend management.

  1. System default language package settings:In the "Global Function SettingsHere built-in Chinese and English and other languages, you can choose one as the default system operation language.It is necessary to note that this setting mainly affects the display language of the background management interface, as well as some non-content frontend texts automatically generated by the system (such as “Submit” button, error prompts, etc.).It does not automatically translate specific articles, product descriptions, or category names on your website.

  2. Template static text translation (trLabel):For hard-coded static text in template files (such as navigation menu items, fixed phrases in the footer copyright statement), AnQiCMS providestr(translate) To implement the localization of these texts, use the tag.

    To enable the translation feature of the template, you need to create one under the template directory.localesFolder. Inside this folder, create subfolders for each language (for examplezh-cn/en-us), and place a file in each language folderdefault.ymlfile.

    For example,zh-cn/default.ymlThe content of the file may be:

    "yourLocation": "您的位置"
    "contactUs": "联系我们"
    

    whileen-us/default.ymlThen it may be:

    "yourLocation": "Your Location"
    "contactUs": "Contact Us"
    

    In the template, you can use{% tr "yourLocation" %}or{% tr "contactUs" %}Call these translated texts. When users visit the website, the system will automatically display the corresponding translated content based on the current language environment, greatly enhancing the continuity of the user experience.

English, Summary

AnQiCMS provides a comprehensive solution for multilingual content and frontend display through its multi-site management, flexible language switch tags, and完善的模板本地化机制. You can choose to create independent sites for each language to manage content in detail according to business needs, while taking advantage of the system language packages andtrLabels ensure seamless localization of the template and system interface.This combination strategy not only helps enterprises effectively reach global users, but also lays a solid foundation for the international SEO of the website.

Common Questions (FAQ)

  1. Q: AnQiCMS 是否支持在同一个文档内实现多语言切换,例如在同一篇文章中切换中文和英文版本?A: According to the document description, AnQiCMS mainly manages different language content by creating independent language sites (or configuring different language site instances in multi-site mode).This means that you usually need to create separate articles or pages for each language.trTags are mainly used for localizing static text in system interfaces and templates, rather than switching between multilingual versions of the same content entity.

  2. Q: How should I add a new language version website in AnQiCMS?A: Adding a new language version website usually involves using AnQiCMS's 'Multi-Site Management' feature.You need to create a new site, configure a separate domain name or subdomain for it, and then create and manage specific language content under that site.languagesTags to provide language switch access.

  3. Q: I selected the English language pack in the "Global Function Settings" on the back end, but the content of my website (such as article titles) still displays in Chinese. Why is that?A: The 'Global Function Settings' in the background mainly affects the display language of the AnQiCMS backend management interface, as well as some frontend prompt texts generated by the system that are not created by users.It does not directly translate the specific content you edit and publish in the background (such as articles, products, pages, etc.).trLabel localization.