How can language switch links be displayed in multilingual sites?

Calendar 👁️ 91

Build a website for global users, multilingual support is an indispensable part.AnQiCMS was well thought out from the beginning, providing a powerful and flexible solution for the publication and management of multilingual content.By making some simple configuration and template adjustments, we can easily implement language switching functionality on the website, allowing users of different languages to smoothly browse the website content.

AnQiCMS Multilingual Capabilities

AnQiCMS is inherently equipped with excellent multilingual content management capabilities, mainly due to its flexible "multi-site management" and "default language package" design.It not only supports the creation of independent sites for each language version, ensuring the independence of content, URL structure, and SEO strategy, but also built-in multiple language packages, convenient for localizing the back-end interface and system prompts.This means we can manage the Chinese version, English version, French version, etc. of the website as separate sites, each with its own content, templates, and even independent domains or subdomains, while AnQiCMS coordinates in the background.

Core: Language Switch Link Display

To display the language switch link on the website front-end, AnQiCMS provides a very convenient template tag:languages. This tag helps us to get all the multilingual site information that is configured, and then through the loop of this information, dynamically generate language switch links.

Basic usage method:

We usually place the language switch function at the top (Header) or bottom (Footer) of the website, etc., public areas, so the relevant code is placed in the public part of the template file (for examplebase.htmlorpartial/header.htmlIt would be appropriate.

Here is an example of code to create a language switch link.

{%- languages websites %}
{%- if websites %}
<nav class="language-switcher">
    <ul>
        {%- for item in websites %}
        <li {% if item.IsCurrent %}class="active"{% endif %}>
            <a href="{{item.Link}}" {% if item.Nofollow %}rel="nofollow"{% endif %}>
                {%- if item.LanguageIcon %}
                <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}">
                {%- else %}
                {{item.LanguageEmoji}}
                {% endif %}
                {{item.LanguageName}}
            </a>
        </li>
        {%- endfor %}
    </ul>
</nav>
{%- endif %}
{%- endlanguages %}

In this code block:

  • {% languages websites %}This tag will traverse all language sites configured in the AnQiCMS backend and assign their data towebsitesVariable.
  • {% for item in websites %}We loop throughwebsitesto process the information of each language site one by one.
  • item.LinkThis will output the URL of the current language site, and the user can click to jump to the corresponding language version.
  • item.LanguageName: Display the name of the language site, for example, "Simplified Chinese" or "English".
  • item.LanguageIconoritem.LanguageEmoji: If the background is configured with a national flag icon or Unicode emoji for the language, the icon will be displayed first, followed by the emoji, providing users with a more intuitive switching method.
  • item.IsCurrentA boolean value indicating whether the current language being cycled through is the language being visited by the user, which can be used to add a link for the current languageactiveStyle.
  • item.NofollowA boolean value indicating whether to add a link for the current onerel="nofollow"The attribute, which is very useful for SEO control of certain links that you do not want to pass weight.

Through this code, the website front-end can automatically generate a set of language switch links based on the backend configuration, and can flexibly display language names, national flags, or emojis.

Multilingual SEO: Hreflang Tag

To help search engines better understand the multilingual versions of a website and display them to the correct users, configurationhreflangTags are crucial.hreflangTags can tell search engines that the content under different URLs is a substitute version of the same content, just for different languages or regions.

In AnQiCMS, we can combinelanguagestags, easily in the website<head>these in the partshreflang.

Hreflang tag example:

Place the following code snippet in the website template's<head>area (usuallybase.html):

{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}
  • item.LanguageThis field outputs the language code of the language site (e.g., 'zh-CN' or 'en'), and the search engine will judge the language and target region based on this code.

This way, each language version of the website will include links to all other language versionshreflangto ensure that search engines can accurately index and display them.

Implementation steps

To implement the above function, the following configuration is usually required:

  1. Backend site configuration:

    • Create a multilingual site:In the AnQiCMS backend's 'Multi-site Management' module, create an independent site for each target language. For example, you can create a Chinese site (www.example.com)and an English site(en.example.comorwww.example.com/en/Make sure to set the site name, website address, and most importantly the 'default language package' (which can be selected under 'Global Settings' -> 'System Settings') when creating a site.
    • Configure language information:In each site's “Global Settings” -> “System Settings”, in addition to setting up the “Default Language Pack”, you can also upload a “Language Icon” (flag, etc.) for the language site or select a “Language Emoji”, this information will be transmitted throughlanguagesLabels are automatically provided to the frontend for use.
  2. Frontend template integration:

    • Edit the template file:Find the current template file your website is using, for example, located in/template/你的模板目录/base.html.
    • Insert language switch code:Translate the language switch link code (first section) abovelanguagesPaste the example label) where you want to display the language switcher, for example in<header>or within tags.<footer>Tag inside.
    • Insert Hreflang code:Translate the above hreflangLabel code (second paragraph)languagesPaste the label example to<head>Inside the label, usually placed<title>After the label or all<meta>the tag afterward.

