We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Attribute translation Short name and prompt

Thread ID:

Created:

Updated:

Platform:

Replies:

144997 May 31,2019 12:20 PM UTC Jun 3,2019 12:21 PM UTC Xamarin.Forms 1
loading
Tags: SfDataForm
Alexis
Asked On May 31, 2019 12:32 PM UTC

Hi,

I use the function C.T(word to translate) to do the translation of my app. I use the pot format and not ressource method so I can't use the ressourcename as attribute.

I have a model with this code and have an issue with the attributes:

  [Display(ShortName = C.T("Transaction password"), Prompt = C.T("Enter password"))]
        [DataType(DataType.Password)]
        public string Password { get; set; }

I have the error: 

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

How can I fix this issue? What is the workarround?

Thanks,


Subburaj Pandian Veluchamy [Syncfusion]
Replied On June 3, 2019 12:21 PM UTC

Hi Alexis, 
  
Thank you for contacting Syncfusion support. 
  
We have analyzed the reported query “How to use an attribute with the method as parameter value?” attribute parameter should be a constant value since they are evaluated at compile time, your method value can change at runtime. 
  
You can achieve your requirement by using AutoGeneratingDataFormItemevent, in which you can set Labeltext and PlaceHolderText using custom methods to Translate. Please refer the following code, 
 
Code Snippet: 
 
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e) 
{ 
         if(e.DataFormItem != null) 
          { 
                if(e.DataFormItem.Name == "Password") 
                { 
                    e.DataFormItem.LabelText = Translate(e.DataFormItem.Name); 
                    e.DataFormItem.PlaceHolderText = Translate("Enter password"); 
                } 
          } 
    } 
  
Kindly refer the following KB for more information about changing placeholder text,  
 
  
We have prepared a sample for the same, 
 
Sample link: DataForm 
  
We hope this helps. Kindly revert us if you have any concern. 
 
Regards,
Subburaj Pandian V 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon