In today's global digital world, a website that can present its content in multiple languages undoubtedly can greatly expand its user base and significantly enhance the user experience.AnQiCMS as a powerful content management system, fully considers the needs of international operation, and provides a flexible and efficient mechanism to realize the switching and display of multi-language content.
Why is multi-language content so important?
Imagine a user from Japan visiting your website. If they can read product descriptions or service instructions in their native language, their sense of trust and engagement will immediately increase.Multilingual content can not only break through language barriers, allowing your information to reach a wider audience, but also improve the visibility of search engines in different countries and regions, thereby bringing more precise traffic.AnQiCMS knows this well, taking multilingual support as one of its core features, aiming to help operators easily achieve global layout.
English content management base of AnQiCMS
AnQiCMS has adopted a stratified approach to implementing multilingual content, which makes the system both flexible and powerful. First, the system provides support forDefault language packageThe support, this means that the website backend interface and some built-in system prompts can be switched to Chinese or English, convenient for administrators from different language backgrounds to operate.However, it should be noted that the language package here is mainly aimed at the system interface and will not directly change the content of the articles, products, or categories you publish on your website.
To manage actual website content (such as articles, product introductions, single-page websites, etc.), the core advantage of AnQiCMS lies in itsFlexible Content ModelandMulti-site managementFunction.This means you can create independent content collections for each language version, and even use the multi-site management feature to set up a separate subdomain or subdirectory for each language, thus achieving complete separation of content and sites. This is particularly practical for large-scale internationalized websites.
Implementation of front-end multi-language switching and display
AnQiCMS provides special template tags that allow you to easily implement language switching on the website frontend and ensure that content in different languages is displayed correctly.
1. Switcher and language list display
A language switcher is usually placed in the header, footer, or sidebar of a website. AnQiCMS provides{% languages %}Label to get the list of all configured multilingual sites. Through this label, you can easily build a user-friendly language selection menu.
For example, you can use it in your template like this to display the language list:
{%- 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 traverse all available language sites, generate a link for each language, and display its name, Emoji expression, or custom icon.When users click these links, the website will switch to the corresponding language version.
2. Language adaptation of page content
When the user selects a specific language through the language switcher, AnQiCMS will translate according to{% languages %}in the tags providedLinkNavigate to the corresponding language site or content version.This means, you need to create or associate dedicated content for each target language.For example, if your website has both Chinese and English versions, an article named "AnQiCMS Introduction" would need to create content for both the Chinese and English versions.Through the powerful content model and flexible classification system of AnQiCMS, you can organize these contents in different languages, ensuring that correct and appropriate content is displayed in different language environments.
3. Translation of template static text
除了动态内容,网站模板中还有很多静态文本,如导航菜单项、按钮文字、版权声明等。AnQiCMS 提供了 English{% tr %}Translate the label to process these fixed strings.
To use this feature, you need to create it under the template directorylocalesFolder, and create corresponding YAML translation files for each language within it. For example:
./locales
├── en-us
│ └── default.yml
└── zh-cn
└── default.yml
zh-cn/default.ymlThe content of the file may be as follows:
"yourLocation": "您的位置"
"home": "首页"
"contactUs": "联系我们"
Then, in the template, you can directly use{% tr "home" %}Translate the word 'Home' when calling this. When the website switches to English, ifen-us/default.ymlthere is a correspondinghome: "Home"translation, the system will automatically display the “