Contact information label for AnQi CMS: How to intelligently switch display in a multilingual environment?

In today's globalized business environment, multilingual support for websites is no longer an option, but a necessity for businesses to expand into the international market.For businesses that use a content management system (CMS) to build and manage websites, how to efficiently handle multilingual content, especially critical information such as contact details, is a common concern for operators.AnQiCMS (AnQiCMS) is a system focused on providing an enterprise-level content management solution, and its performance in multilingual aspects is naturally of great concern.

Then, in response to the specific question 'Does AnQiCMS contact information label support automatic switching to display corresponding language contact information based on the user's access language?', as an experienced operations expert, my answer is:Of Security CMScontactThe tag itself does not have a built-in parameter to automatically switch contact information based on the user's access language, but the system provides high flexibility, which can perfectly meet this need by skillfully combining its 'custom parameter' function and the 'condition judgment' at the template level.

Let's delve into how to implement this feature in AnQiCMS.

Overview of the multilingual capabilities of AnQiCMS

Firstly, it is worth mentioning that AnQiCMS fully considered the needs of multilingual promotion from the beginning of the project design.According to the project advantage document, one of the core functions of Anqi CMS is 'multilingual support', which aims to 'help enterprises expand into international markets, allowing content to be directly addressed to users of different languages.'This lays the foundation for us to implement multilingual switching on the contact information.The system can handle the switching and display of multilingual content, including pages, articles, etc., but for information like contact details that are stored in the system's global settings and are not the main content, we need to adopt some customized strategies.

Contact label (contactThe current situation and challenges of )

AnQiCMS provides convenientcontactA label used to call the contact information configured in the background template. For example, we can easily get{% contact with name="Cellphone" %}to get the phone number, or{% contact with name="Wechat" %}to display the WeChat number. In addition,help-setting-contact.mdThe document clearly states that in addition to the preset fields such as contacts, phone numbers, addresses, and email addresses, the system also supports "custom settings parameters".This means we can add any number of contact information fields according to our needs.

However,contactThe tag does not provide a parameter directly (such aslanguage="en"orlocale="zh"),Let us be able to directly pull the contact information in the corresponding language based on the current language environment of the website. This means that if we only set one in the backgroundCellphoneThe field will display the same value on all versions of the website in any language.This is a challenge that needs to be addressed for enterprises that need to provide localized contact information for different countries or regions.

Solution: Flexible use of custom parameters and conditional judgment

Fortunately, AnQiCMS's powerful custom capabilities provided us with a perfect solution. We can achieve the automatic multi-language switching display of contact information through the following steps:

Step 1: Configure multilingual contact information in the background

Go to the AnQiCMS backend's 'Backend Settings' -> 'Contact Information Settings' page. Here, we will no longer only use the defaultCellphone/EmailFields are not translated, but custom fields are created for each target language.

For example, if your website needs to support Chinese and English, you can configure it like this:

  • Default field (or primary language field):
  • Custom parameter:
    • Parameter name:Cellphone_EN, Parameter value:+1-XXX-XXXX-XXXX(Note: English customer service phone number)
    • Parameter name:Email_EN, Parameter value:[email protected](Note: English customer service email)
    • Parameter name:WhatsApp_EN, Parameter value:+1-XXX-XXXX-XXXX(Note: English WhatsApp)
    • Parameter name:Cellphone_ZH, Parameter value:+86-XXX-XXXX-XXXX(Note: Chinese Customer Service Phone)
    • Parameter name:Email_ZH, Parameter value:[email protected](Note: Chinese Customer Service Email)
    • Parameter name:Wechat_ZH, Parameter value:yourwechatid(Note: Chinese WeChat ID)

In this way, we ensure that all language contact information has its independent storage location.

Step two: Get the current website language environment

AnQiCMS allows us to obtain the current website language setting in the template. By{% system with name='Language' %}tags, we can dynamically obtain the language code of the current visitor (for examplezh-CN/en-USwait). This is the key basis for conditional judgment.

Step three: Implement conditional logic in the template.

With multi-language contact information and the current language environment, we can write logic in the template file to display the corresponding contact information according to the current language.

