In today's digital world, your website may need to be accessible to global users.AnQiCMS fully understands this requirement and provides powerful multi-language support functions, allowing you to easily build and manage multi-language websites and better serve users from different countries and regions.How to implement multi-language content switching and display in AnQiCMS templates?Let us explore step by step.
Understand the multi-language mechanism of AnQiCMS: the processing of two 'languages'
In AnQiCMS, we need to distinguish between two types of 'language' content:
- System built-in and template static text: This includes prompt information on the backend management interface, fixed navigation items in templates (such as 'Home', 'Contact Us'), and footer copyright statements, etc., which usually do not change with the articles published by users.
- User published content:This refers to your articles, products, single pages, category descriptions, and other dynamic content, which are the core information of the website.
AnQiCMS provides different processing methods for these two types of content to ensure flexibility and management efficiency.
Implement the switching and display of built-in system and template static text.
In order for the interface elements of your website to switch according to the language selected by the user, AnQiCMS has introduced the mechanism of language packs and translation tags.
First, you need to create a folder namedlocalesin the template directory. In this folder, you can create a subfolder for each supported language, for examplezh-cn(Simplified Chinese),en-us(English) etc. Each language subfolder will create onedefault.ymlfile.
For example, in English, the directory structure may be as follows:
/template
└── your_template_name
└── locales
├── en-us
│ └── default.yml
└── zh-cn
└── default.yml
Inen-us/default.ymlIn the file, you can define the translation content in this way:
"homePage": "Home"
"contactUs": "Contact Us"
"yourLocation": "Your Location"
Andzh-cn/default.ymlauto
"homePage": "首页"
"contactUs": "联系我们"
"yourLocation": "您的位置"
In your template file (for exampleheader.htmlorindex.htmlauto{% tr "key" %}auto
<nav>
<a href="/">{% tr "homePage" %}</a>
<a href="/contact.html">{% tr "contactUs" %}</a>
</nav>
<p>{% tr "yourLocation" %}</p>
When the user switches to a different language, AnQiCMS will automatically load the correspondingdefault.ymlfile and display the corresponding translated text.
In addition, you can find the 'Default Language Package' option in the 'Global Function Settings' of the AnQiCMS backend.Here you can set the language of the backend interface and built-in prompts of the current site, for example, selecting "Chinese" or "English".Please note that this setting mainly affects the language environment of the system itself and will not directly change the language of the articles, categories, and other user-generated content in your templates.
Implement user content publishing management and display
For articles, products, single pages, and other core content, AnQiCMS's design philosophy is to achieve independent management and display of multilingual content through the "multi-site management" feature. This means that you will usually set up an independent site for each language, for example:
www.yourdomain.com(English site)en.yourdomain.com(English site)fr.yourdomain.com(French site)
This method has several significant advantages:
- Content independence:Content for each language is completely independent, convenient for management and updates, and avoids confusion.
- SEO friendly:Each language version has an independent URL structure, which is beneficial for search engines to crawl and rank different language content, and it is also convenient for configuration
hreflangLabel. - Flexibility:Different language sites can even use different template designs to meet specific cultural or market needs.
In the "Multi-site Management" section of the AnQiCMS backend, you can easily add these independent language sites.Each site will have its own content, categories, tags, and even an admin account.This means that you need to independently publish and manage articles, products, and other content in each language site.Although this may mean the need to re-enter and translate content, it can bring **flexibility and maintainability**.
Provide a language switcher in the template
To facilitate users to switch between different language versions, you need to add a language switcher in the template. AnQiCMS provides{% languages websites %}Label to get the list of all configured multi-language sites.
You can add the following code snippet to the header or footer of the template to switch languages:
{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
<span>切换语言:</span>
{%- for item in websites %}
<a href="{{item.Link}}" title="{{item.Name}}">
{%- 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 the configured language sites and generate a link with the language name, icon, or Emoji for each site.Users can click on these links to jump to the corresponding language site.
Additionally, to better facilitate international SEO, it is strongly recommended that you specify the other language versions corresponding to the current page on each page.<head>area tag.hreflangTags, indicating the other language versions corresponding to the current page.
<head>
{# 其他head内容 #}
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}
</head>
hreflangTags inform search engines that your website has multiple language versions and specify the URL for each version, which is crucial for avoiding duplicate content issues and guiding users to the correct language version page.
Summary
AnQiCMS provides a flexible and efficient multilingual solution by distinguishing between system内置 built-in text and user发布 published content. UtilizinglocalesDirectory and{% tr %}The label can easily handle the translation of template static text, and with the powerful "multi-site management" feature, it can build clear, independent language versions of your core content website. Accompanied by the language switcher in the template, hreflangLabels, your AnQiCMS website will be able to seamlessly serve global users, helping your business go international.
Common Questions (FAQ)
1. Can I provide multiple language versions for an article on the same AnQiCMS site?
AnQiCMS 的核心设计理念是针对多语言内容采用多站点管理。这意味着,通常情况下,您会为每种语言创建独立的站点(例如en.yourdomain.comandfr.yourdomain.comThen publish articles in this language at each site.Although it is possible to hardcode multiple language texts in the same article content field and display them through frontend logic, this is not recommended practice as it makes content management complex and不利于 SEO.The multi-site mode provides a clearer and easier-to-maintain solution.
2. How to ensure the SEO effect of a multilingual website?
Firstly, providing a separate URL for each language (such as through subdomains or subdirectories) is fundamental. Secondly, make sure to have each page<head>areahreflangLabel, clearly inform the search engine of the other language versions and corresponding URLs of this page.Ensure that the content of each language version is high quality and unique, avoiding simple machine translation.Additionally, conduct keyword research and localization content optimization for markets with different target languages, and configure independent TDK (title, description, keywords) and pseudo-static rules for each language version.
3. If my website only has a few fixed words that need translation and I do not want to build a complete multilingual site, is that possible?
Absolutely. If you only need to translate a few fixed words in the template and the core content published by the user (articles, etc.) is still in a single language, then you just need to use{% tr "key" %}translate tags andlocalesLanguage package mechanism is available. You can only create language package files containing these fixed word translations (for exampleen-us/default.yml), and use them in the template.