How to judge whether the current page is in a multilingual site environment in AnQiCMS template?

Calendar 👁️ 91

As an experienced website operations expert, I am well aware of the importance of how templates intelligently adapt to different language versions in a multilingual site environment.AnQiCMS is an enterprise-level content management system developed based on the Go language, and its powerful multilingual and multi-site management features are the key tools for us to achieve this goal.Judging the current language environment of the page accurately in the template can not only optimize the user experience but also greatly improve the SEO performance and content operation efficiency of the website.

Today, let's delve deeply into how to cleverly and accurately judge whether the current page is in a multilingual site environment in the AnQiCMS template, and how to combine practical application scenarios to transform these technical points into practical content operation strategies.


Adaptable to a global audience: The way AnQiCMS determines its multilingual site

AnQiCMS was designed with the need for global content promotion in mind, one of its core highlights being the seamless integration of 'multilingual support' and 'multi-site management'.This means you can easily create independent sites for different language audiences or different language versions of the same site, and manage them uniformly through a single system.But having these features is not enough, the key is how our template can intelligently 'perceive' which language version the current user is visiting, thereby dynamically adjusting the displayed content, loading specific resources, and even providing appropriate language switching options.

In the AnQiCMS template system, the language environment of the current page can mainly be determined by the following two core tags: systemTags andlanguagesTags. They are like the 'eyes' of a template, able to perceive the language status of the current site and the available multilingual options.

Core Tool One:systemTag - Get the language information of the current site

systemThe tag is the universal key to obtain the global system configuration information in AnQiCMS templates, which includes the language settings of the current site.By this tag, we can directly obtain the language code used by the current page, which is usually the most direct and effective way to judge the current language environment.

When you call in the template{% system with name="Language" %}When it returns, it will return the language code configured in the background "Global Function Settings" of the current site, for examplezh-cn(Simplified Chinese),en-us(American English) orja(Japanese) and others.

With this language code, we can make conditional judgments in the template and display differentiated content according to different language codes.For example, if the current language is English, we can load an English version of the JS library;If it is in Chinese, then display Chinese-specific promotional phrases. This approach greatly enhances the adaptability of the template, avoiding the need to create a completely different template for each language version, greatly simplifying maintenance work.

Core Tool Two:languagesTag - Insight into all multilingual site overviews

In addition to getting the language of the current page, sometimes we also need to understand which multilingual sites are configured in the entire AnQiCMS system, for example, by providing a language switcher at the bottom of the page. At this time,languagesthe label comes into play.

{% languages websites %}This tag can get the list of all multilingual sites configured under the current AnQiCMS project.It returns an array object, where each element represents a language site and includes the site's language name, language code, link address, and even the corresponding emoji or icon.

By traversing thiswebsitesArray, we can not only know which languages the current system supports, but also dynamically generate language switching links.For example, you can create a dropdown menu at the top or bottom of the page so that visitors can easily switch to other language versions according to their needs.This is crucial for enhancing user experience and website accessibility.

Transform technology into practical strategies: Multilingual application practice in templates

Understood the working principle of these two tags, we can build flexible and versatile multilingual adaptation logic in the AnQiCMS template.

1. Load different resources or display specific content based on the current language code:

Assuming your website has two versions in Chinese and English, you may want to load a special font file on the Chinese site, or load another one on the English site, or display promotional images in different languages at some ad positions.

