安企CMS, as an enterprise-level content management system developed based on Go language, is committed to providing efficient and customizable solutions for small and medium-sized enterprises and content operation teams.In today's global internet environment, multilingual support is no longer an optional feature, but a core function for expanding markets and enhancing user experience.localesThe folder undoubtedly plays a crucial role, which is the key to translating static text in the front-end template.
localesThe folder plays a core role in the multi-language settings of AnQiCMS.
In short,localesThe folder is the 'translator' at the AnQiCMS template level.It is specifically used to manage all static text content that requires multilingual translation in the front-end templates of websites, such as navigation menu items, button text, page titles, prompts, copyright statements, and other user interface (UI) elements.localesThe folder was created for this purpose.
Imagine that your website needs to support Chinese, English, and French.If you add a language, you will need to manually modify the corresponding text in the template file, which will be a huge and error-prone task.localesThe folder introduces a set of key-value translation system, decoupling these static texts from the template code. In this way, no matter how many languages your website needs to support, you do not need to change the template structure, just inlocalesAdd or modify translation files in the folder to easily switch the interface language.
localesExplanation of the folder's working mechanism.
AnQiCMSlocalesThe folder is usually located in the root directory of the template theme you are using (i.e.,/template/您的模板名/locales). Within this folder, you will create a separate subdirectory for each supported language, such aszh-cnFor Simplified Chinese,en-usFor American English,frfor French and others. Each language subdirectory will contain one or more YAML formatted translation files, usually nameddefault.yml.
These YAML files internally store a series of key-value pairs (Key-Value Pair).Where “Key” is a unique identifier referenced in the template, and “Value” is the translation text of this key in a specific language.zh-cn/default.ymlin, you may define"yourLocation": "您的位置"; while inen-us/default.ymlin English, the corresponding definition is"yourLocation": "Your location".
When you need to display this text in AnQiCMS template files, you no longer write "Your location" directly, but use the AnQiCMS provided{% tr "key" %}Translate label. For example, you will enter in the template{% tr "yourLocation" %}When the user visits your website, AnQiCMS will automatically search from the corresponding language subdirectory based on the user's current language settings (or the default language configuration of the website)default.ymlfile, extract outyourLocation键所对应的“值”,并将其动态地呈现在网页上。这样,即便您的网站有数十种语言版本,所有UI文本的切换都将是无缝且自动的。
localesEnglish translation: With the collaborative strategy of AnQiCMS multilingualism.
It is worth noting that,localeslocalesThe translated content of the folder in the front-end template is different.
Additionally, AnQiCMS supports managing multiple sites through the multi-site management feature, allowing independent domain names and content to be configured for sites of different languages,配合Hreflang标签(可由languagesTag generation), achieving a multilingual site structure friendly to search engines.localesThe folder is an indispensable part of this multilingual strategy, ensuring that users can not only see the translated dynamic content when browsing different language versions of the site, but also experience a fully localized user interface.
In summary,localesThe folder is the core mechanism of AnQiCMS for implementing the front-end multi-language interface translation.It greatly simplifies the development and maintenance of multilingual websites through structured file management and easy template tag calls, providing website operators with great flexibility and convenience, allowing the website to face global users in a more friendly and professional manner.
Common Questions (FAQ)
1.localesIs the folder only used to translate the text in the front-end template?Yes,localesThe folder is mainly used for managing and translating the hardcoded static text content in AnQiCMS front-end templates, such as navigation menus, button labels, copyright information, and other user interface elements.For articles, product descriptions, category names, and other dynamic content, you usually need to create or edit separate data entries for each language in the backend, or manage them through the multi-site feature.
2. The “Default Language Package” setting of AnQiCMS backendlocalesWhat is the difference between the folder?AnQiCMS backend "Global Settings" "Default Language Pack" mainly affects the built-in prompt information, backend management interface text, etc., which changes the core language display provided by the AnQiCMS program itself.localesFolder is responsible for translating the text you use in custom template files{% tr "key" %}Label introduction of the text content you define by yourself. Both serve different translation levels and together improve the multilingual environment of AnQiCMS.
3. If my template does not use{% tr "key" %}Label, thenlocaleswill the folder still work?No.localesthe translation content in the folder will only be used if the template file passes through{% tr "key" %}The label will be loaded and applied only when explicitly called. If the static text in your template has not been{% tr %}Label wrapping, AnQiCMS will not attempt to translate it, but will directly display the original text content in the template. Therefore, to implement a multilingual interface, it is necessary to use the template correctly{% tr %}Label.