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

Calendar 👁️ 88

Today, having a website that supports multiple languages has become a key factor for enterprises to expand into international markets and enhance user experience.AnQiCMS is an efficient and flexible content management system that fully considers this requirement, providing you with a convenient multi-language content switching and display solution.

Different from simply piling up multiple languages on the same page, AnQiCMS adopts a more flexible and powerful multi-site management mode to implement multi-language support.This means that you can create an independent website for each target language, which shares the core system of AnQiCMS, but the content, settings, and even domain names can be independently configured to better meet the personalized needs of users in different languages.

Below, we will explore how to easily handle the switching and display of multilingual content in AnQiCMS.

Step 1: Build the basic architecture of a multilingual site.

The core of implementing multilingual content switching lies in the "Multi-site Management" function of AnQiCMS.You can treat different language versions as different sites, each independently operated, but managed uniformly through AnQiCMS.

  1. Create an independent language site in the background:
    • First, log in to your AnQiCMS main site backend.
    • Find the "Multi-site Management" feature entry and click "Add New Site".
    • Create a new site for each target language. For example, if your main site is in Chinese and you now want to add an English version, you can create a new site named 'English Site'.
    • During the creation process, you need to configure the following key information for the new site:
      • Site nameis used to distinguish different language sites.
      • Site root directorySpecify an independent directory path to store the cache and other data for the language site.
      • website address: This is the access URL of the language version site. You can choose a different domain (such asen.yourdomain.com) or a subdirectory (such asyourdomain.com/en/To implement this, it usually requires the reverse proxy configuration of a server (such as Nginx or Apache) to work with the port mapping of AnQiCMS's Go project.
      • Administrator account password: Set independent backend management credentials for the new site.
      • Database name: It is recommended to configure an independent database for each language site to ensure complete isolation of content and data, avoiding confusion.
      • Default language packageThis is an important step, select the corresponding language package for the new site (for example, 'English site' selects 'English').This will affect the display of built-in text in the AnQiCMS system, such as the back-end interface, certain system prompts, etc.Please note that this will not automatically translate the actual content of your website, articles, products, etc.

After completing these configurations, you will have a new, independent language site. Repeat this step to create more language versions of the site.

Step 2: Publish and manage multilingual content

After each language site is created, you can manage the corresponding language content in the respective backend just like any other website.

  1. Publish content independently:
    • Log in to the backend of the site you created for a specific language (for example, the backend of the English site).
    • Publish all the articles, products, single pages, and other content you want to display in that language under the site.
    • Ensure that all text, image descriptions, SEO titles, keywords, and descriptions are written in this language to provide a high-quality localized experience.
  2. Maintain consistency and synchronization of the content.:
    • Although the content is independently managed, you may want different language versions of the content to be consistent in terms of theme and structure.For example, a Chinese article about 'Company Profile' should also have an English version.
    • AnQiCMS does not have built-in automatic translation or content association features, therefore, consistency of the content needs to be ensured by you through manual maintenance or internal workflows.

Step 3: Optimize language switching and display on the front-end

To allow users to easily switch between different language versions and improve the search engine's recognition of multilingual content, you need to adapt the website template.

  1. Integrated language switch function:tag-/anqiapi-other/10537.htmlIntroduced in the document{% languages websites %}The tag is the key to language switching. This tag can retrieve all the multi-language site information you have configured in AnQiCMS.

    You can add a piece of code to dynamically generate a language switch link in a prominent position on the website's header or footer:

    {%- languages websites %}
    {%- if websites %}
    <div class="language-switcher">
        <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 through all configured language sites and generate a link for each site, the link text can be the name of the language, and next to it, you can display the corresponding national flag icon or Emoji expression to enhance the visual effect.

  2. Translate the fixed text in the template: In addition to the content you publish on the website template, there are many navigation menus, buttons, copyright information, and other fixed texts. In order for them to change according to the current language settings of the site, AnQiCMS provides translation tags{% tr "关键词" %}.

    • Create language file: Under your template directory, create a folder namedlocales. Then in thelocalesfolder, create a subfolder for each language (for examplezh-cnwhich represents Simplified Chinese, en-usRepresents American English) and create one in each subfolderdefault.ymlfile. For example,locales/zh-cn/default.yml:
      
      yourLocation: "您的位置"
      home: "首页"
      contactUs: "联系我们"
      
      locales/en-us/default.yml:
      
      yourLocation: "Your Location"
      home: "Home"
      contactUs: "Contact Us"
      
    • Use translation tags in the template:
      
      <nav>
          <a href="/">{% tr "home" %}</a>
          <a href="/contact">{% tr "contactUs" %}</a>
      </nav>
      <p>{% tr "yourLocation" %}:XXX</p>
      
      when the user visits the Chinese site,{% tr "home" %}The page will display "Home"; when accessing the English site, it will display "Home".
  3. Enhance search engine friendliness (Hreflang tag)To help search engines better understand the multilingual of your website

Related articles

How to display the path of static files (CSS/JS/images) in AnQiCMS template?

When building a website with AnQiCMS, the correct reference to static files (such as CSS stylesheets, JavaScript scripts, and images) is the basis for ensuring the normal operation and beautiful presentation of the website.AnQiCMS provides us with a clear and flexible mechanism for managing and displaying these file paths, whether it is the static resources built into the template or the media files uploaded through the backend, there is a convenient way to reference them.

2025-11-08

How to display the mobile URL of the website in AnQiCMS template?

When using AnQiCMS to build and manage websites, many friends may encounter such a need: If the website has an independent mobile version, how can you conveniently obtain and display the URL of this mobile website in the template?This makes it convenient for users to switch between different devices, and it also has a positive impact on search engine optimization (SEO).Don't worry, AnQiCMS provides a very intuitive way to achieve this.Why do we need to display the mobile URL in the template?First, let's talk about why there is such a need

2025-11-08

How to use AnQiCMS filters to truncate or convert text to uppercase and lowercase?

AnQiCMS provides powerful flexibility in content display, its template engine is built-in with a rich set of filters, helping users to easily process text without modifying the original content, including truncation and case conversion.These filters make the presentation of front-end content more accurate and beautiful, meeting the display needs of different scenarios.In AnQiCMS template syntax, the use of filters is very intuitive.You can apply a filter by adding a pipe symbol (`|`) after the variable name, if the filter requires parameters, then use a colon (`:`) after the filter name

2025-11-08

How to use a for loop to traverse data and display it in the AnQiCMS template?

AnQiCMS with its flexible and powerful template system makes content display efficient and expressive.For website operators and developers, mastering how to traverse and display data in templates is a key step to unlocking their powerful features and bringing the website content to life.Today, let's delve into how to use the `for` loop in AnQiCMS templates to easily present your dynamic data.AnQiCMS's template engine adopts syntax similar to Django, which allows users familiar with other mainstream template languages to quickly get started.

2025-11-08

How does AnQiCMS control the display and hiding of content based on user group permissions?

When building and operating a website, we often encounter such needs: some content is intended for everyone to see, while others are designed specifically for certain user groups, such as paid membership exclusive, VIP content, or materials for internal team review.AnQiCMS provides a powerful and flexible user group permission control mechanism that can help us easily achieve fine-grained display and hide of content.

2025-11-08

How to display data of custom content models (such as products, events) in AnQiCMS?

Manage and display custom content models in Anqi CMS, such as product lists, event details, etc., which is a reflection of its powerful flexibility.The design philosophy of AnQi CMS aims to allow users to highly customize the content structure according to their own business needs and present these structured data in a直观, rich manner on the website front-end. ### The Foundation of Flexible Content Models Firstly, we need to understand the "Flexible Content Model" feature of Anqi CMS. It allows you to go beyond the traditional 'article' category, creating content types with unique fields. For example

2025-11-08

How to set image watermark in AnQiCMS to protect the display of original content?

In the era of content is king, protecting the copyright of original works becomes increasingly important, especially for image content on websites.AnQiCMS (AnQiCMS) understands this and provides content creators with image watermarking features to help them effectively maintain their original rights while displaying beautiful images. ### Easily Protect Original Content: A Practical Guide to Setting Image Watermarks in AnQiCMS When your meticulously crafted images are spread across the internet, adding watermarks is undoubtedly one of the most direct and effective ways to make a copyright declaration.

2025-11-08

How does AnQiCMS display website traffic statistics and crawler scraping information?

During the operation of a website, a comprehensive understanding of the website's access situation and interaction with search engines is the key to improving website performance.AnQiCMS (AnQiCMS) understands this point and therefore provides a set of built-in traffic statistics and crawler monitoring functions to help us intuitively grasp the operation status of the website, thereby making more intelligent operational decisions.In the AnQiCMS backend management interface, this data is concentrated in the "Data Statistics" function module.

2025-11-08