Building multilingual websites in AnQiCMS, providing convenient language switching features, and correct SEO settings is a crucial step to expand the international market and improve user experience.As a modern content management system developed based on the Go language, AnQiCMS provides strong and flexible support in this aspect, allowing content operators to easily handle the global content publication needs.
Understand the multilingual capabilities of AnQiCMS.
AnQiCMS was designed with a focus on the needs of global content promotion, and its built-in multilingual support feature is one of the core advantages of building an internationalized website. This means that we can not only publish content in different languages but also switch languages and correspondinghreflangsettings.
In AnQiCMS backend, we can create multiple language versions of sites through the "Multi-site Management" feature, each site can have an independent domain, subdomain, or subdirectory.At the same time, in the "Global Feature Settings", we can specify the default language package for each site, such as Chinese, English, etc., which will affect the display of the built-in text in the system.
Further, AnQiCMS also supports multilingual content translation at the template level. By creatinglocalesfolder under the template directoryen-us/zh-cnaccording to the language code (such asdefault.ymllanguage files in the template directory, we can use{% tr "yourKey" %}Such translation tags are used to display corresponding text in different languages. For example, ifzh-cn/default.ymlis defined in"yourLocation": "您的位置",en-us/default.ymlis defined in"yourLocation": "Your location",then the Chinese site will display “Your location”, and the English site will display “Your location”, which makes the internationalization of the template very efficient.
Implement multi-language switching links in the template
To provide users with a convenient language switch entry on the website front-end, we need to call the specific tags provided by AnQiCMS in the template to get all the configured language site information.This is usually placed in prominent positions such as the header, footer, or sidebar of a website.
AnQiCMS provides a namedlanguagesThe template tag, which can retrieve the list of all multilingual sites configured on the backend.This tag does not require any parameters, it can be called directly to get an array object containing information about all language sites.
We can use it like this in the template to generate language switching links:
{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
<span>切换语言:</span>
{%- for item in websites %}
<a href="{{item.Link}}" {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}>
{%- if item.LanguageIcon %}
<img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}} Flag" class="language-flag" />
{%- else %}
<span class="language-emoji">{{item.LanguageEmoji}}</span>
{% endif %}
<span class="language-name">{{item.LanguageName}}</span>
</a>
{%- endfor %}
</div>
{%- endif %}
{%- endlanguages %}
In this code,websitesis an array,itemRepresents an object for a language site in each iteration. We can use it toitem.Linkget the URL of the corresponding language site,item.LanguageNameGet the language name (such as “Simplified Chinese”, “English”),item.LanguageEmojiGet the Emoji expression corresponding to the language,item.LanguageIconGet the custom language icon。item.NofollowThe property can help us determine whether we need to add a linknofollowTags, which may be used in some SEO strategies. Through these fields, we can flexibly build a language switcher that is both beautiful and practical.
SethreflangTags for optimizing SEO
In addition to providing users with an intuitive language switching function, proper configuration for search engine optimization (SEO) is also crucial.hreflangTags are also very important.hreflangLabel informs search engines that your website content has multiple language or regional versions, which helps search engines display the most relevant language version to the correct users, avoids duplicate content issues, and enhances international SEO performance.
hreflangTags are usually placed in the HTML document's<head>Region. AnQiCMS also utilizeslanguagestags to help us easily generate these SEO-friendly metadata.
in your template (usually the basic layout file, such asbase.html) of<head>Part, you can add the following code to generate automaticallyhreflangLink:
<head>
{# 其他head内容,如meta标签、title等 #}
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}
</head>
Here, we use it againlanguagesTag to get all language sites. For eachitem(language site), we useitem.LinkashrefThe value of the attribute, providing the URL of the corresponding language site.hreflangThe value of the attribute comes fromitem.Languagethe field, which will return the standard language code (e.g.zh-cn/en-us)。So, the search engine can accurately understand the relationship between different language versions.
Considerations and suggestions in practice
Background site configurationAll these flexible switching features depend on the correct configuration of the "Multi-site Management" module in AnQiCMS backend.You need to create a separate site for each target language, and configure their domain names, subdomains, or subdirectories, as well as the corresponding default language packages.
languagesLabels must be used to correctly retrieve information about all language versions.hreflangWithx-defaultEnglish: In addition to setting for each languagehreflang, if your website has a default version that is not targeted for a specific language or region (such as an English international version), it is recommended to add ax-defaultofhreflangAnQiCMS'slanguagesLabel currently provides options for each configured language site.hreflangOutput, if needed.x-default, it may be necessary to make additional judgments and add manually. For example:<link rel="alternate" href="https://yourwebsite.com/en/" hreflang="x-default">Here are the
https://yourwebsite.com/en/Should point to your generic default language version.Location of template fileLanguage switch link is usually placed in
header.htmlorfooter.htmlin common template files, ensuring that each page can access it. Andhreflangthe tag must be located on all pages.<head>Tags inside.
Through these steps, you can fully utilize the multi-language support function of AnQiCMS, not only providing users with a seamless language switching experience, but also through the correcthreflangSet, to win better visibility and ranking in international search engines for your website.
Common Questions (FAQ)
Q1: How to configure multiple language versions of the site in AnQiCMS backend?A1: To configure multiple language versions of the site, you need to go to the "Feature Management" or "Multi-site Management" module of AnQiCMS backend. Here, you can add new sites and set independent domain names for each site (such asexample.com), subdomains (such asen.example.com)or subdirectory(such asexample.com/en/)。You also need to specify the default language package (such as Chinese, English) and the template used for each site.
Q2: How to implement multilingual on my website if it only has one domain?A2: Even if there is only one primary domain, AnQiCMS supports multi-language through 'Multi-site Management'. You can choose to configure different language versions as subdirectories (for exampleexample.com/en/Used for English,example.com/fr/用于English)。When creating a site in the background, set the website address to the corresponding subdirectory URL.AnQiCMS will automatically handle routing and link generation, ensuring that content of different language versions is displayed in their respective subdirectories.
Q3:hreflangTags and{% tr %}What are the differences between translation tags, and what are their respective functions?A3:hreflangTags and{% tr %}While all translation tags are related to multilingualism, their functions and target audiences are different:
hreflangtagsMainly for search engines.It is an SEO metadata that tells search engines that your web page has multiple language or regional versions.This helps search engines display content in the correct language to users in the corresponding regions, avoiding duplicate content penalties due to similar content, and optimizing international search rankings.{% tr "key" %}Translate LabelMainly aimed at website visitors and content operators. It is used to implement the translation of static text content in template files. For example, navigation