{"id":23,"date":"2014-08-17T13:17:00","date_gmt":"2014-08-17T13:17:00","guid":{"rendered":""},"modified":"2016-01-30T23:34:03","modified_gmt":"2016-01-30T23:34:03","slug":"resharper-localizable-string-literals","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2014\/08\/17\/resharper-localizable-string-literals\/","title":{"rendered":"Resharper &#8211; localizable string literals"},"content":{"rendered":"<p>Everyone who has ever tried to create multilingual application knows, that this is very tedious task. The most repetitive work is usually moving hard-coded strings to resource files. Fortunately with Resharper this is definitelly less painfull than usuall. <br \/>In order to point out localizable parts of  application , it is necessary to decorate classes with <i>System.ComponentModel.LocalizableAttribute<\/i>. <a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/LocalizableAttribute.png\" rel=\"attachment wp-att-302\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/LocalizableAttribute.png\" alt=\"LocalizableAttribute\" width=\"450\" class=\"aligncenter size-full wp-image-302\" \/><\/a>However, usually we want to localize an entire program, so more universal solution is to set appropriate project configuration in properties window. To bring up this window, select project file and then press <i>F4<\/i> button.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/PropertiesWindow.png\" rel=\"attachment wp-att-307\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/PropertiesWindow.png\" alt=\"PropertiesWindow\" width=\"350\" class=\"aligncenter size-full wp-image-307\" \/><\/a><br \/>\nFrom now on, Resharper shows warnings indicating that our hard-coded strings might be moved to resource file. Pressing <i>ALT+ENTER<\/i> on these strings will bring up the context menu action, where new option &#8211; <i>&#8220;Move to resource&#8221;<\/i> is available.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/MoveToResourceContextAction.png\" rel=\"attachment wp-att-304\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/MoveToResourceContextAction.png\" alt=\"MoveToResourceContextAction\" width=\"450\" class=\"aligncenter size-full wp-image-304\" \/><\/a><br \/>\nChoosing this option will bring up the <i>&#8220;Move to Resource<\/i>&#8221; window. However if we do not have any resource files in our project, we will get this message.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/NoResourcesFound.png\" rel=\"attachment wp-att-305\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/NoResourcesFound.png\" alt=\"NoResourcesFound\" width=\"450\" class=\"aligncenter size-full wp-image-305\" \/><\/a><br \/>\nIn order to create these files, right click on project and choose <i>Add->New Item<\/i>. Now, select <i>Resource.resx<\/i> file and name it for example <i>LocalizableStrings.resx<\/i>.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/AddingsResource.png\" rel=\"attachment wp-att-297\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/AddingsResource.png\" alt=\"AddingsResource\" width=\"600\" class=\"aligncenter size-full wp-image-297\" \/><\/a><br \/>\nIn this resource file we will store values for our <i>&#8220;default language&#8221;<\/i>. Supporting more languages require us to create additional LocalizableString files with appropriate <i>LETF<\/i> tags suffixes.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/Allfiles.png\" rel=\"attachment wp-att-299\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/Allfiles.png\" alt=\"Allfiles\" width=\"350\" class=\"aligncenter size-full wp-image-299\" \/><\/a><br \/>\nNow, we are able to move our hard-coded string to resource files.<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/MoveToResource.png\" rel=\"attachment wp-att-303\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/MoveToResource.png\" alt=\"MoveToResource\" width=\"450\"  class=\"aligncenter size-full wp-image-303\" \/><\/a><br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/aftermove.png\" rel=\"attachment wp-att-298\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/aftermove.png\" alt=\"aftermove\" width=\"450\" class=\"aligncenter size-full wp-image-298\" \/><\/a><br \/>\nBy default Resharper adds hard-coded strings to default resource file, so we have to specify values for localizable string for other languages. In order to do that, first navigate to resource entry in <i>LocalizableStrings.resx<\/i> file by holding <i>CTRL<\/i> and clicking property <i>&#8220;Program_Main_This_is_localizable_string&#8221;<\/i><br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/GoToProperty.png\" rel=\"attachment wp-att-301\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/GoToProperty.png\" alt=\"GoToProperty\" width=\"450\" class=\"aligncenter size-full wp-image-301\" \/><\/a><br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/overriden.png\" rel=\"attachment wp-att-306\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/overriden.png\" alt=\"overriden\" width=\"450\" class=\"aligncenter size-full wp-image-306\" \/><\/a><br \/>\nand then press <i>ALT+ENTER<\/i> and choose <i>&#8220;Override &#8216;PropertyName\u2026'&#8221;<\/i>. This operation brings up <i>&#8220;Edit Resource&#8221;<\/i> window where You can easily navigate between resource files and update given resource property<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/EditResourceDialog.png\" rel=\"attachment wp-att-300\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/EditResourceDialog.png\" alt=\"EditResourceDialog\" width=\"450\" class=\"aligncenter size-full wp-image-300\" \/><\/a><br \/>\nResharper not only is able to move strings to resource files but also can use existing ones. This basically means that if we use hard-coded string which already has been added to resource file, Resharper will suggest to use predefined resource<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/useproperty.png\" rel=\"attachment wp-att-309\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2014\/08\/resharper-localizable-string-literals\/useproperty.png\" alt=\"localizable string\" width=\"450\" class=\"aligncenter size-full wp-image-309\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone who has ever tried to create multilingual application knows, that this is very tedious task. The most repetitive work is usually moving hard-coded strings to resource files. Fortunately with Resharper this is definitelly less painfull than usuall. In order to point out localizable parts of application , it is necessary to decorate classes with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52,51,53,50],"tags":[196,197,198,199],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-globalization","category-localization","category-r","category-resharper","tag-globalization","tag-localization","tag-r","tag-resharper"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":7,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/534"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}