Developer forum

Forum » CMS - Standard features » Translate Contact Us Form

Translate Contact Us Form

Tin Ma Ma
Reply

Hi

Please advise me how can I translate conatct us form?


Regards,

Tin Ma Ma

 

Image_1.png Image_2.png

Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Tin Ma Ma

That is currently not possible from the form administration. You have 2 other options though:

  1. Create a copy of the form and translate that
  2. When running on the Auto rendering option for the forms app, it uses @Translate method. That means that the form can be translated from the website node: See manual: https://doc.dynamicweb.com/documentation-9/platform/advanced-settings/translations-link#3269

BR Nicolai

Votes for this answer: 1
 
Tin Ma Ma
Reply

Hi Nicolai,

Thank you for your advice.
Point 2, Dropdown field cannot use @Translate method.

Regards,

Tin Ma Ma

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Good point. It can be done by adding this code to your Form Template:

if (fieldType == "Checkboxlist" || fieldType == "Radio" || fieldType == "Select")
                    {
                        foreach (LoopItem option in field.GetLoop("Options"))
                        {
                            string optionText = option.GetString("Option.Text");
                            fieldControl = fieldControl.Replace(optionText, Translate(optionText));
                        }
                    }

It is a bit hacky and will not work with option texts like

[] a
[] Click for a

Since a would be replaced both places causing it not to translate...

Alternatively you can render the options manually in the template - something like this (Example not done):

if (fieldType == "Checkboxlist" || fieldType == "Radio")
                    {
                        foreach (LoopItem option in field.GetLoop("Options"))
                        {
                            int optionId = option.GetInteger("Option.ID");
                            bool optionActive = option.GetBoolean("Option.Active");
                            bool optionDefaultSelected = option.GetBoolean("Option.DefaultSelected");
                            string optionValue = option.GetString("Option.Value");
                            string optionText = option.GetString("Option.Text");
                            string optionChecked = "";
                            string optionHtmlId = String.Format("{0}{1}", fieldSystemName, optionId);
                            if(optionDefaultSelected && String.IsNullOrEmpty(fieldValue)) {
                                optionChecked = " checked";
                            }else if(!String.IsNullOrEmpty(fieldValue)){
                                if (fieldValue.Split((char)',').Contains(optionValue) || fieldValue == optionValue) {
                                    optionChecked = " checked";
                                }
                            }
                            fieldControl = string.Format("<input type=\"{0}\" /> <label for=\"{1}\">{2}</label><br>", fieldType, optionHtmlId, optionChecked, optionText))
                        }
                    }

                    if (fieldType == "Select")
                    {

fieldControl = "<select xxx>"
foreach (LoopItem option in field.GetLoop("Options"))
{

fieldControl += "<option xxxx>"

                        }

fieldControl += "</select>"
                    }

 

BR Nicolai

Capture.PNG
Votes for this answer: 1
 
Tin Ma Ma
Reply

Hi Nicolai,
 

Thank you for your advice.

Regards,

Tin Ma Ma

 

You must be logged in to post in the forum