As an experienced website operations expert, I know that building an efficient and easy-to-manage multilingual website is crucial for expanding the market and enhancing user experience.English CMS (EnglishCMS) provides excellent multilingual support with its powerful performance and flexible design in Go language.However, to truly bring out its advantages, a clear and reasonable template file directory structure is the foundation.
Today, let's delve into how to organize AnQiCMS multilingual template files so that your website can switch languages smoothly and maintain and expand efficiently.
Ride AnQiCMS Multilingual: Guide to the Excellent Template File Directory Structure
In today's global digital environment, having a website that supports multiple languages has become a necessary condition for enterprises to reach a broader audience.AnQiCMS, as an enterprise-level content management system developed based on the Go language, shows its unique advantages and flexibility in multi-language support.It not only allows content managers to easily switch between different languages of content, but also provides a fine-grained template mechanism to support the localization of the interface.And all of this is centered around a well-organized template file directory structure.
Overview of the Basic Architecture of AnQiCMS Templates
To understand the organization of multi-language templates, we first need to familiarize ourselves with the basic structure of the AnQiCMS template system. All front-end template files of the system are uniformly stored in the root directory of the project./templateIn the folder. Each independent template needs to be in this/templatedirectory with its own dedicated folder, such as/template/default. This folder will also contain aconfig.jsonFile, used to describe the basic information of this template, such as the template name, version, author, and most importantly—the template type.The template type determines how a website is displayed on different devices, including auto, code adaptation, or PC+mobile independent site mode.
AnQiCMS's template engine is similar to Django syntax, using English.htmlAs a template file suffix, static resources such as CSS, JavaScript, and images are stored uniformly./public/static/Directory, this helps to separate front-end and back-end and to manage static resources efficiently.
Deep understanding of the organization of multi-language templates: the duet of content and interface
AnQiCMS multi-language support is not simply a copy of multiple sets of website code, but through clever design, both content and interface elements can achieve seamless language switching.
Content language distinction: support at the data level
AnQiCMS has built-in powerful multilingual mechanisms in the content management aspect.This means that, whether it's articles, products, or categories, you can create content in different languages for them in the background.When the user switches language on the front end, AnQiCMS will intelligently call the corresponding language version of the content on the current page for display.The key is that the content in different language versions usually shares the same set of template files.article/detail.htmlThis template is used to render. The template itself does not directly 'translate' content, but rather 'reads' corresponding data based on the current language environment.
Localization of interface elements:localesThe clever use of the catalog
仅仅内容切换还不够,网站的导航、按钮、提示信息等界面元素也需要根据语言环境进行相应的本地化。AnQiCMS引入了Englishlocales(Localized)Directory to elegantly solve this problem.
In the root directory of your template (for example/template/default/),you can create alocalesfolder. In thislocalesIn the folder, create a subdirectory for each supported language, the directory name usually uses standard language codes, such as Simplified Chinese usingzh-cn, English usingen-usEach language subdirectory should have one or more.ymlfiles to store translation text in key-value pairs, for exampledefault.yml.
The structure will be roughly like this:
/template/your_template_name/
├── config.json
├── index.html
├── partial/
│ ├── header.html
│ └── footer.html
├── locales/
│ ├── zh-cn/
│ │ └── default.yml (存放中文界面的翻译文本)
│ └── en-us/
│ └── default.yml (存放英文界面的翻译文本)
└── ... 其他模板文件 ...
Inzh-cn/default.ymlIn the former, you may define:
"yourLocation": "您的位置"
"homePage": "首页"
Anden-us/default.ymlIn the latter, it corresponds to:
"yourLocation": "Your Location"
"homePage": "Home"
Then in your template file (such asheader.htmlorindex.html), you can use the translation tags provided by AnQiCMS{% tr "键名" %}to call these texts:
<nav>
<a href="/">{% tr "homePage" %}</a>
<!-- ... 其他导航项 ... -->
</nav>
<p>{% tr "yourLocation" %}</p>
This is the case whether the website currently displays Chinese or English,{% tr "homePage" %}The content will automatically display as “Home” or “Home”,which has realized the dynamic switching of interface text, greatly improving the reusability and maintenance efficiency of the template.
Responsive and independent mobile template considerations
AnQiCMS also supports various template modes, which also need to be considered when building multilingual websites. If your website is configured in "code adaptation" or "PC+mobile end" mode, then you need to create an additional directory under the template directory.mobile/Subdirectory for storing template files adapted for mobile phones. For example/template/default/mobile/index.html.
It is worth emphasizing that,mobile/Directory is used to distinguish