After completing these steps, clear the website cache, visit your website, and you will see the configured language switch links, and search engines will also better understand the structure of your multilingual website.

Frequently Asked Questions (FAQ)

  1. Q: Is the translation of the website content automatic? Or does it need to be manually processed? A:AnQiCMS itself does not automatically translate content. You need to manually create or import the corresponding language version of the content under each language site.For example, if you have a Chinese version of the "About Us" page, then on the English site, you need to create an English version of the "About Us" page and make sure the content is in English.AnQiCMS site management provides convenience, you can independently edit content for each language version.

  2. Q: Can I use flag icons to represent languages instead of text? A:Absolutely. On top of that

Related articles

How to enable and display captcha in the comment or message form?

In website operation, the message and comment functions are important channels for interacting with users and collecting feedback.However, this is often accompanied by the困扰 of spam and malicious flooding.To effectively filter out this unnecessary content, enabling the captcha mechanism has become a simple and efficient solution.AnQiCMS (AnQiCMS) provides us with a flexible way to easily integrate captcha functionality into comment or message forms. Next, we will learn in detail how to enable and display the captcha in Anqi CMS.### Step 1: Turn on captcha feature in the management background First

2025-11-08

How to add structured data (JSON-LD) in the HTML header to improve search result display?

In today's highly competitive online environment, it is crucial to make your website content stand out in search engine results pages.In addition to high-quality content and an excellent keyword strategy, structured data (especially in JSON-LD format) plays an increasingly important role.It can help search engines understand the information on your page more accurately, so that your content may be displayed in richer, more attractive forms in search results (such as rich media summaries, i.e., Rich Snippets).What is JSON-LD and why should it be used

2025-11-08

How to deploy multiple AnQiCMS sites on the same server and ensure their independent display?

Deploying multiple websites on the same server while ensuring that they run and display independently is a common need for many content operators.For AnQiCMS users, this is not only feasible but also very efficient.The Anqi CMS leverages its powerful multi-site management features, allowing you to easily manage multiple brand sites, sub-sites, or content branches with just one core program.Next, we will discuss in detail how to deploy and manage multiple security CMS sites cleverly on the same server, so that they operate independently without interfering with each other.### Core Concept

2025-11-08

How to display the current year or other system time information in the template?

In website operation, keeping your content up-to-date in real-time, especially information like the year or date of system time, can not only enhance the professionalism of the website but also provide users with more accurate references.AnQiCMS as a flexible and efficient content management system provides a variety of convenient ways for you to easily implement this requirement. Next, let's learn how to flexibly display the current year or other system time information in the AnQiCMS template.### Display the current system time——`{% now %}`

2025-11-08

How to display a user or user group in the template

In AnQi CMS template design, it is crucial to be able to flexibly display user or user group information, which is essential for building personalized, interactive website experiences.AnQi CMS provides intuitive and powerful template tags, allowing you to easily display rich information such as users' profiles and user groups on the front end of the website, thereby enhancing user engagement and the professionalism of the website.Whether you want to display the user's nickname and membership level in the article comment area or show specific content and features based on the user's identity or group, Anqi CMS provides the `userDetail` and

2025-11-08

How can you accurately convert a numeric string to a floating-point number in the Anqi CMS template?

In AnQi CMS template development, we often need to handle various types of data, where the conversion between numeric strings and floating-point numbers is a common and important requirement.For example, you may get a custom field from the background, such as a price (like "12.50"), or a numeric product inventory (like "100"), when performing mathematical operations, comparing sizes, or displaying in a specific format in the template, it is particularly important to convert it from a string type to a floating-point number accurately

2025-11-08

What value will the `float` filter return when encountering a non-numeric string?

In AnQi CMS template development, filters are an important tool for processing and formatting data.They can help us present the data passed from the backend in a way that is more in line with the front-end display requirements.Among them, the `float` filter is specifically used to convert numbers to floating-point format.However, when it encounters a non-numeric string, its behavior becomes particularly critical because it directly affects the accuracy of the template output and the stability of the program.The core function of the `float` filter is to convert the input value to a floating-point number type

2025-11-08

How does AnQiCMS convert user input numeric text to integer type?

In website content management, we often encounter situations where we need to handle digital information, such as product inventory quantities, article reading volumes, and ages submitted by users, etc.These numbers may exist in text form during back-end entry, but when it comes to actual calculations, sorting, or display, we need to ensure that they are true numeric types, not mere text strings.AnQiCMS as a rich-featured enterprise-level content management system, fully considering this point, has provided us with a flexible solution to deal with the need for this kind of data type conversion.###

2025-11-08