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

Calendar 👁️ 64

In today's digital world, your website may need to be accessible to global users.AnQiCMS fully understands this requirement and provides powerful multilingual support features, allowing you to easily build and manage multilingual websites, thereby better serving users in different countries and regions.How can I implement the switching and display of multilingual content in the AnQiCMS template?Let's explore step by step.

Understanding AnQiCMS' multilingual mechanism: processing two types of 'languages'.

In AnQiCMS, we need to distinguish between two types of 'language' content:

  1. Built-in and template static text:This includes prompt information on the background management interface, fixed navigation items in templates (such as "Home", "Contact Us"), footer copyright statements, and so on, which usually do not change with the articles published by users.
  2. User posted content:This refers to your articles, products, single pages, category descriptions, and other dynamic content, which are the core information of the website.

AnQiCMS provides different handling methods for these two types of content to ensure flexibility and management efficiency.

Implement the switching and display of built-in system and template static text.

In order to allow the interface elements of your website to switch languages according to the user's choice, AnQiCMS has introduced the language package and translation tag mechanism.

Firstly, you need to create a folder namedlocalesin the template directory. In this folder, you can create a subfolder for each supported language, such aszh-cn(Simplified Chinese),en-us(English) and so on. A language subfolder is created within each language folder.default.ymlfile.

For example, the directory structure may be as follows:

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

Inen-us/default.ymlIn the file, you can define the translation content in this way:

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

and in thezh-cn/default.ymlIn English, the corresponding content is:

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

