How to implement multi-language content switching and front-end 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 optimize the crawling and ranking of search engines, AnQiCMS provides intuitive and efficient solutions.Below, we will delve into how to use AnQiCMS to implement multi-language content switching and front-end display.

1. Basic of multilingual content switching and display

One of AnQiCMS' core strengths 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 your 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.

Second, implement multi-language content: customize sites for different languages

AnQiCMS recommends and supports the implementation of multi-language website content for different languages throughMulti-site managementTo implement the function. This allows you to create a relatively independent site instance for each target language, 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 the multi-language site information configured and display it on the frontend for easy user switching.

BylanguagesLabel, 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:

  • websitesThe variable contains all the details of the language sites.
  • item.LinkPoints to the link of the corresponding language site.
  • item.LanguageNameIt displays the name of the language (such as "Simplified Chinese", "English").
  • item.LanguageEmojianditem.LanguageIconIt provides a variety of language identification options, you can choose to display flag icons or emoticons to make the switcher more intuitive.

To better support search engine optimization (SEO), especially in international websites, add pages for each language versionhreflangthis attribute.hreflangThe tag informs search engines of the corresponding relationships between different language versions of pages, avoids duplicate content issues, and ensures that search engines display the correct pages to users of different languages. You can<head>Add an area similar to the followinghreflangTags:

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

Hereitem.LanguageIt will output the corresponding language code (such aszh-CN/en-US), the search engine will judge based on this information.

III. Template and system interface multilingual: 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 background management interface.This ensures that the user can obtain an experience that conforms to their language habits when using the system, whether it is front-end browsing or back-end management.

  1. System default language package settings:In the AnQiCMS admin panel, you can find the 'Default Language Pack' option.Here are built-in Chinese, English, and many other languages, you can choose one as the default operation language of the system.It should be noted that this setting mainly affects the display language of the back-end management interface, as well as some non-content frontend text automatically generated by the system (such as the 'Submit' button, error messages, etc.).It does not automatically translate specific articles, product descriptions, or category names on your website.

  2. Template static text translation(trTag):For hard-coded static text in template files (such as navigation menu items, fixed phrases in the footer copyright statements), AnQiCMS providestr(translate) Tag to implement the localization of these texts.

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

    For example,zh-cn/default.ymlfile content may be:

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

    Anden-us/default.ymlThen it could be:

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

    In the template, you can use{% tr "yourLocation" %}or{% tr "contactUs" %}Call this translated text. When the user visits the website, the system will automatically display the corresponding translation content based on the current language environment, greatly enhancing the consistency of the user experience.

Summary

AnQiCMS provides a comprehensive solution for multilingual content and front-end display through its multi-site management, flexible language switch tags, and complete template localization mechanism. You can choose to create independent sites for each language to manage content in detail according to business needs, while utilizing the system language packages andtrTags ensure seamless localization of templates and system interfaces. This combined strategy not only helps businesses effectively reach global users but also lays a solid foundation for the international SEO of the website.

Frequently Asked Questions (FAQ)

  1. Q: Does AnQiCMS support switching between multiple languages within the same document, such as switching between Chinese and English versions in the same article?A: According to the document description, AnQiCMS mainly manages content in different languages by creating independent language sites (or configuring different language site instances in multi-site mode).This means you usually need to create independent articles or pages for each language.System language package andtrThe label is mainly used for localizing static text in system interfaces and templates, rather than switching between multi-language versions of the same content entity.

  2. Q: How should I add a new language version website in AnQiCMS?A: To add a new language version of a website usually involves using the "Multi-site Management" feature of AnQiCMS.You need to create a new site, configure a separate domain name or subdomain for it, and then create and manage content in specific languages under that site.At the same time, ensure that the corresponding language package is selected or created for the site in the background settings, and used in the front-end template.languagesTags to provide language switching access.

  3. Q: Why is my website content (such as article titles) still in Chinese when I have selected the English language package in the background "Global Function Settings"?A: The 'Global Function Settings' in the background mainly affects the display language of the AnQiCMS backend management interface, as well as some system-generated front-end prompts 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.).To implement the translation of website content, you need to create and manage content for different language versions separately, usually through a multi-site mode or by using static text in templatestrLabel localization.