Last post Jan 16, 2008 10:32 AM by davidhov
Jan 11, 2008 01:33 PM|davidhov|LINK
I just tried the "Generate Local Resource" tool is VS 2005 for my ASP.NET 2.0 site. I was startled when it only generated one string resource-- for the title! I was (naively) expecting that it would segregate all static text into "ASP:Localize" controls
and bingo, I would have a set of strings stored into a resource file that I could clone and translate as needed.
Is there a tool on the market that does this? Why didn't VS 2005 do it? The "Generate Local Resource" feature hardly seems worth the effort, given that it ignores the bulk of the text on a page. (My current web site is primarily documentary and has lots
Thanks in advance.
Jan 16, 2008 03:08 AM|rstrahl|LINK
Generate Local Resources will spit out resources for all control properties that are marked as [Localizable] - nothing more, nothing less. There's no way for VS to otherwise know what's localizable and what's not, so that's a realistic choice.
If you want to localize a page completely you can't have static text in the page. You need to use Localize/Labels/Literal to make sure that you can translate the text. I can't imagine what a mess would be generated if all static HTML text was automatically
converted for you... Again, there's no frame of reference on what's to be localized and what's just page markup related.
+++ Rick ---
Jan 16, 2008 10:32 AM|davidhov|LINK
Actually, I've written my Localization utility and it seems to work fairly well. I'm assuming XHTML and I parse the entire document into a DOM-like tree. Then I search for free text that's not whitespace-like and is not a comment. If an "active" text string
is not already bounded by "asp:Localize" tags, I create one and set its Text attibute to the text I've carved out and migrate (add) the string to the already-created RESX file for the XHTML fragment (ASCX, ASPX, etc.). When complete, I rewrite the XHTML document
Note that I'm assuming the user has already run "Generate Local Resource" on the pertinent ASPX, MASTER, and ASCX file; I don't attempt to generate the original .RESX.
My program's outer shell is a translation helper. After converting a project to be translatable by segregating its text, it will, on request, create an ensemble of culture-specific RESX files (like "mypage.aspx.it-IT.resx" for Italian), into which the text
strings are copied but marked as "not yet translated". The main (.Net Windows Forms) application is an editor which loads all the RESX files for a culture and lets the user click on strings. The English (or native) string is loaded into one RichTextBox and
the new culture's current translation into another. The status of the translation is indicated by color changes in the tree of RESX files.
In addition, my tool will "undo" its "asp:Literal" conversions and revert the XHTML document back to its original in-place static text.
I'm sort of wondering if anyone would be interested in this set of tools. The only drawback is that the first step, creating local resources, requires manual fiddling in VS.
BTW, I chose to be XTHML-specific to avoid having to be "quirky" in my parsing. My parser does allow certain tags to be "self-closing", but so far I'm able to parse any valid XHTML documents used by ASP.NET. I'm sure my parser isn't perfect, but it's getting
close enough for real work.
Localization automatic asp:Localize RESX resource