Scott Hanselman

Psuedo Internationalization and your ASP.NET Application

April 9, '05 Comments [1] Posted in ASP.NET | Internationalization | Nant | ViewState | Bugs
Sponsored By

John Robbins has a great MSDN BugSlayer Article from April of 2004 on Psuedo Internationalization. When you're creating localization-ready applications, but you don't want to go to all the hassle of localizing your ever-changing resources to a specific language, you can create psuedo-internaFile Attachment: Psuedoizer.zip (11 KB)tionalized resources.

These are resources using not only funky characters (to cover more of the character spectrum), but they may be longer (simulating more 'verbose' languages like German).

For example, here's an English language snippet from one of our resource files:

<data name="Accounts.Download.Title">
  <value>Transaction Download</value>
</data>
<data name="Accounts.Statements.Action.ViewStatement">
  <value>View Statement</value>
</data>
<data name="Accounts.Statements.Instructions">
  <value>Select an account below to view or download your available online statements.</value>
</data>

Here's the same snippet Psuedo-internationalized:

  <data name="Accounts.Download.Title">
    <value>[Ŧřäʼnşäčŧįőʼn Đőŵʼnľőäđ !!! !!!]</value>
  </data>
  <data name="Accounts.Statements.Action.ViewStatement">
    <value>[Vįęŵ Ŝŧäŧęmęʼnŧ !!! !!!]</value>
  </data>
  <data name="Accounts.Statements.Instructions">
    <value>[Ŝęľęčŧ äʼn äččőūʼnŧ þęľőŵ ŧő vįęŵ őř đőŵʼnľőäđ yőūř äväįľäþľę őʼnľįʼnę şŧäŧęmęʼnŧş. !!! !!! !!! !!! !!!]</value>
  </data> 

It can still be read as near-English, which means you can localize your ASP.NET application to this funky almost-language and see:

  • Which strings in your application you missed pulling into resources
  • What you application looks like with longer strings
  • If you correctly handle the higher-order character sets

John's article includes a nice WinForms application to "psuedoize" resources. However his code doesn't take into consideration:

  • Resources that include markup like <a href={0}>. It will actually psuedoize the "a href" which will actually break your application. I've changed it to watch for the entering and exiting of < >'s and { }'s.
  • There's no command-line version.

I wanted a version to solve both these problems because I want to automatically psuedoize our applications during the Continuous Integration NAnt build. That means, Joe Developer adds a string, and the build will automatically generate psuedo-resources that include them all.

Here's my enhanced I18n Psuedoizer with much respect to John Robbin's original. Psuedoizer.zip (11.03 KB)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Alphabetizing your .NET Resource (RESX) files

April 9, '05 Comments [1] Posted in ASP.NET | Corillian | PDC | XML | Tools
Sponsored By

We internationalize all our ASP.NET Web Applications, and usually end up with hundreds, if not thousands of strings in our RESX files. The names are all very hierarchical, like "AccountSummary.DataGrid.Columns.AvailableBalance" so you can see why it's important to keep them alphabetized. Additionally, there are usually a dozen or more of these RESX files in multiple levels of directories.

So, a little snazzy batch file action:

for /f "Tokens=*" %%i in ('dir /b /s *.resx') do nxslt "%%i"  alpharesx.xslt -o temp.xml & copy temp.xml "%%i" /y

The "dir /b /s" is "Directory BARE FORMAT FULL PATH all SUBDIRECTORIES" which provides the iterator for the FOR DO batch file loop. I had to use a temp.xml file because the nxslt tool didn't allow me to use the same filename for the input and output.

"nxslt" is a fantastic command-line .NET XSLT front end by Oleg Tkachenko. There are many command-line XSLT tools out there, but Oleg's is by far the most powerful and flexible.

The alpharesx.xslt is this XSLT stylesheet. It copies (xsl:copy-of) the RESX header stuff, then sorts the data nodes by name. There's no doubt even 'terser' XSLT-y ways to do this, but this is a start. Thanks to Travis Illig for the idea and starting chunk of XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="/" xml:space="preserve">
        <root>
            <xsl:copy-of select="root/xsd:schema"/>
            <xsl:copy-of select="root/resheader"/>
            <xsl:apply-templates select="root/data">
                <xsl:sort select="@name" />
            </xsl:apply-templates>
        </root>
    </xsl:template>
   
    <xsl:template match="data" xml:space="preserve">
        <data><xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
            <value><xsl:value-of select="value" /></value>
        </data>
    </xsl:template>
</xsl:stylesheet>

I'm also sure there's all sorts of SED-style ways to accomplish this, but this solution seem to be the simplest solution for this, short of writing a little custom C# program. It also was a faster-to-write solution than a new program.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Overheard - Friday, April 8, 2005

April 8, '05 Comments [3] Posted in Javascript | Bugs
Sponsored By

Overheard while debugging some client-side JavaScript today at work...

"How come your body is bigger than your documentElement?"

"That's what she said!"

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

CVS and Subversion vs. VSS/SourceSafe

April 8, '05 Comments [14] Posted in DasBlog | Tools
Sponsored By

