1. Home
  2. Docs
  3. Llamachant Framework Modules
  4. Extended Functionality
  5. Localization Attribute

Localization Attribute

When creating a multi-language application, there are often times where you need to localize text from within a controller. Typically this is done by adding a new entry to the Localization node in the model. Then it must be translated by switching model languages. Because this tends to take a long time and lead to missed language translations, we decided to add the Localization Attribute that you can use within your controllers. The example below defines the text to use for each language right in the controller so you can see it from one place. Note that if you don’t specify a language option, it becomes the default text for all languages.

				
					[LocalizedText("MyExceptionText", "I told you this doesn't do anything...")] //Default text
    [LocalizedText("MyExceptionText", "Mówiłem Ci, że to nic nie robi...", "pl-PL")] //Polish Localization
    [LocalizedText("MyExceptionText", "Le dije que esto no hace nada...", "es")] //Spanish Localization
    public class ActionLocalizationSampleController : ViewController
    {
        public SimpleAction MyAction { get; private set; }

        public ActionLocalizationSampleController()
        {
            MyAction = new SimpleAction(this, nameof(MyAction), DevExpress.Persistent.Base.PredefinedCategory.Unspecified);
            MyAction.Execute += MyAction_Execute;
        }

        private void MyAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            throw new UserFriendlyException(this.GetLocalizedText("MyExceptionText"));
        }
    }
				
			
Automatically Created Localization Node
Was this article helpful to you? Yes 2 No

How can we help?