In your template file (for exampleheader.htmlorindex.htmlYou can use it in the{% tr "key" %}Translation tags are used to display this static text. For example:

<nav>
    <a href="/">{% tr "homePage" %}</a>
    <a href="/contact.html">{% tr "contactUs" %}</a>
</nav>
<p>{% tr "yourLocation" %}</p>

When the user switches to a different language, AnQiCMS will automatically load the correspondingdefault.ymlfile and display the corresponding translated text.

In addition, you can find the 'Default Language Pack' option in the 'Global Function Settings' on the AnQiCMS backend.You can set the language of the current site's backend interface and built-in prompts, for example, choose 'Chinese' or 'English'.Please note that this setting mainly affects the system's own language environment and will not directly change the language of the articles, categories, and other user-generated content in your templates.

Implement user content management and display

For articles, products, single pages, and other core content, AnQiCMS's design philosophy is to achieve independent management and display of multilingual content through the "multi-site management" feature. This means that you usually set up an independent site for each language, such as:

  • www.yourdomain.com(Chinese site)
  • en.yourdomain.com(English site)
  • fr.yourdomain.com(French site)

This method has several significant advantages:

  • Content independence:Each language content is completely independent, convenient for management and update, and avoids confusion.
  • SEO friendly:Each language version has an independent URL structure, which is beneficial for search engines to crawl and rank different language content, and it is also convenient for configurationhreflang.
  • Flexibility:Sites in different languages can even use different template designs to adapt to specific cultural or market needs.

In the 'Multi-site Management' section of the AnQiCMS backend, you can easily add these independent language sites.Each site will have its own content, categories, tags, and even administrator accounts.This means that you need to independently publish and manage articles, products, and other content in each language site.This may mean that you need to enter and translate the content repeatedly, but it brings **flexibility and maintainability.

Provide a language switcher in the template.

To make it convenient for users to switch between different language versions, you need to add a language switcher in the template. AnQiCMS provides{% languages websites %}tags to get the list of all configured multilingual websites.

You can add the following code snippet to the header or footer of the template to switch languages:

{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" title="{{item.Name}}">
        {%- 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 through all the configured language sites and generate links for each site with language name, icon, or Emoji.Users click on these links to jump to the corresponding language site.

In addition, to better internationalize SEO, it is strongly recommended that you specify the corresponding language version of the current page in each page.<head>Area additionhreflangTag, indicating the other language version corresponding to the current page. This can be achieved in the following way:

<head>
    {# 其他head内容 #}
    {%- languages websites %}
    {%- for item in websites %}
    <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
    {%- endfor %}
    {%- endlanguages %}
</head>

hreflangThe tag tells search engines that your website has multiple language versions and specifies the URL of each version, which is crucial for avoiding duplicate content issues and guiding users to the correct language version page.

Summary

AnQiCMS distinguishes between system-built text and user-generated content, providing a flexible and efficient multilingual solution. It utilizeslocalesTable of contents and{% tr %}The tag can easily handle the translation of static text in templates, and combined with the powerful "Multi-site Management" feature, it can build clear and independent language versions of your core content website. Accompanied by the language switcher in the template andhreflangLabel, your AnQiCMS website will be able to seamlessly serve global users, helping your business go international.

Frequently Asked Questions (FAQ)

Can I provide multiple language versions for an article on the same AnQiCMS site?

The core design concept of AnQiCMS is to use multi-site management for multilingual content. This means that, in most cases, you would create an independent site for each language (for exampleen.yourdomain.comandfr.yourdomain.comThen publish articles in that language at each site.Although it is possible to hardcode multiple language texts in the same article content field and display them through frontend logic, this is not recommended as it makes content management complex and不利于 SEO.The multi-site mode provides a clearer, more maintainable solution.

How to ensure the SEO effect of a multilingual website?

Firstly, providing a separate URL for each language (such as through subdomains or subdirectories) is fundamental. Secondly, be sure to have each page<head>area.hreflangLabel, clearly inform the search engine of the other language versions and corresponding URLs.Ensure that each language version of the content is high quality and unique, avoiding simple machine translation.At the same time, conduct keyword research and localization content optimization for different target language markets, and configure independent TDK (title, description, keywords) and pseudo-static rules in each language version.

3. Can I translate a few fixed words on my website without setting up a full multilingual site?

Absolutely. If you only need to translate a few fixed words in the template, and the user's core content (articles, etc.) is still in a single language, then you just need to use{% tr "key" %}Translate labels andlocalesThe language package mechanism is sufficient. You can only create language package files containing these fixed word translations (for exampleen-us/default.yml), and use them in the template.

Related articles

How to configure a separate domain and database information for a new site in AnQiCMS multi-site management?

AnQiCMS with its efficient and flexible multi-site management function provides great convenience to users, especially in scenarios where independent sites need to be built for different brands, products, or services.When you want to configure a separate domain and database information for a new site, AnQiCMS provides a clear and practical management process.This not only helps to isolate and secure the data, but also allows each site to have more independent operation and optimization space.### Understand the value of independent configuration for multiple sites Before discussing the specific operations

2025-11-08

How to configure the pseudo-static rules in AnQiCMS to optimize URL structure and include categories, model aliases?

Building a clear, search engine-friendly URL structure in AnQiCMS is a very important aspect of website operation.By reasonably configuring the pseudo-static rules and cleverly integrating categories and model aliases, not only can it enhance the user experience, but it can also significantly optimize the website's SEO performance.AnQiCMS as a high-performance content management system provides flexible pseudo-static features, allowing us to easily achieve these goals.The importance of optimizing URL structure Imagine you visit a website and see this kind of link: `example

2025-11-08

How does AnQiCMS's 'Full Site Content Replacement' feature efficiently handle content strategy adjustments?

Today, with the increasing refinement and diverse strategies of content operation, how to adjust website content efficiently and accurately is a challenge facing every website operator.When brand information is updated, external link adjustments, or SEO strategy iterations occur, manually modifying thousands of contents on the website one by one is not only time-consuming and labor-intensive, but also prone to errors.Fortunately, AnQiCMS provides an extremely powerful tool - the "Full Site Content Replacement" feature, which can help operators with amazing efficiency and accuracy to deal with various content updates and strategy adjustments, and become a "secret weapon" for content management strategy adjustments.###

2025-11-08

How to define and use custom variables in AnQiCMS templates, such as the `{% with %}` tag?

In the template design of AnQi CMS, we often encounter scenarios where we need to temporarily store or pass data.In order to make the template code clearer, easier to read, and more powerful, AnQi CMS provides the mechanism for defining and using custom variables, the most commonly used of which are the `{% with %}` tag and the `{% set %}` tag.They can help us handle data flexibly in templates, avoiding repeated calculations or passing complex objects.

2025-11-08

How does AnQiCMS increase the level of content operation automation through the timed publishing function?

Today, with the increasing emphasis on efficiency and user experience, the degree of automation in content operation is directly related to the competitiveness of the website.For many small and medium-sized enterprises and self-media operators, how to ensure high-quality, frequent, and precise targeting of content under limited human resources is a continuous challenge.AnQiCMS is an efficient and flexible content management system, and its built-in timed publishing function exactly provides strong support for solving this problem.Imagine such a scenario: You have meticulously planned marketing content for a week or even a month, including articles, product updates, and event previews.

2025-11-08

How to get the global configuration information of AnQiCMS template, such as the website name and logo?

In AnQiCMS template, cleverly obtain the global configuration of the website to make your website more flexible When designing or maintaining an AnQiCMS website template, we often encounter a need: to display unified global information on each page of the website, such as the name of the website, logo, filing number, or custom contact information.Manually adding this information to each page is not only inefficient but also time-consuming and laborious to update once it needs to be changed.

2025-11-08

How to filter the document list based on category ID, model ID, or recommendation attributes for the `archiveList` tag?

In AnQiCMS, flexibly displaying content is one of the keys to building an efficient website.The `archiveList` tag is such a powerful tool that allows us to filter and display the document list of the website based on various conditions.Whether you want to display a certain type of article on a specific page, or organize information based on content type or editor's recommendations, `archiveList` can provide precise control.### Accurate positioning: Filter document list by category ID When we want to display in a certain area of the website, such as the sidebar or a special topic page

2025-11-08

How to create a multi-level category navigation and display its subcategories or related documents in AnQiCMS template?

Build flexible multi-level category navigation and content display in AnQiCMS template Effective organization of website content is crucial for providing a good user experience and improving search engine visibility.Whether it is a corporate website, product display, or self-media blog, a clear multi-level classification navigation can help users quickly find the information they need and is also conducive to search engines understanding the structure of the website.AnQiCMS as an efficient and customizable content management system provides flexible template tags, allowing us to easily implement complex multi-level classification navigation and content display. Next

2025-11-08