{# 获取当前站点的语言代码 #}
{%- system currentLang with name="Language" %}

<head>
    <meta charset="UTF-8">
    <title>{% tdk with name="Title" siteName=true %}</title>
    {# ... 其他通用head内容 ... #}

    {%- if currentLang == "en-us" %}
        {# 英文站专属样式或JS #}
        <link rel="stylesheet" href="{{ system.TemplateUrl }}/css/en-specific.css">
        <script src="{{ system.TemplateUrl }}/js/en-analytics.js"></script>
    {%- elif currentLang == "zh-cn" %}
        {# 中文站专属样式或JS #}
        <link rel="stylesheet" href="{{ system.TemplateUrl }}/css/zh-specific.css">
        <script src="{{ system.TemplateUrl }}/js/zh-analytics.js"></script>
    {%- else %}
        {# 默认或Fallback样式/JS #}
        <link rel="stylesheet" href="{{ system.TemplateUrl }}/css/default.css">
    {%- endif %}
</head>
<body>
    {# ... 页面主体内容 ... #}

    {%- if currentLang == "en-us" %}
        <p>This content is specifically for our English audience.</p>
    {%- elif currentLang == "zh-cn" %}
        <p>此内容专为我们的中文读者呈现。</p>
    {%- endif %}

    {# ... 其他页面元素 ... #}
</body>

2. Dynamically build a multilingual switcher:

Provide an intuitive language switch option, which is a basic requirement for a multilingual website. Uselanguagestags, we can easily achieve this.

{# 获取当前站点的语言代码,用于判断当前激活状态 #}
{%- system currentLang with name="Language" %}

{%- languages websites %}
{%- if websites|length > 1 %} {# 只有当存在多于一个语言站点时,才显示切换器 #}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" class="language-option {% if currentLang == item.Language %}active{% endif %}">
        {%- if item.LanguageIcon %} {# 优先显示后台配置的语言图标 #}
            <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}">
        {%- else %} {# 如果没有图标,则显示语言表情符号 #}
            {{item.LanguageEmoji}}
        {% endif %}
        {{item.LanguageName}}
    </a>
    {%- endfor %}
</div>
{%- endif %}
{%- endlanguages %}

3. Add SEO crucially importanthreflangTags:

hreflangTags can tell search engines that your website has content in different languages or regional versions, which is crucial for avoiding duplicate content penalties and ensuring that search engines display the correct content to the right users.

`twig

{# ... 其他head内容 ... #}
{%- languages websites %}

Related articles

How to call language data from other sites in the AnQiCMS multi-site environment?

## Seamless Cross-Site Language Data Calling: AnQiCMS Content Operation Tool for Multi-Site Environment As an expert well-versed in website operations, I am fully aware of the challenges faced in managing content in multi-site, multi-language environments.Complex repetitive tasks, the trouble of data synchronization often make operators feel overwhelmed.However, AnQiCMS, with its powerful multi-site management and multi-language support capabilities, provides us with a graceful and efficient solution.

2025-11-06

What is the role of the `siteId` parameter in AnQiCMS's multi-site management?

As an experienced website operations expert, I have a deep understanding of the powerful functions of AnQiCMS in actual operation, especially the exquisite design in multi-site management.Today, let's delve deeply into a seemingly minor but crucial parameter in AnQiCMS multi-site management, `siteId`. What role does it play, and how can we fully utilize it to optimize our content operation strategies.--- ### The core role and practice of the `siteId` parameter in AnQiCMS multi-site management AnQiCMS

2025-11-06

How to get the configuration information of different multilingual sites using the `system` tag?

## The Anqi CMS Multilingual Site Operation Manual: Skillfully Using `system` Tags to Retrieve Configuration Information As a senior website operator, we are well aware that efficient content management and flexible configuration adjustments are the keys to success in the ever-changing network environment.AnQiCMS is an enterprise-level content management system developed based on the Go language, which provides us with great convenience with its powerful multi-site and multi-language support.Today, let's delve deeply into a seemingly simple but powerful template tag in AnQiCMS——`system`

2025-11-06

How does the `SiteName` field in AnQiCMS support multilingual title display?

Good, as an experienced website operation expert, I am happy to delve deeply into how the `SiteName` field in AnQiCMS supports multi-language title display and convert it into an article that is practical and easy to understand. --- ## AnQiCMS multilingual实战:How to accurately reach global users with `SiteName` title?

2025-11-06

What development conventions and practices should be paid attention to when developing AnQiCMS multi-language templates?

Under the impetus of the global wave, the multilingual capability of websites is no longer a bonus, but a necessity to reach a wider user base.As an experienced operator of AnQiCMS, I am well aware of the importance of a high-efficiency and maintainable multilingual template for a company to expand into the international market.Today, let's delve deeply into the development conventions and practices to be followed when developing AnQiCMS multilingual templates, so that your website can shine on the global stage.AnQiCMS as a modern content management system developed based on the Go language, with its lightweight

2025-11-06

How to dynamically load language-specific CSS or JavaScript files in AnQiCMS multilingual templates?

I am glad to delve deeply into the strategy of AnQiCMS dynamically loading language-specific resource files in multilingual templates.As an experienced website operations expert, I am well aware that providing customized experiences for users of different languages is very important in today's increasingly globalized world.AnQiCMS strong multilingual support and flexible template engine is the key to achieving this goal.--- ## Unlock the Customized Charm of Multilingual Sites: The Strategy of Dynamically Loading Language-Specific CSS and JavaScript Files in AnQiCMS In today's ever-changing digital world

2025-11-06

How to keep the user's session or status information when switching language sites of AnQiCMS?

AnQiCMS Multi-language Site Switching: Gracefully Maintain User Session and State In today's globalized digital world, a website's ability to serve users in multiple languages is undoubtedly a key to expanding the market and enhancing user experience.AnQiCMS is an enterprise-level content management system developed based on the Go language, and its "multilingual support" feature is undoubtedly one of its core highlights.

2025-11-06

Is there a configuration item related to the AnQiCMS multilingual feature in the `config.` file?

As an experienced website operations expert, I fully understand your attention to the various functions of AnQiCMS, especially the details of its multi-language capability configuration.In modern website operations, multilingual support has become an indispensable factor in expanding the market and enhancing user experience.Today, let's delve into the relationship between the `config.` file in AnQiCMS and the multilingual feature.### `config.`: The "ID card" of the template and metadata In the AnQiCMS ecosystem, `config

2025-11-06