Assuming your template needs to display contact information and email, and you have configured the custom parameters as shown above, you can write the template code like this:

{# 获取当前网站的语言代码 #}
{% set current_language = system.Language %}

<div class="contact-info-section">
    <h3>{% tr "联系我们" %}</h3> {# 使用翻译标签显示静态文本 #}

    {% if current_language == "en-US" or current_language == "en" %}
        {# 显示英文联系方式 #}
        <p>
            <span>{% tr "电话" %}:</span>
            <span>{% contact with name="Cellphone_EN" %}</span>
        </p>
        <p>
            <span>{% tr "邮箱" %}:</span>
            <span>{% contact with name="Email_EN" %}</span>
        </p>
        <p>
            <span>WhatsApp:</span>
            <span>{% contact with name="WhatsApp_EN" %}</span>
        </p>
    {% else %}
        {# 默认显示中文或其他语言联系方式 #}
        <p>
            <span>{% tr "电话" %}:</span>
            <span>{% contact with name="Cellphone_ZH" %}</span>
        </p>
        <p>
            <span>{% tr "邮箱" %}:</span>
            <span>{% contact with name="Email_ZH" %}</span>
        </p>
        <p>
            <span>{% tr "微信" %}:</span>
            <span>{% contact with name="Wechat_ZH" %}</span>
        </p>
    {% endif %}
</div>

In this code block:

  • We first use{% set current_language = system.Language %}To get the current language identifier.
  • Then, through{% if ... else ... %}structure based oncurrent_languageThe value to determine which group of contact information should be displayed.
  • {% tr "电话" %}Such labels (such as)tag-tr.mdAs described) are used to translate fixed text in templates to ensure language consistency of interface elements.

In this way, when a user visits the English version of the website, the template will automatically detectcurrent_languageWithenand displayCellphone_EN/Email_ENthe values of such fields; whereas, when visiting the Chinese version of the website, it will displayCellphone_ZH/Email_ZHetc.

considerations in actual application

  1. Maintenance cost:This method is flexible, but every time a language or a contact method is added to the background, the corresponding custom parameters need to be manually added and maintained.This is not a problem for a small number of languages and contact methods, but it may increase some management burden if the number is large.
  2. Data consistency:It is crucial to ensure that the contact information entered in the background for all languages is accurate and error-free to avoid problems caused by manual input errors.
  3. Alternative to the multi-site mode:AnQiCMS also supports the "multi-site management" feature. If your multilingual needs are very complex, or if different language versions require completely independent operations and content strategies, then set up an independent site for each language (for exampleen.yourdomain.comandcn.yourdomain.com), and independently configure contact information on the backend of each site is also a viable option. In this case, each site'scontactThe tag will directly call the contact information of the site it is located on, without the need for complex template judgment logic.

Summary

Although AnQiCMS'scontactThe label does not provide a one-click multilingual switch function, but its excellent customization capabilities and flexible template engine are more than capable of meeting this need.By carefully designing a custom contact information field in the background and combining it with the language judgment logic in the template, you can provide localized contact information that matches different language users accurately, thereby enhancing the user experience and helping enterprises to expand in the global market.This 'combination拳' solution is a vivid illustration of how AnQiCMS embodies its 'efficient, customizable, and easy to expand' value in practice.


Frequently Asked Questions (FAQ)

1. Can I switch languages only for part of the contact information fields (such as only email) while keeping other fields unchanged?It is completely possible. You just need to create custom parameters in the background for the fields you want to switch languages for, such asEmail_ENandEmail_ZHFor those fields that are universally applicable in all languages (for example, for a global service hotline that may be used in all languages), you can still use the defaultCellphonefield, it does not require the creation of multilingual variants. It is in the template ofifthe judgment will only apply to the multilingual fields you specify.

2. Usetag-tr.mdmentioned translation tags{% tr "..." %}Can the contact information be directly translated?No.{% tr "..." %}The tag is mainly used for translating hard-coded static text strings in templates, such as the "Contact Us", "Phone", "Email" and other similar items on the interface. It cannot