In today's globalized digital world, whether a website can overcome language barriers and directly reach users from different cultural backgrounds often determines its market breadth and influence.Auto CMS is well-versed in this, providing users with a powerful and flexible multilingual support feature.As an experienced website operations expert, I fully understand the importance of an efficient multilingual management mechanism for enhancing user experience and expanding global business..ymlThe file is the core tool to achieve this goal.

This article will take you in-depth understanding of the AnQiCMS multilingual translation feature.ymlThe writing and management strategy of files, helping you transform technical details into practical operational wisdom.

The core of AnQiCMS multilingual system:localesDirectories and.ymlFile

The multilingual support of AnQiCMS is not a simple text replacement, but a well-structured and easy-to-maintain system. Its core lies in the template root directory.localesFolder and its contents..ymlLanguage package file.

Imagine that your website needs to support Chinese (Simplified), English, and even Japanese. AnQiCMS will suggest that you create a directory namedlocalesThe folder. In this folder, you need to create an independent subdirectory for each target language, for example:)

  • zh-cn(representing Simplified Chinese)
  • en-us(representing American English)
  • ja(representing Japanese)

These language codes follow international standards, ensuring the system's recognition and compatibility.

Each language subdirectory usually contains one or more.ymlfiles, the most common and recommended naming isdefault.yml.YAML (Yet Another Markup Language) files are designed with a concise and intuitive key-value pairs structure, making them very suitable for storing static text content in various languages.

Let's look at a simplified example to understanddefault.ymlThe structure is:

# 文件路径: ./locales/zh-cn/default.yml
welcomeMessage: "欢迎来到我们的网站!"
yourLocation: "您的位置"
readMore: "阅读更多"
contactUs: "联系我们"
submitButton: "提交"

# 文件路径: ./locales/en-us/default.yml
welcomeMessage: "Welcome to our website!"
yourLocation: "Your location"
readMore: "Read More"
contactUs: "Contact Us"
submitButton: "Submit"

In this structure,welcomeMessage/yourLocationare unique key names (or called translation IDs), they are in all languagesdefault.ymlKeep consistent in the document.The text after the colon is the translation content in the corresponding language.This design completely separates the website interface text from the code logic, greatly improving the maintenance efficiency of multilingual websites.

to refer to the translation content in the template:{% tr %}The magic use of tags

When your multilingual dictionary (i.e.,.ymlfile) is ready, how can you elegantly apply them in the website template? AnQiCMS provides a simple and powerful{% tr %}translation tags.

In your AnQiCMS template files (usually.htmlsuffix), you do not need to write text in various languages directly. Instead, you just need to use{% tr %}tags, and pass in the.ymlFile-defined key name. For example:

<nav>
    <a href="/">{% tr "yourLocation" %}</a>
    <a href="/contact">{% tr "contactUs" %}</a>
</nav>

<h1>{% tr "welcomeMessage" %}</h1>
<button>{% tr "submitButton" %}</button>

When the user visits the website, AnQiCMS will automatically load the corresponding language package file based on the current site settings (or the language selected by the user). For example, if the user visits the Chinese site, the system will loadzh-cn/default.ymlso that{% tr "welcomeMessage" %}The display will be 'Welcome to our website!';while if the user switches to the English site, the system will loaden-us/default.yml,同样的标签将显示为“Welcome to our website!”。

This dynamic loading mechanism allows you to write a single template that can easily support multiple language displays, greatly reducing the redundancy and maintenance costs of the template.

Careful management and efficient practice

To make full use of the multi-language translation advantage of AnQiCMS, the following management and practical strategies are crucial:

  1. Key names should be unified and meaningful: Ensure that all languages.ymlThe key used in the file should be identical. The key name should be concise and clear, and should clearly express the meaning of the text it represents (for example, pageTitleHomeInsteadpt1This makes team collaboration easier, and also makes future maintenance and expansion more convenient.

  2. Distinguish between static text and dynamic contentThis is a common misconception in multilingual operations.

    • .ymlFile:主要用于管理网站的English静态、界面性文本EnglishFor example, navigation menu items, button text, footer statements, form prompts, system prompt information (such as "Operation successfulThis text is usually a fixed part of the website interface.
    • 后台内容管理系统English:对于文章内容、产品描述、分类名称、单页面内容等English动态、业务性内容EnglishAnQiCMS usually allows you to create and manage these contents separately for different language versions through the background content management interface. This means that you do not need to write every word of each article..ymlFile, but instead uses the powerful content model and multi-site functionality of CMS to achieve content localization. This is also one of the core advantages of AnQiCMS multi-language support.
  3. Organize reasonably.ymlFileWhen the translation text quantity of the website is large, placing all key-value pairs indefault.ymlmay seem bulky. You can create multiple.ymlfiles to organize the translation content, for example:

    • messages.yml(System prompt, welcome message)
    • forms.yml(Form fields, button text)
    • navigation.yml(Navigation menu)
    • errors.yml(Error message) This modular management approach makes it more efficient to search and update translation content. When referencing in a template, just add the filename before the key name, for example{% tr "navigation.home" %}.
  4. Use language switcher andhreflangtags:

    • Language Switcher: AnQiCMS provides{% languages websites %}Label, helps you build an intuitive language switcher on the front-end. Users can easily select their preferred language version by clicking the switch button or the dropdown menu.
    • hreflangtagsFor search engine optimization (SEO), using correctlyhreflangTags are essential. They can inform search engines that your website has multiple language versions and guide them to display the most relevant pages to users in different language regions. You can use{% languages websites %}Label cyclic generationhreflangLink, and place it in the HTML's<head>Block, for example:
      
      {%- languages websites %}
      {%- for item in websites %}
      <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
      {%- endfor %}
      {%- endlanguages %}
      
      This will help your multi