itechnology / T4ResX

Transform ResX files into strongly typed classes via T4
11 stars 4 forks source link

Question on Need #1

Closed toddca closed 11 years ago

toddca commented 11 years ago

Don't you already get strongly typed access to Resx with the designer VS wraps around the Resx? I access my string resources identical to the way you are suggesting this tool allows but without this tool, trying to understand the difference here...?

itechnology commented 11 years ago

Yes and no.. :)

If you use APP_LocalResources, you get access to those resources but only underneath that folder, not in your dll's, and not in other folders.

If you use APP_GlobalResources, you get access to that in your website, but only get a flat namespace and not access in other projects.

If you create a specific dll for localization, you do get universal access, but have to remember each time to set the provider to public.

T4Resx merges all the above and adds access to localized javascript, and dynamic replacement variables by generating some helper methods in the resulting code.

Have a look a this article: http://www.codeproject.com/Articles/506388/Localizing-WebSites-JavaScript-and-Assemblies-with

Hope this answers your questions

Some info on how i'm using it:

Often we need to export all our translations to excel files which we then give to translators and then reintegrate them by re-regenerating .resx files, and then executing T4ResX on top of that for generating final .cs code. It also prevents us from having to manually each time set the rexprovider to public, since we don't need one anymore.

This is then used for localizing the entire website (controllers & pages), generating error messages or data annotations in annex dll's, and injecting localized javascript into the main website.

Our websites are also usually white label, so depending on which skin we are using we replace variables like {DOMAIN} etc on the fly and don't have to hardcode certain things inside our resx files (brand names, urls, and the like).

toddca commented 11 years ago

We have one localization DLL which contains about 100+ resx files. We don't really use App_* resources and we use a template resx in our DLL which we just copy which has the access set to 'public'.

We have several needs which it appears you may have a solution.

  1. we need a way to export the strings from all resx files into a single file (XLSX is best) so we can send to our localization folks. (sounds like you have a solution here).
  2. We need a way to take the XLSX (or whatever format we export to) and import that back into the various resx files.
  3. We need a way to determine what resx string resources are not being used so they can be removed. Since it costs a bit of money to have strings localized we want to ensure we are paying to localize a string that is actually being used.

I don't see that we have a solution for #2.

As for #3 I suspect ReSharper might be a good solution as it has a Show Usages, option but we would have to figure out some way to extend that.

itechnology commented 11 years ago

I'd love a solution for number 3 too :)

For 2) give me an email and i'll send you the project if you like ..it's a half-assed rewrite of http://resx2xls.codeplex.com but it works :)

Problem with the template resx is that PublicResXProvider is actually set inside your .csproj, when you copy paste, visual studio actually takes care of duplicating the public property, once you automate this you are going manual. Thus the reason i use the .tt do do it for me. Not to mention we are currently at 450 resx files in our assembly and counting ! :(

toddca commented 11 years ago

Thanks, chunkbuffer(at)gmail.com

itechnology commented 11 years ago

Geesh i use dropbox everyday and always forget i can share via that ..here's the link to the project. bin/release has a working version

https://www.dropbox.com/sh/m4sammonw5cq7y6/nQ0Bsc299b/SharedCode

Just browse to a project containing .resx files, click next next, and then choose a save path for the xls

You will probably need office on the pc doing the generating code (interop stuff), and there is a possibility that it will generate a xlsx with a xsl extension ..ignore open anyway.

Reverse process is just browsing to the resx file and choosing a output folder, the XLS file has to be in the same format as the one generated, and you will not get any .cs code behind stuff, just pure resx ..thus the .tt to either generate the .cs stubs of toggle the file to public provider.

Like i said, this is used internally and not ready for the public, even if it's based on Resx2Xls i mentioned above which dates back to 2007. I have a full rewrite of this planned and it will be released on github when i get it finished.

toddca commented 11 years ago

Thanks! I exported my resx from my DLL and it worked great. The UI is not that swank but as you said its free and a work in progress. I have not done an import just yet and I am concerned it will trash my project, just worried about how much testing has been done. I will take a backup and restore my project to a new location and test.

Thanks again for sharing. If I run across a solution for #3 I will let you know. I have opened a feature request with ReSharper for import/export (like this tool) and for #3 and they have it on their TODO list - hopefully we will see some movement on this.

itechnology commented 11 years ago

Yes, clone your project and import it there, like this you can play with it until you feel comfortable with it.

Would be nice if resharper could look for unused Resources, i know that i am starting to have quite a bit building up in my resx files ..and that's money thrown away if you ask translators to translate stuff you don't even use anymore :)

Glad to help, have fun with the code :)