【en】Contact Information Label: How to intelligently switch display in a multi-language environment?

In today's globalized business environment, multilingual support for websites is no longer an option, but a necessary capability for enterprises to expand into the international market.For enterprises that use a content management system (CMS) to build and manage websites, how to efficiently handle multilingual content, especially for key information like contact details, is a common concern for operators.AnQiCMS, as a system focusing on providing enterprise-level content management solutions, naturally attracts attention for its multilingual performance.

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 a senior operations expert, my answer is:Anqi CMS'scontactThe tag itself does not have a built-in parameter to automatically switch contact information based on the user's access language, but the system offers great flexibility. By cleverly combining its 'custom parameters' feature with conditional judgment at the template layer, this requirement can be elegantly achieved.

Next, let's delve into how to implement this feature in AnQiCMS.

AnQiCMS Overview of Multilingual Capabilities

Contact Information Tag (contact) Current Status and Challenges

AnQiCMS provides convenientcontacttags, used to call the contact information configured in the background in templates. For example, we can easily{% contact with name="Cellphone" %}to get the contact phone number, or{% contact with name="Wechat" %}[show WeChat ID. 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,contact[The tag currently does not provide a parameter directly (such as]language="en"orlocale="zh"),Let us be able to directly pull the contact information corresponding to the current website's language environment. This means that if we only set one in the background,CellphoneA field, which will display the same value on all language versions of the website.This is a 'challenge' for businesses that need to provide localized contact information for different countries or regions.

Solution: Flexibly use custom parameters and conditional judgments

It is fortunate that AnQiCMS's powerful customization capabilities provide us with a perfect solution. We can achieve the automatic multilingual switching display of contact information through the following steps:

Step one: Configure multilingual contact information in the background

Go to the "Background Settings" -u003e "Contact Information Settings" page on AnQiCMS backend. Here, we will no longer use only the defaultCellphone/EmailInstead of having a single field for all languages, a custom field is 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 parameters:
    • Parameter name:Cellphone_ENParameter value:+1-XXX-XXXX-XXXX(Note: English Customer Service Phone)
    • Parameter name:Email_ENParameter value:[email protected](Note: English Customer Service Email)
    • Parameter name:WhatsApp_ENParameter value:+1-XXX-XXXX-XXXX(Note: English WhatsApp)
    • Parameter name:Cellphone_ZHParameter value:+86-XXX-XXXX-XXXX(Note: Chinese Customer Service Phone)
    • Parameter name:Email_ZHParameter value:[email protected](Note: Chinese Customer Service Email)
    • Parameter name:Wechat_ZHParameter value:yourwechatid(Note: Chinese WeChat ID)

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

Step 2: Get the current website language environment

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

Step 3: Implement conditional logic in the template

With multilingual contact information and the current language environment, we can write logic in the template file to display the corresponding contact information based on the current language.

Assuming your template needs to display contact phone number 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 astag-tr.mdThe said)is used to translate fixed text in the template, ensuring the consistency of the language of interface elements.

In this way, when the user accesses the English version of the website, the template will automatically detectcurrent_languageresponse forenand displayCellphone_EN/Email_ENThe value of this field; while accessing the Chinese version of the website, it will displayCellphone_ZH/Email_ZHetc.

Considerations in practical applications

  1. Maintenance costs:This method is flexible, but each time a language or a contact method is added in 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 communication 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 for all languages entered in the background 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 requirements are very complex, or if different language versions require completely independent operation and content strategies, then set up an independent site for each language (for example)en.yourdomain.comandcn.yourdomain.comThe configuration of contact information independently at the back-end of each site is also a viable option. In this case, each site'scontactThe label will directly call the contact information of the site it is located in, without complex template judgment logic.

Summary

Although the AnQiCMScontactThe tag 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 custom contact method fields in the background and combining language judgment logic in the templates, you can provide precise localized contact information for users of different languages, thereby enhancing user experience and helping enterprises expand in the global market.This 'combination punch' solution is a vivid illustration of AnQiCMS embodying its 'efficient, customizable, and easy to expand' values in practice.


Common Questions (FAQ)

1. Can I implement multilingual switching for only some contact information fields (e.g., only email) while keeping the other fields unchanged?It is absolutely fine. You just need to create custom parameters in the backend for the fields you want to implement multi-language switching (for example,Email_ENandEmail_ZHFor those fields that are universally applicable across all languages (such as perhaps all languages use the same global service hotline), you can still directly use the defaultCellphoneField, no need to create a multilingual variant for it. The template containsifthe judgment will only take effect for the multilingual fields you specify.

2. Usetag-tr.mdtranslation tags mentioned{% tr "..." %}Can the contact information be translated directly?Cannot.{% tr "..." %}Labels are mainly used to translate hard-coded static text strings in templates, such as interface elements like 'Contact Us', 'Phone', 'Email', etc. It cannot