How to implement the multi-language content switching and front-end display of AnQiCMS website?

Calendar 👁️ 73

It is undoubtedly a crucial link in the construction of a global digital content platform.AnQiCMS (AnQiCMS) is a management system designed specifically for content operators, deeply understanding this field, providing comprehensive multilingual content switching and frontend display functions, aiming to help users efficiently expand into international markets and reach a wider audience.

AnQiCMS multi-language feature overview

AnQiCMS is developed based on the Go language, with its high efficiency, customizable and easy-to-expand features, it has become an ideal choice for small and medium-sized enterprises and content operation teams.One of its core advantages is the powerful multilingual support. This means that you can easily manage different language versions of the website interface, and also achieve seamless switching and display of content, allowing your content to directly target users of different languages, effectively helping enterprises to carry out multilingual promotion and global layout.

The backend is preparing: Starting the journey of multilingual content support

To enable multilingual content switching on the website, you first need to make the corresponding configuration and content preparation in the Anqi CMS backend.

Step 1: Configure default language package

A safe CMS provides the option for the "default language package" in the "global settings".This is the foundation of system-level language, which determines the display language of the background interface and some default system prompts.You can choose the appropriate language package according to the main operating language, such as Chinese or English.This setting is the starting point of the entire multilingual system.

Step 2: Plan for multilingual content versioning

The AnQi CMS allows you to flexibly manage multilingual content according to your actual needs. Although the system does not directly provide a "language version" field within individual content items (such as articles, products, pages), you can manage multilingual content in the following two common ways:

  1. Implement multilingual content management through multiple site management: A key feature of AnQi CMS is its powerful "multi-site management" function. You can create an independent sub-site for each target language (for example,www.example.comUsed for Chinese,en.example.comorwww.example.com/en/Used in English). Each sub-site has its own database or data prefix, and can be configured with its own default language package and template.In this mode, you can create and publish content corresponding to each language sub-site, achieving completely independent content management.When the user switches language, it is actually jumping to the corresponding language sub-site.

  2. By content model, customize fields to distinguish content: If you do not want to create a separate site for each language, another way is to add custom fields for different languages in the "content model". For example, for the "article" model, you can addTitle_en(English title),Content_en(English content) and other fields. When publishing content, editors need to manually fill in the fields for each language version. The front-end template needs to dynamically select the display based on the current language environment.TitleorTitle_enThis method has higher requirements for template writing and needs editors to manually maintain all language content.

The key is to clearly define the storage and management logic of each language content. For general users, using multi-site management is often a clearer and easier-to-maintain choice.

Front-end implementation: Allows users to easily switch languages

After the content is ready, the next step is to build a friendly language switch feature on the website front-end, and ensure that the search engine can correctly identify your multilingual pages.

Implement a language switcher

Adding a language switcher to your website template is the key to providing a multilingual experience. Anqi CMS provides a convenientlanguagesTag used to retrieve a list of all available multilingual site lists and generate switch links.

You canbash.htmlAdd the following code segment to (or any public header template):

{%- languages websites %}
{%- if websites %}
<div>
    <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 %}

This code will iterate through all configured languages (or multilingual sites) and generate a toggle button with a link, name, and optional icon/Emoji for each language.Clicking will take you to the corresponding language version of the page.

Translation of static text in the template

In addition to dynamic content, the website interface also contains many fixed static texts, such as navigation menu items, copyright statements, button texts, etc. Anqi CMS throughtrA tagging and language package mechanism is used to manage the translation of these static texts.

  1. Create a language package fileIn your template directory, create alocalesFolder, and create a subfolder for each language under it, such aszh-cnand Simplified Chineseen-us(American English). Create adefault.ymlfile.locales/zh-cn/default.ymlExample:

    yourLocation: "您的位置"
    welcomeMessage: "欢迎来到安企CMS"
    

    locales/en-us/default.ymlExample:

    yourLocation: "Your Location"
    welcomeMessage: "Welcome to AnQiCMS"
    
  2. Using the templatetrTag: Use your template, in{% tr "键名" %}Call the corresponding translation text in the form of

    <p>{% tr "welcomeMessage" %}</p>
    <p>{% tr "yourLocation" %}</p>
    

    When the user switches language, the system will automatically load the appropriatedefault.ymlfile and display the corresponding translation text.

SEO optimization: The application of Hreflang tags

For multilingual websites, in order to inform search engines about the relationship between different language versions of the pages, use it correctlyhreflangTags are crucial. This helps search engines provide the most relevant search results for users in different regions and languages, avoiding issues with duplicate content.

You can visit the website<head>Area additionhreflangLabel, it can also be usedlanguagesLabel dynamically generated:

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

