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

Calendar 👁️ 71

As an experienced website operation expert, I know that in the context of globalization, the multilingual ability 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.


AnQiCMS template multilingual translation guide: easily achieve text internationalization

In the digital age, a website that can support multiple languages is undoubtedly a key to businesses reaching global users and expanding their brand influence.AnQiCMS with its concise and efficient architecture, provides the possibility of international promotion for small and medium-sized enterprises and content operation teams.Especially for the fixed content in the template, such as navigation menu items, button text, form prompts, etc., AnQiCMS provides a直观而强大的多language translation mechanism, allowing your website to easily speak multiple languages.

AnQiCMS' "Multilingual Support" is not just a concept, it is one of the core features aimed at helping users expand into international markets and directly face users of different languages.However, we need to distinguish an important concept: AnQiCMS's 'Multi-site Management' feature is often used to build websites in different languages, each managing articles, products, and other dynamic content in their respective languages.{% tr %}Where to use translation tags.

AnQiCMS supports built-in language packages (just like itsv2.1.1As described in the update log), it allows you to create translation files for specific text in the template and switch them in the website background.This not only makes your website interface more internationalized, but also greatly enhances the localization experience of users.

Detailed steps: Add multilingual support for specific text in the template

To provide multilingual translation for the static text in the AnQiCMS template, you mainly need to complete the following steps: set up the website language package, prepare translation files, and use translation tags in the template.

First step: Set the default language package of the website

AnQiCMS backend "Global Function Settings" provides an option called "Default Language Pack".This setting determines the system's built-in prompts and which language translation file will be loaded first when your template does not specify a language explicitly.For example, if you select 'English' as the default language package, the system will try to load the English translation file.Remember, this setting affects the entire system, and in the case of multi-site deployment scenarios, each site can be independently configured in its own backend.

Second step: Create and manage language translation files

The translation mechanism of AnQiCMS relies on a specific file structure. You need to create a subdirectory named under your template directory (usually/template/[您的模板名]/),locales. In thislocalesIn the directory, you need to create a separate folder for each target language, and the folder name should use the standard language code (such as,zh-cnrepresenting Simplified Chinese,en-usrepresenting American English,jaRepresents Japanese and so on).

Inside each language folder, you need to create adefault.ymlFile. This YAML formatted file will contain key-value pairs, where the "key" is the unique identifier you use in the template, and the "value" is the corresponding translation text in that language.

For example, if you want to translate the text "Your location":

  1. InlocalesCreate in the directoryzh-cnFolder, and create within itdefault.yml:
    
    # /template/[您的模板名]/locales/zh-cn/default.yml
    "yourLocation": "您的位置"
    
  2. InlocalesCreate in the directoryen-usFolder, and create within itdefault.yml:
    
    # /template/[您的模板名]/locales/en-us/default.yml
    "yourLocation": "Your Location"
    

It is worth noting that all thedefault.ymlFiles should be saved with UTF-8 encoding to ensure correct character display in different language environments and to avoid garbled characters.

Step 3: Use in the template.{% tr %}Tag

After completing the preparation of the translation file, you can now use it in your AnQiCMS template{% tr %}The label is used to reference these translation texts. This label is very intuitive, as it automatically searches and displays the corresponding translation content based on the current language setting of the website.

Assume you have an area in the template that displays the user's current location, and you want it to switch the display of "Your Location

<div class="user-location">
    <span>{% tr "yourLocation" %}:</span>
    <span>{{ current_page_path }}</span> {# 假设这里是一个动态获取的页面路径 #}
</div>

When your website language is set to Simplified Chinese,{% tr "yourLocation" %}The translation will be "Your Location"; when the language is switched to English, it will display "Your Location".The AnQiCMS template engine will automatically match the corresponding key and language file to achieve seamless switching.

Step 4: Build a multilingual switcher and Hreflang tags (advanced application)

To allow users to freely switch website languages and optimize international SEO, you can further utilize the features provided by AnQiCMS{% languages %}The tag can list all the multi-language site information that has been configured, making it convenient for you to build a language switch menu and provide Hreflang information to search engines.

Build a language switcher:

At a suitable position in the template (such as the header or footer), you can add the following code to create a simple language switch menu:

{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" title="{{item.LanguageName}}">
        {%- if item.LanguageIcon %}
        <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}图标" />
        {%- else %}
        {{item.LanguageEmoji}} {# 如果没有图标,可以使用Emoji表情 #}
        {% endif %}
        {{item.LanguageName}}
    </a>
    {%- endfor %}
</div>
{%- endif %}
{%- endlanguages %}

This code will traverse all configured language sites and generate a link for each site, so that users can click to switch to the corresponding language website.

Add Hreflang tags:

To help search engines understand the content of your website for different languages or regions, it is recommended to add on each page's<head>the tag withhreflangProperties. This helps to avoid duplicate content issues and ensures that the correct language version is displayed to the correct users.

<head>
    {# ... 其他head内容 ... #}
    {%- languages websites %}
    {%- for item in websites %}
    <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
    {%- endfor %}
    {%- endlanguages %}
</head>

item.Linkwill provide the URL of the corresponding language site,item.LanguageThen provide the language code, the search engine will judge accordingly.

Related articles

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

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

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

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

As an experienced website operations expert, I fully understand the importance of a powerful and flexible content management system for the enterprise'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 crucial for personalized content display and optimizing user experience.Today, let's delve deeply into how to accurately determine the current active language in the AnQiCMS template based on the `Language` code.

2025-11-06

How should the directory structure of AnQiCMS multilingual template files be organized?

As an experienced website operations expert, I fully understand that building an efficient and easy-to-manage multilingual website is crucial for expanding the market and improving user experience.AnQiCMS (AnQiCMS) leverages the powerful performance and flexible design of the Go language to provide us with excellent multilingual support.However, to truly bring out its advantages, a clear and reasonable template file directory structure is the foundation.

2025-11-06

What role does the `locales` folder play in the AnQiCMS multilingual settings?

AnQi CMS, as an enterprise-level content management system based on Go language, it is committed to providing efficient and customizable solutions for small and medium-sized enterprises and content operation teams.In today's globalized internet environment, multilingual support is no longer an optional feature, but a core function for expanding the market and enhancing user experience.When we talk about the multilingual settings of AnQiCMS, the `locales` folder undoubtedly plays a crucial role, as it is the key to translating static text in front-end templates.The `locales` folder is located in

2025-11-06

How to write and manage content in AnQiCMS multilingual translation for `.yml` files?

In today's globalized digital world, whether a website can overcome language barriers and directly reach users from different cultural backgrounds often determines its market breadth and influence.The AnQi CMS is well-versed in this, providing users with powerful and flexible multilingual support features.As an experienced website operations expert, I fully understand the importance of an efficient multilingual management mechanism for improving user experience and expanding global business.In AnQiCMS, the `.yml` file is the core tool to achieve this goal.This article will take you to a deeper understanding of the AnQiCMS multilingual translation of`

2025-11-06

How to implement dynamic content translation with the `{% tr %}` tag in AnQiCMS template?

## Magic in AnQi CMS template: How the `{% tr %}` tag enables dynamic content translation on your website?In today's globalized digital marketing environment, a corporate website that can flexibly meet multilingual needs will undoubtedly have a competitive edge in the international market.AnQiCMS, as an enterprise-level content management system developed based on the Go language, deeply understands this, and provides users with powerful and concise multilingual support.

2025-11-06