How does AnQiCMS implement the switching and display of multilingual content to enhance the international user experience?

In today's globalized digital world, a website that can present its content in multiple languages undoubtedly can greatly expand its user base and significantly enhance the user experience.AnQiCMS as a powerful content management system, fully considers the needs of international operation, and provides a flexible and efficient mechanism to switch and display multilingual content.

Why is multilingual content so important?

Imagine a user from Japan visiting your website. If they can read the product description or service instructions in their native language, their sense of trust and engagement will immediately increase.Multilingual content not only breaks language barriers, allowing your information to reach a wider audience, but also improves the visibility of search engines in different countries and regions, thereby bringing more accurate traffic.AnQiCMS is well aware of this, considering multilingual support as one of its core features, aiming to help operators easily achieve a global layout.

The foundation of multilingual content management of AnQiCMS

AnQiCMS has adopted a hierarchical strategy for implementing multilingual content, making the system both flexible and powerful. First, the system provides access toDefault language packageThis support means that the website backend interface and some built-in system prompts can be switched to Chinese or English, convenient for administrators from different language backgrounds to operate.However, it is important to note that the language package here is mainly for the system interface and will not directly change the articles, products, or categories published on your website itself.

To manage actual website content (such as articles, product introductions, single-page applications, etc.), the core advantage of AnQiCMS lies in itsFlexible content modelandMulti-site managementFunction. This means you can create an independent content set for each language version, and even take advantage of the multi-site management feature to set up an independent subdomain or subdirectory for each language, thus achieving complete separation of content and site, which is particularly practical for large-scale internationalized websites.

realizing front-end multi-language switching and display

AnQiCMS provides dedicated template tags to easily implement language switching on the website front-end and ensure that content in different languages is displayed correctly.

1. The display of the switch and language list

A language switch is usually placed in the header, footer, or sidebar of a website. AnQiCMS provides the following{% languages %}Tag to retrieve a list of all multilingual sites configured. With this tag, you can easily build a user-friendly language selection menu.

For example, you can use it in your template like this to display the language list:

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

This code will iterate over all available language sites, generate a link for each language, and display its name, Emoji expression, or custom icon.When the user clicks on these links, the website will switch to the corresponding language version.

2. Language adaptation of page content

After the user selects a specific language through the language switcher, AnQiCMS will according to{% languages %}Tag provided.LinkNavigate to the corresponding language site or content version. This means that you need to create or associate dedicated content for each target language.For example, if your website has both Chinese and English versions, then an article named "AnQiCMS Introduction" needs to create content for both versions separately.By using AnQiCMS's powerful content model and flexible categorization system, you can organize these contents in different languages, ensuring that they are displayed correctly and appropriately in various language environments.

3. Translation of template static text

In addition to dynamic content, there are many static texts in website templates, such as navigation menu items, button text, copyright statements, etc. AnQiCMS provides{% tr %}Translate tags to process these fixed strings.

To use this feature, you need to create it under the template directory.localesCreate a folder and create a corresponding YAML translation file for each language. For example:

./locales
├── en-us
│   └── default.yml
└── zh-cn
    └── default.yml

zh-cn/default.ymlThe content of the file may be as follows:

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

Then you can directly use it in the template.{% tr "home" %}Call the translation of the word "Home". When the website switches to English, ifen-us/default.ymlthere is a correspondinghome: "Home"translation, the system will automatically display "