This will generate one for each language version<link>The tag indicates the corresponding URL and language code, helping search engines understand your multilingual content structure.

The logic of presenting multilingual content

When the user selects a language through the language switcher, AnQiCMS will automatically load and display the content version of the selected language based on the corresponding configuration (such as jumping to the corresponding language sub-site URL or setting language parameters in the current URL). For users who usetrlabel's

Related articles

How to control the number of articles displayed per page and the sorting method on the article list page?

## Fine Control: The Practical Guide to the Number and Sorting of Articles on the AnQi CMS List Page In content operations, the list page of articles on the website is an important window for users to browse content and discover information.A well-organized and content-rich list page, which not only enhances user experience but is also a key factor in search engine optimization (SEO).AnQi CMS is well-versed in this, enabling you to easily and precisely control the number of articles displayed per page and the sorting method of the content through its powerful and flexible template tag system.This article will take you deep into how to use Anqi CMS

2025-11-07

How to customize the URL rewrite rules for the article detail page in the AnQiCMS template?

## Optimize SEO, Enhance User Experience: AnQiCMS Detailed Explanation of Custom Article Detail Page URL Static Rules In website operation, a clear and meaningful URL structure is crucial for search engine optimization (SEO) and user experience.Imagine a user sees `/article.php?Which link would be more attractive to them, the one with `id=123&category=news` such as this, or the one with `/news/anqicms-url-guide.html` such as this?

2025-11-07

How to customize the display of SEO titles, keywords, and descriptions on the AnQiCMS homepage?

In the digital age, the homepage of a website is like the 'front door' of a company, the information presented to search engines is crucial.An meticulously optimized homepage that clearly conveys the core value of the website, attracts target users, and provides friendly crawling signals to search engines.In AnQiCMS, customizing the display of the SEO title (Title), keywords (Keywords), and description (Description) on the homepage is a straightforward and powerful process, which is an important manifestation of AnQiCMS's SEO-friendly features.

2025-11-07

How does AnQiCMS adaptively display website content for different devices (PC/Mobile end)?

In today's parallel network environment of multiple devices, users may access websites through desktop computers, laptops, tablets, or smartphones.Therefore, ensuring that the website content displays well on different devices and provides a smooth user experience is a key link in the success of website operation.AnQiCMS as an enterprise-level content management system fully considers this requirement and provides a flexible and diverse adaptive display scheme for device content, allowing users to choose the most suitable method according to their own situation.AnQiCMS mainly provides three core strategies for handling multi-device display of website content

2025-11-07

Does AnQiCMS support directly retrieving and displaying system configuration information (such as website name, Logo) in templates?

During the process of building and maintaining a website, we often encounter the need to display basic information about the website at various positions on the page, such as the name of the website, Logo, copyright statement, filing number, and so on.If this information is scattered in all corners of the template, it will be very cumbersome and prone to errors once it needs to be modified.What kind of solution does AnQiCMS provide in this regard?Does it support us to directly obtain and display these system-level configuration information in the template?The answer is affirmative.

2025-11-07

How to call and display the contact information (phone, email, address) set in the back-end template on the front-end?

It is crucial to clearly and effectively display contact information in website operation to establish user trust and promote communication.Whether it is to consult products, seek service support, or give feedback, a reachable phone, email, or address can greatly enhance the user experience.AnQiCMS (AnQiCMS) fully considers this requirement, providing a flexible and convenient way for website administrators to centrally manage contact information in the background, and easily call and display on the front-end page through simple template tags.### Step 1

2025-11-07

How does AnQiCMS ensure the safety and compliance of front-end displayed content, such as sensitive word filtering?

When operating a website, the security and compliance of content is an indispensable part, especially in the context of the increasingly regulated online environment today.For users who use AnQiCMS, the system provides a variety of functions to help ensure the security and compliance of the displayed content on the front end, such as the sensitive word filtering that users are generally concerned about.At the beginning of its design, AnQiCMS placed content security at the core position.It is not just a content publishing tool, but also a platform dedicated to providing users with a safe and compliant content management environment

2025-11-07

How to implement lazy loading (Lazyload) of images in the article content to optimize page performance?

In website operation, page loading speed is crucial for user experience and search engine optimization (SEO).Especially when the article content includes a large number of images, the loading of image files often becomes the "culprit" that slows down the page speed.Lucky enough, by implementing the Lazyload image technology, we can effectively solve this problem.For friends using AnQiCMS, understanding and applying this technology will significantly improve website performance. Image lazy loading, as the name implies, is to delay the loading of images outside the user's current viewport.When the user scrolls the page

2025-11-07