How to determine the current active language in AnQiCMS template based on the `Language` code?

Calendar 👁️ 84

As an experienced website operations expert, I am well aware of the importance of a powerful and flexible content management system for a company's globalization strategy.AnQiCMS, with its excellent multilingual support capabilities, has become a powerful assistant for many small and medium-sized enterprises to expand into the international market.In the development of templates for multilingual websites, how to accurately determine the active language of the page being browsed by the current user is the key to personalized content display and optimizing user experience.Today, we will delve deeply into how to useLanguageThe code accurately determines the current active language.

AnQiCMS language recognition mechanism: Core and tools

AnQiCMS provides a simple and powerful mechanism to identify the active language of the current page. The core of this mechanism lies in its built-in template tag system, especiallysystemTags andlanguagesTags. They allow us to retrieve the global configuration information of the website, including the language code of the current site, and the list of all configured multilingual sites.

Firstly, to obtain the code of the currently active language, we mainly rely onsystemThe label is specifically used to extract various system parameters configured in the "Global Settings" of the AnQiCMS backend, including the current site'sLanguagecode.

You can use the following method at any location in the template to get the current language code:

{% system currentLangCode with name='Language' %}

Here, currentLangCodeIs a variable name you define to store the language code of the current site, for examplezh-CNrepresenting Simplified Chinese,en-USRepresents American English. The accuracy of this code comes directly from the configuration you made in the AnQiCMS background "Global Settings" -> "Default Language Package".

Useful template application: Make the language intelligent

After mastering the current language code, you can use it to realize various intelligent language judgments and content presentation in the template.

1. Display conditions for specific languages

The most direct application is to conditionally display different content, styles, or scripts based on the language code.This enables your website to provide highly customized experiences for users of different languages.

For example, you may want to display different greetings based on language:

{% set currentLang = '' %}
{% system currentLang with name='Language' %}

{% if currentLang == 'zh-CN' %}
    <p>欢迎访问我们的中文网站!</p>
{% elif currentLang == 'en-US' %}
    <p>Welcome to our English website!</p>
{% else %}
    <p>Welcome!</p> {# 默认或其他语言的欢迎语 #}
{% endif %}

Similarly, you can also load different CSS stylesheets or JavaScript files based on the language to adapt to the layout habits or interaction needs of different languages:

`twig

<meta charset="UTF-8">
<title>{% tdk with name='Title' siteName=true %}</title>
<link rel="stylesheet" href="/static/css/common.css">

{% set currentLang = '' %}
{% system currentLang with name='Language' %}
{% if currentLang == 'zh-CN' %}
    <link rel="stylesheet" href="/static/css/styles-chinese.css"> {# 中文专用样式 #}
{% elif currentLang == 'en-US' %}

Related articles

Will the AnQiCMS multilingual site list include information about the current site being visited?

In the Anqi CMS ecosystem, multilingual support and multi-site management are its core advantages, aimed at helping enterprises and content operators easily expand into global markets.When you build a multilingual site and want to provide language switching functionality on the front end, you will naturally think: 'Will the AnQiCMS multilingual site list include information about the site being visited?'The answer is affirmative, and this design has brought great convenience and rationality in practical application.### Understanding AnQiCMS Multi-language Site List Mechanism AnQiCMS when handling the multi-language site list

2025-11-06

How to correctly deploy the `hreflang` tag in the HTML header of the AnQiCMS multilingual site?

As an experienced website operations expert, I am well aware that the correct deployment of the `hreflang` tag is of great importance for SEO when carrying out global content layout.It can effectively guide search engines to identify the different language or regional versions of your multilingual site, thereby displaying the most relevant content to users in different regions and avoiding potential duplicate content issues.For AnQiCMS such a powerful and highly flexible content management system, understanding its multilingual features and combining them with `hreflang` tags is the key to improving international operation efficiency.

2025-11-06

How to automatically generate SEO-friendly `hreflang` tags using the `languages` tag?

AnQi CMS, as a Go language development system that deeply understands the art of enterprise content management, its considerations in multilingual support and SEO optimization undoubtedly bring a blessing to websites operating globally.Today, we will focus on a crucial SEO strategy - the `hreflang` tag, discussing how the Aiqi CMS cleverly uses its `languages` tag to help us automatically and efficiently generate these search engine-friendly multilingual instructions.### Embrace the Global

2025-11-06

What kind of jump function does the `Link` field provide in the `languages` tag?

The key to AnQiCMS multi-language site interconnection: in-depth analysis of the `Link` field in the `languages` tag In today's global internet environment, whether a content management system can provide strong and flexible multilingual support has become one of the important criteria for evaluating its quality. AnQiCMS (AnQiCMS), with its efficient and customizable architecture based on Go language, performs excellently in this aspect, especially in handling seamless transitions between multi-language sites and search engine optimization (SEO), where its template tag `languages` contains the

2025-11-06

How to enable or configure AnQiCMS's core multilingual feature?

As an experienced website operations expert, I fully understand the importance of multilingual websites for companies to expand into international markets.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that naturally understands this and provides powerful and practical multilingual support features.Today, let's delve into how AnQiCMS enables and configures its core multilingual functionality, helping your website easily go international.

2025-11-06

What built-in default language packages does AnQiCMS support for user selection?

As an experienced website operations expert, I am well aware of the importance of a good content management system (CMS) in today's global market.AnQiCMS (AnQiCMS) is a tool dedicated to providing efficient solutions for small and medium-sized enterprises, self-media, and multi-site managers.When expanding overseas and targeting global users, multilingual support is undoubtedly one of the core competitive advantages.Today, let's delve into the performance of AnQiCMS in terms of language support, especially which built-in default language packages it provides for users to choose from.

2025-11-06

What content on the website will be affected after setting the default language package of AnQiCMS?

## After setting the default language package of AnQiCMS, what aspects of the website will it change? AnQiCMS (AnQiCMS) is a highly efficient and customizable enterprise-level content management system that plays an important role in helping small and medium-sized enterprises and content operation teams manage content and marketing.The system provides a wealth of features, with 'multilingual support' being a major highlight, aimed at helping enterprises expand into the international market.

2025-11-06

How to perform multilingual translation for specific text in the AnQiCMS template?

As an experienced website operations expert, I am well aware that in the context of globalization, the multilingual capability of a website is crucial for expanding the market and improving user experience.AnQiCMS as an efficient and flexible content management system, naturally also provides strong support in this regard.Today, let's delve into how to implement multilingual translation for specific, static text content in the AnQiCMS template.

2025-11-06