The Joel on Software Discussion Group (CLOSED)A place to discuss Joel on Software. Now closed. |
||
|
This community works best when people use their real names. Please
register for a free account.
Other Groups: Joel on Software Business of Software Design of Software (CLOSED) .NET Questions (CLOSED) TechInterview.org CityDesk FogBugz Fog Creek Copilot The Old Forum Your hosts: Albert D. Kallal Li-Fan Chen Stephen Jones |
To cut a very long story short, I've got an automated build process for some application that writes out a set of string resources as a text files. This text file then gets whizzed over to somebody else to review all the text, mainly to make sure our software never ends up on TheDailyWTF's "Error'd" section ;-)
To streamline things a bit, I'd like to run an automatic spell check on this file as part of our build, so if somebody writes a string resource with a spelling mistake, it gets caught and thrown back immediately at build time, rather than waiting for a human to check it. A couple of options that spring to mind: * Download the source to aspell and port it to Windows via cygwin. * Use Windows Powershell to launch Word in the background and spell check the file. Do any of you lot have any better ideas? Somebody else somewhere must have done something similar.... PS: Yes, I make spelling mistakes too.
There is already a compiled windows port on the aspell website, I use it to spell check my latex sources. It works fine.
Karl Wednesday, January 28, 2009
This script will use Word in the background and spell checks the clipboard. You can modify the msgbox part to handle errors the way you want plus look elsewhere other than the clipboard for the text. Its mainly an idea on how to use the Word object that you can learn from and modify.
Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status Set oWD = WScript.CreateObject("Word.Application") oWD.Visible =false oWD.Documents.Add On Error Resume Next oWD.Selection.Paste If err.number<>0 then MsgBox "Clipboard was Empty" oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing Set oWD=Nothing WScript.Quit End If ' Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End) If oWD.CheckSpelling(RangeOriginal)=False Then oWD.ActiveDocument.CheckSpelling Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End) RangeCorrected.copy ' If RangeCorrected.Words.Count>7 Then Cnt=RangeCorrected.Words.Count Status= "The text beginning with: "&_ RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_ RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_ RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1)&_ " "&RangeCorrected.Words.Item(Cnt)&vbCRLF&"has been checked "&_ "and corrected version copied to the clipboard" Else Status= "<< "&RangeCorrected&" >>"&vbCRLF&"has been checked and the"&_ " corrected version was copied to the clipboard" End If ' Else Status= "All words in the clipboard were spelled correctly" End If ' oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing MsgBox Status
That looks terrifying! I solved my problem in the end with a one line bash script calling out to aspell, awk and uniq (but not necessarily in that order).
|
|
Powered by FogBugz