Here's a response I gave to a fellow on an email list I'm on yesterday. He was having trouble understanding that CVS (and other source control systems) didn't "lock" files (checkout with reservation) as he has been a VSS person for his whole career. This is what I said (a bit is oversimplified, but the essense is there):

With VSS you:

Checkout with reservations – meaning that developer has an exclusive lock on that file.

With CVS you:

Edit and Merge optimistically – developers can make a change to any file any time. However, CVS is the authoritative source and they must Update and Commit their changes to the repository.

It sounds scary, but it’s HIGHLY productive and very powerful. It works more often than not, as most devs don’t work on the exact same function. It is largely this concept that makes Continuous Integration work.

It’s a FANTASTICALLY powerful way to manage source. No need to wait for that “locked” file. Source files can be edited at any time. For example, if there is a file with two functions:
 
Line1: Public void a()
Line2: {}
Line3:
Line4: Public void b()
Line5: {}

Two developers can edit the same file, different functions: 

Line1: Public void aChanged() <- DEV1
Line2: {}
Line3:
Line4: Public void bDifferent() <- DEV2
Line5: {}

These changes are called “non-conflicting.” CVS will automatically merge them. Now, we don’t know if they files will still compile (that’s the job of the developer and the build system) but since different lines of text are changed, they don’t conflict.

If two devs change the SAME LINE, then CVS holds both changes with “Conflict Markers” and demands that the developer RECONCILE the changes before committing. I manage all the dasBlog development worldwide using CVS. How could I do that if I allowed you in India to LOCK a file for days at a time? For example, when you are done working in your sandbox, it’s your responsibility to merge your changes in with the mainline.

From http://www.atpm.com/7.03/voodoo-personal.shtml

"CVS (Concurrent Versions System) is an open-source version control tool that’s extremely popular in the Unix/Linux world. CVS is a client-server system, which makes it easy for multiple users, possbly scattered across the Internet, to collaborate.. In fact, Apple uses it internally to manage the development of Mac OS X, and to make their sources for the Darwin kernel available to the world. CVS’s signature feature is its use of “optimistic” locking to let multiple people work on the same file at the same time. It then automatically merges their changes and signals whether it thinks human intervention will be required to complete the merge. (It seems like it would take magic for CVS to do this reliably, but in practice it has worked very well for me.) CVS (Concurrent Versions System) is an open-source version control tool that’s extremely popular in the Unix/Linux world. Unlike Projector and VOODOO Personal, CVS is a client-server system, which makes it easy for multiple users, possibly scattered across the Internet, to collaborate. Although only the client runs on Classic Mac OS and Windows, the server runs on Mac OS X. In fact, Apple uses it internally to manage the development of Mac OS X, and to make their sources for the Darwin kernel available to the world. CVS’s signature feature is its use of "optimistic" locking to let multiple people work on the same file at the same time. It then automatically merges their changes and signals whether it thinks human intervention will be required to complete the merge. (It seems like it would take magic for CVS to do this reliably, but in practice it has worked very well for me.)"

From http://www.xpro.com.au/Presentations/UsingCVS/Document%20Version%20Control%20with%20CVS.htm

"By default, CVS uses an optimistic multiple writers approach. Everybody has write permission on a file, and changes are merged as the editors commit their changes to the repository. Changes won’t commit without merging. At first, this protocol appears problematic to most people who haven’t used it. In practice, manual intervention is only required for lines which have been modified by both editors involved in the merge. As with file-locking, this protocol is not without risk. It is possible to introduce logical errors to a file which has merged without incident, as added or deleted lines can change the semantics of the prior version. This technique is most effective when changes are committed frequently and the number of simultaneous writers is minimised."

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Updating an old iMac's Firmware while running OSX

April 5, '05 Comments [16] Posted in Musings
Sponsored By

Here's some randomness. I had to do some testing with Safari 1.2, which is apparently only available on Mac OS X 10.3. Version 10.2 has Safari 1.0. Why I need to upgrade the OS to get a new browser, I don't know.

So, here's what went down.

  • Boot up iMac that has OS X 10.2
  • Put in OS X 10.3 disk
  • I'm informed that I need to "update my firmware" and I should visit http://www.apple.com/support/downloads. I'm unable to continue and install OS X 10.3
  • I go to the Apple site and search for "imac firmware"
  • I'm greeted with KB articles from 1999. Apparently "relevance" is low on the priority list there.
  • I finally find some firmware from 2001 and download it.
  • When I run the firmware updater, I'm told it will only run on OS 9. Lovely.
  • I find a copy of OS 9 and install it side-by-side. (What if I DIDN'T have it around?)
  • I go to System Preferences|Startup Disk and tell it to dual boot into OS 9.
  • I boot up, download the firmware again.
  • I run it, and I'm told that I have to reboot AND I have to find a secret recessed button on the iMacs ass and push it in with a pen. Stunning.
  • I reboot, push the funny button. The iMac screams in pain. It then sits for a minute doing nothing.
  • It restarts, again into OS 9 and tells me that it's flashed the firmware successfully.
  • Now, I'm just tired. I can't figure out how to get back into OS X 10.2...
  • I boot off the OS X 10.3 disk and just format the hard drive completely with the new OS X 10.3.

All this to update Safari on a 2-year-old iMac.

Anyone who says it's all peaches and cream in the Mac world is nuts.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.