How to localize strings in Attributes?

I want to localize some strings in Attributes.

Here is an example:

        [StringLength(255, MinimumLength = 1, ErrorMessage = "Please enter a unique name.")]
        [Required]
        [Category("Standard")]
        [Description("Name des selektierten Elements")]
        [DisplayName("Name")]
        public new string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                    HasChanges = true;

                this.RaiseAndSetIfChanged(x => x.Name, ref _name, value);
            }
        }

Resharper recognizes "Name" in [DisplayName("Name")] as localizable, but doesn't offer a "move to resource" context action.

Strangely it works for the on "Please enter a unique name." in the StringLength attribute.

Is there a way to make it work for DisplayName, Description etc.?

Regards,
Gunter

2 comments
Comment actions Permalink

It works for StringLenght as this attribute supports resouce files directly via a key and a resource type and R# 7 added a new feature to support move to resoucefile..
For the other ones you have to create new attributes which inherit from DisplayName (because the designer is looking for that type) etc. Not sure if you can build it similar to StringLenght, I mean the key property and the resourcetype property. Depends on how you have to call the base class and what you can overwrite.

By the way I opened a you track issue as I need this resource feature for our own attributes too. We have a key property and a resourcetype property. Is there some way to tell resharper about it so that it supports move to resources?

0
Comment actions Permalink

If you need a tool to better organize the strings localization process, have a look at the l10n platform POEditor

It has some really cool localization automation features and it's also a good solution to manage collaborative translation.

0

Please sign in to leave a comment.