Localization with Dataform

Just wondering if it's possible to support localization with the Display, Prompt and ErrorMessages for the DataForm editors.

With this code:

[Display(ShortName = "Username", Prompt = "Enter Username")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Name should not be empty")]
[StringLength(25, ErrorMessage = "Username should not exceed 25 characters")]
public string Username
{
        get { return _username; }
        set
        {
            if (_username != value)
            {
                _username = value;
                OnPropertyChanged();
            }
        }
}

I have a resource file (AppResources.resx and AppResources.es.resx) which define the values for the shortname, prompt and both error messages, but I don't see how I can access those in this file. As a side note, I also need to support changing the language at runtime so that must be taken into account too.

6 Replies

VR Vigneshkumar Ramasamy Syncfusion Team July 2, 2018 01:09 PM UTC

Hi Teal,  
   
Regarding query with localizing validation messages.  
   
You can localize the SfDataForm validation messages using ErrorMessageResourceType and ErrorMessageResourceName Validation attributes.  
   
In which ErrorMessageResourceName attribute is used as the key for the validation message in ErrorMessageResourceType attribute which is used to declare the Resources (.Resx) file for the localization.  
   
Regarding query with localizing Display attributes such as short name, prompt and so.  
   
We have provided the localization of Display attribute support in our latest Essential Studio Volume 2, 2018 (Version 16.2.0.41) and you can localize the Display attributes such Name, prompt and so using ResoureType DisplayAttribute which is used to declare the Resources (.Resx) file for the localization.  
   
Please refer the code example for validation and display attribute localization.  
[C#]  
   
[Display(Name ="User", Prompt = "EnterUsername", ResourceType = typeof(Localization))] 
        [Required(AllowEmptyStrings =false,ErrorMessageResourceType = typeof(Localization), ErrorMessageResourceName = "EmptyString")] 
        [StringLength(25,MinimumLength =5,ErrorMessageResourceType = typeof(Localization), ErrorMessageResourceName = "StringLength")] 
        public String Username { get; set; }  
   
   
Please refer the below link for more details.  
   
We have prepared a simple sample for the same. Please find the sample from the below link,  
   
   
Note:  
Based on the culture, you need to specify the corresponding culture string value of display and validation attribute in Resource (.Resx) file. The corresponding Resoure file (.resx) value updates only when the device language changes for android and ios.  
   
Regarding support changing the language at runtime.  
As of now we do not have direct support to change the loaded SfDataForm elements with other culture localization at run time (for e.g. changing localization in button click). If the shared detail is not meet your requirement, please revert us with more details about localization through device settings or sample level , so that we could analyze further and provide you a possible solution.  
  
Regards  
Vigneshkumar R  



TW Teal Wilkes July 2, 2018 02:54 PM UTC

Thanks for the reply. I was hoping that this would be possible to change the values at runtime as that is what is really needed. I've tried changing the placeholder text via a message during runtime to the new resource value based on the selected language. The value in the debugger is showing correctly, but it's not being displayed on the UI properly. Also I'm not sure how to access the header text. This is being dones in a custom entry editor.


TW Teal Wilkes July 2, 2018 04:59 PM UTC

**Update**

I've managed to get the errors and place holder text to change at runtime. The only piece I'm missing now is the header text changing at runtime. Any ideas?


VR Vigneshkumar Ramasamy Syncfusion Team July 3, 2018 12:54 PM UTC

Hi Teal,  
   
Regarding changing the language at runtime  
   
Your requirement for changing the data form display values at run time based on culture can be achieved by using RefreshLayout method of SfDataForm which is used to refresh the data form item created.  
  
Please find the code example for changing data form display values based on culture.  
   
     private void Button_Clicked(object sender, EventArgs e)
        {
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("ja");
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("ja"); 
 
              dataForm.RefreshLayout(true);
        } 
 
   
  
Note:  
 
You need to pass the True in RefreshLayout  method to regenerate all the items from the committed data object.  
 
Also, you can refresh the particular data form item. Please refer the below link for code example.  
  
We have prepared a sample for the same. Kindly find the sample below link.  
 
 
Please let us know for further assistance.  
 
Regards 
Vigneshkumar R 



TW Teal Wilkes July 3, 2018 02:17 PM UTC

That worked thank you.


VR Vigneshkumar Ramasamy Syncfusion Team July 5, 2018 03:54 AM UTC

Hi Teal 
 
We are glad to know that your requirement has been achieved. Please get in touch if need further assistance on this.  
Regards 
Vigneshkumar R 


Loader.
Up arrow icon