How to implement language switching functionality for multilingual sites in Anqi CMS?

Calendar 👁️ 88

When our website aims to serve global customers, providing multilingual support becomes an indispensable function.This not only helps us expand the international market, but also significantly improves the access experience for users of different languages.AnQiCMS (AnQiCMS) understands this need and therefore makes multilingual support one of its core highlights, allowing us to easily build and switch between multilingual websites.

How to implement language switching for multilingual sites in Anqi CMS

To implement language switching for multilingual websites, it mainly involves backend configuration and integration of frontend templates.AnQiCMS provides a simple and efficient solution, making technical details easy to understand and operate.

Backend multilingual site configuration: Build language foundation

First, in the AnqCMS backend, we can find the multi-language related settings.Although the "default language pack" in the document mainly refers to the language of the backend management interface, it implies that the system supports a multilingual environment.For the multilingual versions of the content itself on the website, it is usually to create different language versions of the same article, product, or page at the time of content publication.For example, you can publish a Chinese article and then create its corresponding English, French, or Japanese version and associate it.

Further, the "Multi-site Management" feature of AnQiCMS also provides great flexibility for multilingual sites. You can set up independent subdomains for each language version (such asen.example.com/fr.example.com) or subdirectory (such asexample.com/en//example.com/fr/They are configured as independent sites, but all managed by the same AnQiCMS instance.This pattern helps to implement more fine-grained language content and URL structure management.

Front-end language switcher: Let users choose easily

Let users switch between languages easily, which is the key to a multilingual website experience. AnQiCMS provides a namedlanguagesThe template tag is specifically used to retrieve the list of all configured multilingual sites.By this tag, we can build an intuitive language switcher at any location on the website (usually in the header or footer).

UselanguagesThe label is very simple, it returns an array containing information about all language sites, and we can iterate through this information to generate a switch link for each language:

{%- 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 %}

In this code block,item.LinkThe link will automatically direct to the link under the corresponding language on the current page, anditem.LanguageName/item.LanguageEmojianditem.LanguageIconLanguage names, emoticons and icons are provided separately, making it convenient to design beautiful and easily recognizable language switch buttons.

Template text translation: Details determine the experience.

In addition to the main content and pages, many fixed texts in the website template, such as navigation menu items, footer statements, form prompts, and button texts, also need to be displayed according to the current language. AnQiCMS throughtr(translate) tag andlocalesThe directory has implemented this function.

You need to create one under the template directory.localesFolder, and create a corresponding language package file for each language (for exampleen-us/default.yml/zh-cn/default.ymlThese YAML files will store key-value pairs, where the key is the identifier you use in the template, and the value is the corresponding translation text.

For example, in a Chinese language package (locales/zh-cn/default.yml):

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

In the template, you can usetrtags to call these translated texts:

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

The system will automatically load when the user switches to Englishen-us/default.ymlThe corresponding translation is used to achieve seamless switching of static text in the template.

Search Engine Optimization (SEO):hreflangThe importance of tags

For a multilingual website, it is crucial to inform search engines of the corresponding relationship between different language version pages, as this can avoid the penalty for duplicate content and ensure that search engines display the correct language pages to users in the correct regions. AnQiCMS integrateslanguagesTags can help us easily generatehreflang.

You just need to place the following code block in the website template's<head>area:

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

This code will generate a tag for each language version<link rel="alternate" hreflang="xx" href="yyy">whereitem.Languageis a language code (such asen/zh-CN)item.LinkThis is the complete URL of the corresponding language page. This can effectively improve the performance of the website in international search engines.

Some considerations in actual operation.

When deploying a multilingual site, in addition to the above technical implementations, there are also some operational considerations:

  • URL structure selection: AnQiCMS's 'Static Rules' and 'Multi-site Management' provide great flexibility. You can choose subdirectories such asexample.com/en/) or subdomain (such asen.example.comAs a multilingual URL structure. Both methods have their pros and cons, usually subdirectories are more suitable for the same brand's multilingual content, while subdomains are more suitable for providing differentiated content for different regional markets.
  • Content Management ProcessMake sure the content team can create all target language versions in time when publishing new content.AnQiCMS' content model and content management features should well support this process, for example, providing language version switching options when editing articles.
  • Consistency: Regardless of language switching, the brand image, design style, and core information of the website should remain consistent.

AnQiCMS with its built-in multilingual support and flexible template tags, provides us

Related articles

How to create pagination navigation for document lists, Tag lists, and other Anqi CMS features?

In website operation, providing clear and easy-to-use pagination navigation for content lists not only greatly improves user experience but also optimizes search engine crawling efficiency, helping content to be discovered better.AnQiCMS (AnQiCMS) knows this and therefore provides powerful and flexible pagination tags in template design, allowing content operators to easily create pagination navigation for document lists, tag lists, and so on. We will discuss together how to implement this feature in AnQi CMS templates, organizing your website content neatly.--- ###

2025-11-08

How to generate and display the breadcrumb navigation of the current page in Anqi CMS

When we browse websites, we often see a line at the top or bottom of the page indicating the current location path, such as “Home > Product Category > Electronic Products > Laptop”.This is what we commonly call 'breadcrumb navigation', which not only clearly informs us of our location but also makes it convenient for us to quickly return to the previous level page, greatly enhancing the website's user experience and navigation efficiency.In Anqi CMS, implementing and displaying breadcrumb navigation is a very easy thing to do.The system is built-in with special template tags that can intelligently adapt to the content structure of the current page

2025-11-08

How to set and display the TDK (Title, Description, Keywords) on the homepage of Anqi CMS?

In website operation, TDK (Title, Description, Keywords) play a crucial role, they are the first window for search engines to understand the content of the website, directly affecting the visibility and click-through rate of the website in search results.An optimally optimized TDK can not only improve the website's SEO performance but also accurately convey the core value of the website to potential visitors.AnQiCMS is a content management system that focuses on SEO optimization, providing users with a convenient and efficient way to set up and manage the TDK of the homepage.

2025-11-08

How to retrieve and display the contact information, phone number, address, and email of the website?

In website operation, a clear and easily searchable contact method is a key factor in building user trust and promoting communication conversion.Whether you are seeking a partner for cooperation or a user in need of help, you can quickly find you through the contact information provided on the website.AnQiCMS provides flexible and convenient functions for managing and displaying contact information, allowing you to easily obtain and display various contact information such as contacts, phone numbers, addresses, and email addresses.

2025-11-08

How to display the Banner slideshow image on the homepage or a specific group?

The homepage and banner carousel images of specific groups, which are key elements in attracting visitors and displaying core content on the website.A convenient and flexible system for management and display, which can greatly improve the operation of your website.AnQiCMS (AnQiCMS) takes advantage of its intuitive design and powerful template tag features, allowing you to effortlessly handle these visual elements, whether it's creating an eye-catching homepage image or customizing exclusive promotional images for specific category pages, you can do so with ease.

2025-11-08

How to customize or override the JSON-LD structured data in AnQi CMS?

The AnQi CMS has always been committed to providing efficient and flexible solutions in content operation and search engine optimization.Structured data, especially JSON-LD, is an important means to improve the visibility of website content in search engines.It can help search engines understand the page content more accurately, thereby giving it the opportunity to display richer search results (i.e., rich media summaries) and attract more users to click. AnQi CMS understands the importance of structured data, and has preset some default JSON-LD structured data for you in the system design.

2025-11-08

How to obtain the background custom global parameters in the template?

In AnQi CMS, the flexibility and maintainability of the website are one of its core advantages.Content operators and developers often need to dynamically adjust some global information of the website without modifying the template code, such as the company name, contact number, and even some marketing campaign links.These are the background custom global parameters that are the key to achieving this requirement.Today, let's delve into how to easily obtain and display these custom global parameters configured in the Anqi CMS template.### Why do we need global parameters? Imagine that

2025-11-08

How to display the current year or a specified format of time in the template?

In website operation, it is often necessary to keep the web page content up-to-date or accurately display the time of specific events, whether it is the copyright year in the footer, the publication date of the article, or the update time of the product. These dynamic time information can make the website look more professional and active.AnQiCMS provides a very flexible and intuitive way, allowing you to easily display the current year or specify the format of time in templates. Next, we will explore two main methods together, allowing your AnQiCMS website to flexibly display various time information.## One

2025-11-08