AnQiCMS (AnQiCMS) is a system focused on providing an efficient and customizable content management solution, with its powerful multilingual support function, it provides convenience for website expansion into the global market.When using AnQiCMS to build a website containing Chinese or other non-ASCII characters, ensuring that these contents are displayed normally and avoiding garbled characters is a fundamental and crucial step.This is particularly important for the UTF-8 encoding requirements of the template file.
The importance of UTF-8 encoding in template files
The AnQiCMS has a clear and important requirement when processing template files: all template files must use UTF-8 encoding.UTF-8 is the most commonly used character encoding on the Internet, capable of accommodating almost all characters in the world, including Chinese, Japanese, Korean and other languages.
If the template file does not use UTF-8 encoding, when these files contain Chinese or other multilingual characters, the browser cannot correctly identify the encoding of these characters, resulting in a mess of unreadable garbage on the page.This greatly damages the user experience and makes the website look unprofessional.
How to ensure UTF-8 encoding is used in template files
For most AnQiCMS users, ensuring that the template file encoding is correct mainly focuses on the editing and saving stages.
Use a text editor that supports UTF-8:Modern text editors like VS Code, Sublime Text, Notepad++, etc., all support UTF-8 encoding by default. When you create or modify template files (usually
.htmlWhen a file extension is used, these editors will usually automatically save it in UTF-8 format.Explicitly set UTF-8 encoding (especially in the Windows environment):For Windows users, it is especially important to pay attention to the save options when editing template files.Some editors may default to using GBK or ANSI encoding under specific configurations.
- In Notepad++:You can select 'Encoding' in the menu bar -> 'Convert to UTF-8 without BOM', and make sure the file is saved with UTF-8 encoding.
- In VS Code:It usually detects and uses UTF-8 automatically. If you need to set it manually, you can click the encoding display at the bottom right of the status bar (usually "UTF-8" or "GBK"), then select "Reopen with Encoding" or "Save with Encoding", and select "UTF-8"。
Principle of Uniformity:It is recommended to use UTF-8 encoding uniformly for not only HTML template files but also custom CSS stylesheets, JavaScript scripts, and so on.Although they may not contain Chinese content directly, a unified encoding standard helps to avoid potential compatibility issues.
Strategy for displaying multi-language content in Anqi CMS:
Ensure that the template file encoding is correct is just the first step in displaying multilingual content. AnQiCMS also provides more features to help you implement and manage multilingual websites:
Translation of built-in template text:If your template contains some fixed text that does not change, such as the navigation bar on the home page, about us, etc., you can use the AnQiCMS provided
{% tr %}Translation label. First, you need to createlocalesa folder under the template directory, and create a sub-folder for each language (for examplezh-cn/en-us). Place a singledefault.ymlA file, which defines key-value pairs. For example,zh-cn/default.ymlcan be written here:"yourLocation": "您的位置" "aboutUs": "关于我们"And
en-us/default.ymland here:"yourLocation": "Your Location" "aboutUs": "About Us"In the template, you can call
{% tr "yourLocation" %}the text of the corresponding language.Management and display of dynamic content:One of the core advantages of AnQi CMS is its "multilingual support" feature.This means you can create different language versions for dynamic content such as articles, products, categories, etc.The system will provide the corresponding mechanism in the background, allowing you to enter content corresponding to each language.When a user visits the website, AnQiCMS will automatically retrieve and display the content in the corresponding language version based on the current language settings.
Language switcher and SEO optimization:To facilitate users switching between different language versions, you can use:
{% languages %}Labels to generate language switch links. This label will list all the multilingual sites configured. For example, it can be used in templates like this:{%- 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 %}In addition, to better perform multilingual SEO, you should also specify the page's
<head>in the tag.hreflangproperties, indicating the language and region of the page.{% languages %}tags can also help you generate these keyhreflang:{%- languages websites %} {%- for item in websites %} <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}"> {%- endfor %} {%- endlanguages %}This helps search engines understand the structure of your multilingual content, avoid duplicate content issues, and display the most suitable version for the language and region of the user.
Default language package:In the AnQiCMS background 'Global Settings', you can set the 'default language package'.This setting mainly affects the AnQiCMS backend interface and some system内置 hints text language, but will not change the language of the articles, products, categories, and other content you add to your website.
By using these methods, combined with the correct UTF-8 encoding of the template file, you can ensure that the multilingual content on the AnQiCMS website (including complex Chinese text) can be displayed normally and smoothly, providing a high-quality access experience for users from different countries and regions.
Frequently Asked Questions (FAQ)
1. Why does my template file, which is saved in UTF-8, still display Chinese content as garbled on the page?This may be due to a variety of reasons. First, please ensure that your HTML file header<head>tags contain<meta charset="UTF-8">Check if your web server (such as Nginx, Apache) is correctly configured for UTF-8 encoding, or if the browser automatically selects the wrong encoding when parsing (you can try manually changing the browser encoding settings).Finally, clearing the browser cache and AnQiCMS system cache may also solve the problem.
2. How does AnQiCMS manage multilingual versions of dynamic content (such as article titles and content)? Do I need to create multiple versions of articles?AnQiCMS supports multilingual content models. Typically, this means that when editing articles or products in the background, you can select or switch to different language versions for editing and saving.For example, you create a Chinese article and then switch the language option to input the English version of the same article.When the user switches the website language, the system will automatically load the corresponding language version based on their choice.You do not need to create completely independent multiple article IDs, but manage different language variants under the same content ID.
3.{% tr %}Translate labels and{% languages %}What are the differences between labels? What are their respective application scenarios?
{% tr %}Labels are mainly used to translate hard-coded, static text strings in templates.For example, navigation bar menu items, footer copyright statements, text on form buttons, etc., these contents do not change with the database data. And{% languages %}The tag is used to retrieve and display links to all configured multilingual sites, usually used to create a language switcher at the top of the website, allowing users to manually browse different language versions. In short, {% tr %}Handle the language of the template itself{% languages %}Handle the entry for switching the website's language