As an experienced website operations expert, I am well aware of the importance of website user experience and global layout for the development of a company.AnQiCMS as a content management system focusing on efficiency and customization indeed puts in a lot of effort in multilingual support.Today, let's delve into the issue that everyone is concerned about: Does AnQiCMS captcha support multi-language switching and internationalization?

毫无疑问,AnQiCMS在设计之初就考虑到了全球化的内容运营需求,因此其核心功能中就包含了强大的多语言支持。However, for interactive elements such as captcha, the internationalization of prompts and error messages needs to be implemented in conjunction with AnQiCMS's overall multilingual framework.

AnQiCMS's overall multilingual framework

To understand the internationalization of captcha information, we first need to have a macro understanding of the multi-language support mechanism of AnQiCMS. AnQiCMS provides two main levels of multi-language capabilities:

Firstly, isSystem built-in multilingual. AnQiCMS in全局功能设置provides默认语言包

Secondly, ismultilingual content and template。AnQiCMS supports creating and managing multilingual content, for example, you can publish the same article for different language versions. What's more critical is that it provides翻译标签 {% tr %}This tag allows developers to perform internationalization on any static text in the template file. You just need to create in the template directorylocalesFolder, and configure the corresponding translation files for each language (such aszh-cn/default.yml/en-us/default.yml) and then use them in the template.{% tr "yourKey" %}This is an example. In this way, all hard-coded text on the front-end page can be dynamically switched according to the user's language selection.

Internationalization practice of captcha prompt text and error information

Understood the multi-language architecture of AnQiCMS, let's take a look at the specific situation of the captcha:

1. Internationalization of captcha prompt text

For example, the validation code mentioned in the document, the prompt text that users see in the form, such as "Please enter the validation code", is usually written directly on the front-end template (for example,guestbook/index.htmlorcomment/list.html)of the HTML codeplaceholderattribute orlabelTags inside.

This means that the hint text belongs tothe content and template levelThe text. To achieve internationalization, you need to make full use of AnQiCMS.翻译标签 {% tr %}.

For example, if your template reads:

<input type="text" name="captcha" required placeholder="请填写验证码" class="layui-input">

To achieve internationalization, you need to:placeholderThe value is changed to a reference to the translation tag, andlocalesdefine the corresponding multilingual text in the file:

<input type="text" name="captcha" required placeholder="{% tr "fillCaptchaPlaceholder" %}" class="layui-input">

Then inlocales/zh-cn/default.ymlIn:

"fillCaptchaPlaceholder": "请填写验证码"

Inlocales/en-us/default.ymlIn:

"fillCaptchaPlaceholder": "Please enter the verification code"

So, when the user switches the website language, the hint text of the captcha will change accordingly.

2. Internationalization of captcha error information

The error message for the captcha, such as "Captcha is incorrect" or "Captcha has expired", usually returned by the backend API after the user submits the form. In the document.tag-/anqiapi-other/167.htmlThe example also confirms this point, it goes throughfetch('/api/captcha')requesting the backend, and processing in the callback functionres.msgThis is exactly the error message returned by the backend.

Since these error messages aresystem built-in levelGenerated dynamically by the AnQiCMS backend API, they will be affected by全局功能设置in默认语言包Configuration effects.This means that when the default language package of AnQiCMS is set to English, the backend will also automatically display the verification code error information in English (if the system has defined an English translation for the error).

Therefore, for such error messages generated by the system backend, we usually do not need to use it additionally in the frontend template{% tr %}Label processing, AnQiCMS will automatically return the corresponding multilingual error prompt according to the current system language package.

How to fully utilize AnQiCMS to implement captcha internationalization

Ensure that the captcha prompt text and error messages support multilingual switching and internationalization well, you can follow the following steps:

  1. Configure the default language package:In the AnQiCMS backend,全局功能设置Make sure,默认语言包Set it correctly and understand its impact on the system's built-in text (including error messages returned by the backend).
  2. Use translation tags:For the hard-coded captcha-related text in the front-end template (such asplaceholder/labelText),using{% tr "yourKey" %}translate tags to wrap. At the same time, inlocalescreate the corresponding translation files for all supported languages under the directory, and define eachkeycorresponding multilingual text.
  3. Front-end language switch:If your website needs users to switch languages on the front end, you can获取多语言站点列表标签({% languages %}) to build a language switcher, guide the user to select the appropriate language. Once the language is switched, all uses of{% tr %}The text of the label and the backend system error information (if the backend can detect the current session language and return the corresponding language) will be updated accordingly.

Summary

AnQiCMS provides comprehensive support for the multi-language switching and internationalization of captcha prompt text and error messages. The prompt text is handled through the front-end template.翻译标签 {% tr %}Implementation, while error messages depend on the backend system according to the configuration默认语言包Perform output. By reasonably utilizing these features, your AnQiCMS website can easily cater to the needs of users in different languages, providing a smooth and localized user experience.


Common Questions (FAQ)

1. If I want to add a language that AnQiCMS does not have built-in (for example, Spanish), how will the captcha prompts and error messages be displayed?

答:For the captcha prompt text, you can add Chinese and English, just like adding Chinese and English,localesdirectory createes/default.ymland Spanish translation files,{% tr "yourKey" %}tags