AnQiCMS (AnQiCMS) is a system that focuses on providing efficient and customizable content management solutions. Its powerful multilingual support function provides convenience for expanding the global market of the website.When using AnQiCMS to build a website with Chinese or other non-ASCII character content, ensuring that these contents can be displayed normally without garbled characters is a basic and crucial step.This is particularly important for the UTF-8 encoding requirement of the template file.
The importance of UTF-8 encoding in template files
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 lot of unreadable乱码on the page.This not only greatly damages the user experience, but also makes the website look unprofessional.
How to ensure that template files use UTF-8 encoding
For most AnQiCMS users, ensuring the correct encoding of template files is mainly focused on the editing and saving stages.
Use a text editor that supports UTF-8:Modern text editors such as VS Code, Sublime Text, Notepad++ and others all support UTF-8 encoding by default. When you create or modify template files (usually
.htmlWhen saving files with suffixes), these editors usually save them in UTF-8 format automatically.Explicitly set UTF-8 encoding (especially in 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 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 manually, you can click the encoding display at the bottom right of the status bar (usually "UTF-8" or "GBK
Principle of Uniformity:It is recommended to use UTF-8 encoding for not only HTML template files, but also your custom CSS stylesheets, JavaScript scripts, and so on.Although they may not directly contain Chinese content, a unified coding standard helps to avoid potential compatibility issues.
Strategy for multi-language content display in AnQi CMS
Ensure the encoding of the template file is correct is just the first step to display multilingual content normally. AnQiCMS also provides more features to help you implement and manage multilingual websites: English
Template built-in text translation:If some text in your template is fixed and does not change, such as 'Home' and 'About Us' on the navigation bar, you can use the text provided by AnQiCMS to
{% tr %}Translate label. First, you need to create a folder under the template directorylocalesfolder, and create a corresponding subfolder for each language (for examplezh-cn/en-us). Place a file in each language folder.default.ymlFile, where key-value pairs are defined. For example,zh-cn/default.ymlyou can write:"yourLocation": "您的位置" "aboutUs": "关于我们"while
en-us/default.ymlthen write:"yourLocation": "Your Location" "aboutUs": "About Us"In the template, you can use
{% tr "yourLocation" %}to call the text of the corresponding language.Dynamic content management and display:One of the core strengths of AnQi CMS is its 'multi-language 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 input the corresponding content for each language.When the user visits the website, AnQiCMS will automatically retrieve and display the corresponding language version of the content 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 configured multilingual sites. 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 indicate the language and region of the page.
<head>Add content inside the tag.hreflangAttributes can specify the language and region of the page.{% languages %}Tags can also help you generate these keyhreflangLink:{%- 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 user's language and region.
Default language package of the system:In the "Global SettingsThis setting mainly affects the AnQiCMS background interface and some system-built-in prompts in text language, and will not change the language of the content you add to your website manually, such as articles, products, categories, etc.
Through 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 browsing experience for users from different countries and regions.
Common Questions (FAQ)
1. Why does the Chinese content on the page still display as garbled characters even though my template file has been saved as UTF-8?This may be due to various reasons. First, please make sure your HTML file header<head>tags include<meta charset="UTF-8">.其次,check your web server (such as Nginx, Apache) whether it is correctly configured with UTF-8 encoding, or whether the browser automatically selects the wrong encoding when parsing (you can try to manually change the browser encoding settings).Finally, clearing the browser cache and AnQiCMS system cache may also solve the problem.
2. How does AnQiCMS manage the multi-language versions of dynamic content (such as article titles and content)? Do I need to create multiple versions of articles?AnQiCMS supports multilingual content model.English, 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 selection.You do not need to create completely independent multiple article IDs, but manage different language variants under the same content ID.
3.{% tr %}translate tags and{% languages %}What are the differences between tags? 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, copyright statements in the footer, and text on form buttons, etc., these contents do not change with database data.{% languages %}Labels are used to retrieve and display links to all configured multilingual sites, typically used to create a language switcher at the top of the website, allowing users to manually browse language versions. In short, {% tr %}Process the "language of the template itself".{% languages %}Process the "entry to switch the website's language".