"Move to resource" doesn't appear...

Hi everyone.

I have a MVC3 solution under .NET 4 VS2010.

In my classes i see the strings underlined with the "Localizble String:xxxxx" warning... but no "Move to Resource" option appears...

I guess it's cause R# can't find my resource file... maybe because it's not called as the file where the string is, and it's in another project (I have a project for all the .resx files) so I can update literals without having to update the whole solution's dlls.

My classs is are at:

xxxxxxx.Client.Web/Areas/xxxxxx/Models/MyEntityModel.cs
xxxxxxx.Client.Web/Areas/xxxxxx/Controllers/MyEntityController.cs
xxxxxxx.Client.Web/Areas/xxxxxx/Views/MyEntity/Index.cshtml

My resource string file is at:

xxxxxxx.Client.Web.Localization/Areas/xxxxxx/MyEntityStrings.cs


I wanted to put all "MyEntity" strings in the same file as all of them are related to the same entity, and have them in a separate project .... but I can't make R# to work, no "Move to Resource" menu...

I've already tried to set the .resx Custom Tool to "PublicResXFileCodeGenerator", my project's Localizable to Yes, Localizable Inspector to "Pessimistic" without any result...

Any hint??

My R# version is 5.1.1.1766.4

Cheers!!

4 comments

Upon further investigation... I've found it doesn't appear in certain places...

For example.. it will work in a MyClass.Title = "this is the title"; sentence at the controller... but it won't appear at a [DisplayName("this is a label")] at the viewmodel class. It won't show either at @("this is a localizable text") within my razor view...

Is that a bug? will it be solved?

Cheers

0

Hi

there is a setting Resharper -> Options -> Languages -> C# -> Localization which is called "Don't analyse verbatim strings @Hello world"
I guess this is activated and could be the source why your resource in your view is not showed as localizable.

I noticed that attributes don't have this option either however I think this is because it is technical not possible to use a resource file at this place.
AFAIK you can only use constant values as parameters.

This is why we have created a LocalozedDisplayName attribute wich extends DisplayName and look ups the given value in a resource file.
It is the same way microsoft is using for their controls.

As for your first question, have you checked that you resource file is public? IF I remember right some Jetbrains-Dev posted that Resharper marks localizable string only if there is also a resource file in you project.

0

Thanks for the respone, but the verbatim strings settings is not the issue... in fact, I use @ verbatim strings to flag the strings that doesn't have to be translated.

As for the attributes, you can in fact do it by passing them the literal keys another way, like this:

[Display(ResourceType = typeof(MyResourceClass), Name = @"Resource_Literal_Key"), Required]

This is included in MVC3 and it works perfectly...

The fun thing is that ReSharper does work with

[Range(1,long.MaxValue, ErrorMessage = "My message")]

When it finds this attribute, you can right click on the message and select "Move to resource" from the menu... you create the resource literal and then R# changes the attribute to this:

Range(1, long.MaxValue, ErrorMessageResourceType = typeof(MyResourceClass), ErrorMessageResourceName = "MyClass_MyProperty_MyMessage")]

I guess it has something to do with the Display() attribute being new or changed in the MVC3 DataAnnotations update? My suggestion is that Jetbrains would do a little fix to make this:

[DisplayName("My label")]

change to this:

[Display(ResourceType = typeof(MyResourceClass), Name = @"MyClass_MyProperty_MyLabel"), Required]

using the "Move to resource" item...

As an add... it would be really cool if they''d make resharper work with MVC3  Razor templates...

Cheers and thanks for the reply...

0

Hi

thats interesting to know. I am working with winforms applications only so I don't know those attributes. However would be nice to have some way to use this technic in winforms too.

Can some Jetbrains Dev explain me how this works with the range object and if it can be adapted to custom attributes?

Best regards,
Sven

0

Please sign in to leave a comment.