Localization in our .NET 4.0 C# project is basically the following:
MyCompany.Resources.dll
contains two RESX files:A.resx
andB.resx
with their localized counterparts (A_de.resx
,B_hu.resx
, etc.). These files consist of the usual RESX xml elemens, like<data name="key" xml:space="preserve"><value>value</value></data>
MyCompany.Common.dll
contains a public (singleton) classMyCompanyResourceManager
with two methods for accessing the localized values inA.resx
andB.resx
by key, likeGetA(string key)
andGetB(string key)
.Wherever there is a string in the C# code that needs to be localized, we manually open either
A.resx
orB.resx
with XML editor (the Visual Studio resource editor screws up something in the xml), add a new<data>
tag to the XML document with a new key, and in the C# code we manually replace the string with a call toMyCompanyResourceManager.Instance.GetA(...)
(orGetB(...)
).
This work can be speeded up with code snippets and live templates in ReSharper, but I feel a need for a better solution for this "workflow" (and not for the localization mechanism, that cannot be changed :) ). That's why a want to write a ReSharper plugin that does the repetitive parts. What I would like to achieve:
- When the caret is on a string literal in the C# code, offer context actions
Localize in A
andLocalize in B
- When I choose either of them, popup a dialog to prompt the key to be used in the RESX from the user
- Place the new
<data>
tag in the corresponding RESX file and replace the string literal with the call the appropriate method. Import the namespace of theMyCompanyResourceManager
class if needed, and reference its assembly, if needed. (Referencing the assembly is not a must, because it can be assumed thatMyCompany.Common
is referenced everywhere) - open the chosen RESX file to see the changes
Optional features (to make plugin more widely usable):
- settings page to specify the RESX files (even more than two), the corresponding method calls, and the class that contains these methods
- before prompting the key, search in the chosen RESX file for the string literal, just in case it is already localized
My problems / questions:
- I'm kind of lost in the ReSharper SDK reference and in its incomplete documentation, so a comprehensive material / tutorial on the available classes / interfaces would be great (if there is any)
- How to open a project / solution file in Visual Studio with the ReSharper API?
- How to manipulate XML files with the ReSharper API? The sample context action is a reverse string thing, so accessing the literal under the caret is OK.
- Should I use a context action or a refactoring for this scenario?
- How to start a refactoring from a context action?
- Where to start, what should be well understood of the API for this task?
Thanks in advance!