How to implement multilingual content switching and display in AnQiCMS templates?

As an experienced website operations expert, I am willing to deeply analyze the powerful capabilities of AnQiCMS in multi-language content switching and display.Today, as globalization becomes increasingly prevalent, making website content accessible to users of different languages has become a key factor for enterprises to expand their markets and enhance their brand influence.AnQiCMS, as an efficient and customizable content management system, naturally also provides a mature and flexible solution in this aspect.


How to implement multilingual content switching and display in AnQiCMS templates?

When building a website for a global audience, multilingual support is indispensable.AnQiCMS understands this and provides a highly effective and flexible mechanism that allows you to easily switch and display multilingual content in templates, thereby providing users from different regions with a localized browsing experience.

AnQiCMS mainly implements multilingual throughSystem language package, template translation tagsas well asMulti-site / content management strategyCompleted by combining, with the support of front-end language switching logic and SEO-friendlyhreflangSet.

Understand the multilingual foundation of AnQiCMS: system language packages and template translation

First, AnQiCMS provides multilingual support at the system level.In the background "Global Function Settings", you can select the website "Default Language Pack", the system built-in Chinese and English and other language options.This setting mainly affects the language of the AnQiCMS backend interface and some built-in system prompts.

But you might be curious, this is just the system's own language, so how is the content of the website's front-end translated? Don't worry, AnQiCMS provides strongtemplate translation tags——{% tr "关键词" %}.

  1. Set language package fileTo use{% tr %}Label, you need to create a named file under the template directory you are currently usinglocalesfolder. In thislocalesInside the folder, create a subfolder for each target language, for exampleen-usRepresents American English,zh-cnRepresents Simplified Chinese. Create a folder within each language folderdefault.yml(or any other name) file, used to store the translation key-value pairs for the language.

    For example, yourlocales/zh-cn/default.ymlMay include:

    "yourLocation": "您的位置"
    "contactUs": "联系我们"
    

    Andlocales/en-us/default.ymlIt will be:

    "yourLocation": "Your Location"
    "contactUs": "Contact Us"
    
  2. Use translation tags in the templateOnce the language package file is set up, you can use it happily in the template.{% tr %}Labels to display the corresponding language text. For example, in your template file (such asheader.htmlorfooter.html) in the file, you do not need to hardcode 'Contact us', but write it as:

    <div>{% tr "contactUs" %}</div>
    

    When a user visits the website, AnQiCMS will automatically search for the corresponding language package file based on the current language environmentcontactUsTranslation and display. In this way, the navigation, footer information, button text, and other static content of the website can easily achieve multi-language switching.

Part two: the management strategy of multi-language dynamic content

For articles, products, and other dynamically generated content, the multi-language implementation strategy needs more detailed planning, AnQiCMS provides several flexible ideas:

  1. Multi-site management (recommended)AnQiCMS is one of its highlights for its powerful multi-site management function.You can set up an independent 'site' for each language, even though these sites are all running on the same AnQiCMS instance.For example, you canwww.yourdomain.com/en/Set to English site,www.yourdomain.com/zh/Set to Chinese site, oren.yourdomain.comandzh.yourdomain.com.

    In this mode, each language site has its independent documents, categories, tags, and so on.You need to manually create and translate content for each language version and publish it under their respective sites.This may mean that the workload of content entry increases, but it brings clarity to content management, with each language version of the content being completely independent and able to support more complex localization needs, such as displaying different products or services for different language versions.

    When calling different site data in the template, many tags (such asarchiveList/categoryList/systemsuch assiteIdParameters, allowing you to accurately obtain data from specified language sites.

  2. Content model and custom fields (auxiliary)For certain scenarios, you can also use custom fields in the content model to store content in different languages. For example, you can add to the article modelTitle_en/Content_enThis method is suitable for smaller content volumes, or relatively simple content structures, and when you do not want to maintain multiple 'sites'.

    However, this method requires additional logical judgments when rendering templates (such as{% if current_language == "en" %}{{archive.Title_en}}{% else %}{{archive.Title}}{% endif %}), and it may not be as intuitive in the backend management as the multi-site mode, content editors need to ensure that all language fields are updated.

3. Front-end language switching and SEO optimization

To enable users to switch between different language versions and to achieve better ranking in search engines, the following two aspects are crucial:

  1. Language switcherAnQiCMS provides{% languages websites %}Labels can help you easily build a language switch menu on the front end.This tag will return all configured multilingual site information, including language names, language codes, and corresponding link addresses.

    You can use it in the template like this:

    {%- languages websites %}
    {%- if websites %}
    <nav class="language-switcher">
        <span>切换语言:</span>
        {%- for item in websites %}
        <a href="{{item.Link}}" {% if item.Language == current_lang_code %}class="active"{% endif %}>
            {%- if item.LanguageIcon %}
            <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}"/>
            {%- else %}
            {{item.LanguageEmoji}}
            {% endif %}
            {{item.LanguageName}}
        </a>
        {%- endfor %}
    </nav>
    {%- endif %}
    {%- endLanguages %}
    

    In this way, users can click on the link to directly jump to the website version of the corresponding language.

  2. hreflangTags (SEO key)To tell search engines that your website has multiple language versions and that these versions are interconnected, you need to include in the HTML's<head>Area additionhreflangtag. AnQiCMS's{% languages %}Tags can also be used to generate these SEO-friendly meta information:

    {%- languages websites %}
    {%- for item in websites %}
    <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
    {%- endfor %}
    {%- endLanguages %}
    

    This setting can effectively prevent search engines from treating different language versions of content as duplicate content, and help users see the most suitable pages for their language preferences and geographic locations in search results.

Summary

AnQiCMS through a comprehensive strategy, allows the website's multilingual functionality to be flexible implemented.From language package configuration on the backend, to translation tags in templates, and to multi-site management mechanisms and front-end language switchers, each link aims to provide you with a solution that meets localization needs while also balancing operational efficiency and SEO effects.Whether it is a startup hoping to expand into the overseas market or a content operator who needs to manage multiple language versions of content, AnQiCMS can provide solid technical support.


Frequently Asked Questions (FAQ)

  1. Q: Does AnQiCMS support automatic translation functionality, or is it necessary to manually translate all content?A: AnQiCMS itself does not provide automatic translation functionality.Multilingual content requires manual translation and entry. This design is to ensure translation quality and content accuracy, as machine translation often cannot reach the level of professional human translation, especially when involving professional terminology or marketing copy.Of course, you can combine external translation services or tools to assist in your translation process.

  2. **Q: How to set up independent domain names for websites in different languages (such asen.yourdomain.com) or subdirectory (such aswww.yourdomain.com/en/)