As an experienced website operations expert, I fully understand that building an efficient and easy-to-manage multilingual website is crucial for expanding the market and enhancing user experience.AnQiCMS (AnQiCMS) leverages the powerful performance and flexible design of the Go language to provide us with excellent multilingual support.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.
Guide to the exquisite template file directory structure of AnQiCMS multilingual
In today's global digital environment, having a website that supports multiple languages has become a necessary condition for businesses to reach a wider audience.AnQiCMS, as an enterprise-level content management system developed based on the Go language, demonstrates its unique advantages and flexibility in multilingual support.It not only allows content managers to easily switch between different language content, but also provides a refined template mechanism to support interface localization.The core of all this, cannot be separated from an organized template file directory structure.
Overview of the basic architecture of AnQiCMS templates
To understand the organization of multilingual templates, we first need to familiarize ourselves with the basic structure of the AnQiCMS template system. All the 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/templateThe directory has its own exclusive folder, for example/template/defaultThis folder will also contain aconfig.jsonA file 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 adaptive, code adaptation, or PC+mobile independent site mode.
AnQiCMS template engine is similar to Django syntax, using.htmlAs a template file suffix, static resources such as CSS, JavaScript, and images are stored in/public/static/Directory, this helps to separate front-end and back-end and efficiently manage static resources.
Understand the organization of multilingual templates in depth: a duet of content and interface.
AnQiCMS multilingual support is not simply a copy of multiple sets of website code, but through clever design, allows content and interface elements to achieve seamless language switching.
Content language differentiation: support at the data level
AnQiCMS has built-in powerful multilingual mechanisms at the content management level.This means that, whether it's articles, products, or categories, you can create content in different languages for them in the backend.When the user switches the language on the front end, AnQiCMS will intelligently call the corresponding language version of the content on the current page to display.The key is that the content of these different language versions usually shares the same set of template files.For example, an English article and a Chinese article may both be written byarticle/detail.htmlThis template renders. The template itself does not directly translate content, but reads the corresponding language data according to the current language environment.
Localization of interface elements:localesThe magic of the catalog.
It's not enough to switch the content, the navigation, buttons, prompts, and other interface elements of the website also need to be localized according to the language environment. AnQiCMS introducedlocales(Localization) directory to elegantly solve this problem.
Under the root directory of your template (for example)/template/default/), you can create alocalesfolder. In thislocalesInside the folder, create a subdirectory for each supported language, the directory name usually uses standard language codes, such as Simplified Chinese usingzh-cn, English usesen-us. Create one or more subdirectories for each language.ymlto 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": "首页"
and in theen-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 way, no matter what language the website is currently displaying, whether it is Chinese or English,{% tr "homePage" %}It will automatically display as "Home" or "Home", realizing the dynamic switching of interface text and greatly improving the reusability and maintenance efficiency of the template.
Consideration for responsive and independent mobile templates
AnQiCMS also supports various template modes, which also need to be considered when building multilingual websites. If your website is configured to 'code adaptation' or 'PC+mobile end' mode, then you need to create an additional one in the template directorymobile/Subdirectory, used to store mobile adaptation template files. For example/template/default/mobile/index.html.
It is worth emphasizing that,mobile/The directory is used to distinguish