Today, in the era of content globalization, enabling a website to support multi-language switching and display has become an important part of many companies' international market expansion.AnQiCMS with its flexible architecture, provides us with an efficient way to achieve this goal.This article will delve into how to configure and manage multi-language content in AnQiCMS, ensuring they can be correctly switched and displayed on the front-end website, thereby providing a high-quality browsing experience for users of different languages.
AnQiCMS Overview of Multi-language Capabilities
AnQiCMS skillfully integrates multilingual content management into its core features.The key to implementing multilingual functionality lies in the close integration of "multi-site management" and "language packs" as well as "template tags.This means that you can treat each language version of the website as an independent site for management, with each site having its own independent database content, templates, and language configurations, thereby achieving a high degree of customization and isolation of content.
Background configuration: lay the foundation for multilingualism
To ensure that the multilingual content of AnQiCMS is correctly switched and displayed on the front end, a series of basic configurations need to be made in the background.
Set default language packageIn the "Global Function SettingsHere built-in Chinese, English and other languages for you to choose.Choose a language package after, this will affect the display of the system backend interface and some built-in, non-user-generated text on the front end.For example, some system prompts, button text, etc. will be displayed according to the selected language.
However, please be sure to pay attention to this settingIt will not translate automaticallyThe specific content published on your website, such as articles, products, single pages, etc. This core content created by users needs to be independently created and maintained for each language.
Create different language versions through multi-site managementAnQiCMS 强大的“多站点管理”功能是实现多语言策略的核心。“auto”翻译成“English”为:AnQiCMS Powerful "Multi-site Management" feature is the core of implementing multilingual strategies. "auto" translates to "EnglishYou can create a separate site for each target language.
en.yourdomain.comThe English site, as well as a site namedes.yourdomain.comThe Spanish site.When adding a new site on the "Multi-site Management" interface in the background, you need to configure the following information for each language site:
- Site Name:It is convenient to distinguish between different language versions, such as 'English site', 'Spanish site'.
- Site Root Directory:Each site should have an independent root directory to store cache, uploaded files, and other data to avoid conflicts. Usually followed by
/app/a name based on domain name transformation, such as/app/en_yourdomain_com. - Website addressThis is the access domain name for this language version, for example,
http://en.yourdomain.comPlease ensure that the domain has been correctly resolved to your server. - Administrator account passwordSet independent backend management permissions for each site.
- Database nameEach language site has its own database to store its unique content. It is also recommended to name it with the domain name conversion, such as
en_yourdomain_com. - Select the template to use:You can select or customize exclusive templates for each language version to adapt to the typesetting and design requirements of different languages.
Through this way, each language site will have its own backend, content, and templates, providing a solid foundation for fine-grained operation of different language markets.
Front-end template implementation: Ensure language switching matches content
How to correctly switch and display content in the website front-end after the site is configured with different languages in the background is the key.This is mainly completed through the template tags provided by AnQiCMS.
Build a front-end language switcherIn order for users to be able to freely choose the language version of the website, we need to provide a language switch menu on the website front-end. AnQiCMS's
languagesLabels can help us easily achieve this. This label will return an array containing information about all configured language sites.In the template, you can use it like this:
languagesLabels to build a language switcher:{%- 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 %} {# 否则使用 Emoji 表情符号 #} {{item.LanguageEmoji}} {% endif %} {{item.LanguageName}} </a> {%- endfor %} </div> {%- endif %} {%- endlanguages %}This code will iterate over all the language sites that have been set up and generate a link for each site.
item.LinkIt will point to the root directory of the corresponding language site, ensuring that the user can correctly jump to the home page of the language version after clicking.It realizes the localization translation of the text in the template.For fixed text on the website interface, such as navigation menu items, footer information, form prompts, etc., you can use AnQiCMS's
tr(translate) Label is localized. This avoids copying the entire template for each language, making template maintenance more efficient.To enable this feature, you need to create a folder named in the root directory of the template.
localesWithin this folder, create a subfolder for each language (for example,en-us/zh-cnEnglish"), and place one in these subfolders.default.ymlfile.For example, your
locales/zh-cn/default.ymlThe content of the file may be:yourLocation: "您的位置" contactUs: "联系我们"while
locales/en-us/default.yml文件内容则可能是: “`yaml yourLocation: “Your Location” contactUs: “Contact Us”