Nevermind. Looking closer at your post I see you were doing something different.
I had a different approach, using this collection of handers. (This is very basic AppleScript and has been in use for like 20 years.
Basically, I have a database that includes movie and TV titles and other information (description, rating, cast, etc.). The script adds a new field (titleSort) to each record, and uses that for sorting.
Converting numbers to words in titles is indeed complicated.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set listOfTitles to {"2001: A Space Odessy", "1900", "The Magnificent 7"}
set fixedTitles to {}
repeat with aTitle in listOfTitles
set titleSort to FixTitleForSorting(aTitle as text)
set the end of fixedTitles to titleSort & tab & "|" & tab & aTitle as text
end repeat
set AppleScript's text item delimiters to {return}
return fixedTitles as text
on FixTitleForSorting(titleToFix)
set titleToFix to titleToFix as text
set titleToFix to PrepTitleForSort(titleToFix)
set titleToFix to findAndFixNumbers(titleToFix)
set titleToFix to FixLeadingNonAlphas(titleToFix)
return titleToFix
end FixTitleForSorting
on PrepTitleForSort(titleText)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
set prefixList to {"A", "An", "The", "El", "La", "Los"}
if word 1 of titleText is in prefixList then
set titleWords to every word of titleText
set the last item of titleWords to the last item of titleWords & ","
set the end of titleWords to item 1 of titleWords
set titleWords to the rest of titleWords
set AppleScript's text item delimiters to " "
set titleText to titleWords as text
end if
set AppleScript's text item delimiters to saveTID
return titleText
end PrepTitleForSort
on NumberToWords(aNum)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
set onesList to {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}
set tensList to {"ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}
set AppleScript's text item delimiters to ""
set aNumList to every text item of (aNum as text)
set aNum to aNum as integer
if aNum = 0 then
set numWord to "zero"
if the (count of aNumList) > 1 then
set aNumList to the rest of aNumList
set numWord to {numWord}
set the end of numWord to NumberToWords(aNumList as text)
end if
else if aNum < 20 then
set numWord to (item aNum of onesList) as text
else if aNum < 100 then
set tenNum to (item 1 of aNumList) as integer
set oneNum to (item 2 of aNumList) as integer
set numWord to {item tenNum of tensList}
if oneNum ≠ 0 then set the end of numWord to item oneNum of onesList
else if aNum < 1000 then
set hundNum to (item 1 of aNumList) as integer
set aNumList to the rest of aNumList
set hundRem to (aNumList as text) as integer
set numWord to {item hundNum of onesList, "hundred"}
if hundRem ≠ 0 then set the end of numWord to NumberToWords(hundRem)
else if aNum < 1100 then
set numWord to {"one-thousand"}
set aNumList to the rest of aNumList
set thouRem to (aNumList as text) as integer
if thouRem ≠ 0 then set the end of numWord to NumberToWords(thouRem)
else if aNum < 2000 then
set thouNum to items 1 thru 2 of aNumList
set thouNum to (thouNum as text) as integer
set numWord to {NumberToWords(thouNum)}
set aNumList to items 3 thru -1 of aNumList
set the end of numWord to "hundred"
set AppleScript's text item delimiters to ""
set thouRem to (aNumList as text) as integer
if thouRem ≠ 0 then set the end of numWord to NumberToWords(thouRem)
else if aNum < 10000 then
set thouNum to item 1 of aNumList
set aNumList to the rest of aNumList
set thouNum to (thouNum as text) as integer
set numWord to {NumberToWords(thouNum)}
set the end of numWord to "thousand"
set AppleScript's text item delimiters to ""
set thouRem to (aNumList as text) as integer
if thouRem ≠ 0 then set the end of numWord to NumberToWords(thouRem)
else if aNum < 100000 then
set thouNum to items 1 thru 2 of aNumList
set aNumList to items 3 thru -1 of aNumList
set thouNum to (thouNum as text) as integer
set numWord to {NumberToWords(thouNum)}
set the end of numWord to "thousand"
set AppleScript's text item delimiters to ""
set thouRem to (aNumList as text) as integer
if thouRem ≠ 0 then set the end of numWord to NumberToWords(thouRem)
else if aNum < 1000000 then
set thouNum to items 1 thru 3 of aNumList
set aNumList to items 4 thru -1 of aNumList
set thouNum to (thouNum as text) as integer
set numWord to {NumberToWords(thouNum)}
set the end of numWord to "thousand"
set AppleScript's text item delimiters to ""
set thouRem to (aNumList as text) as integer
if thouRem ≠ 0 then set the end of numWord to NumberToWords(thouRem)
else if aNum < 10000000 then
set milNum to item 1 of aNumList
set aNumList to the rest of aNumList
set milNum to (milNum as text) as integer
set numWord to {NumberToWords(milNum)}
set the end of numWord to "million"
set AppleScript's text item delimiters to ""
set milRem to (aNumList as text) as integer
if milRem ≠ 0 then set the end of numWord to NumberToWords(milRem)
else if aNum < 100000000 then
set milNum to items 1 thru 2 of aNumList
set aNumList to items 3 thru -1 of aNumList
set milNum to (milNum as text) as integer
set numWord to {NumberToWords(milNum)}
set the end of numWord to "million"
set AppleScript's text item delimiters to ""
set milRem to (aNumList as text) as integer
if milRem ≠ 0 then set the end of numWord to NumberToWords(milRem)
else if aNum ≤ 536870911 then
--this is the largest integer that does not get displayed as an exponent
set milNum to items 1 thru 3 of aNumList
set aNumList to items 4 thru -1 of aNumList
set AppleScript's text item delimiters to ""
set milNum to (milNum as text) as integer
set numWord to {NumberToWords(milNum)}
set the end of numWord to "million"
set AppleScript's text item delimiters to ""
set milRem to (aNumList as text) as integer
if milRem ≠ 0 then set the end of numWord to NumberToWords(milRem)
else
set numWord to aNum as text
end if
set AppleScript's text item delimiters to "-"
set numWord to numWord as text
set AppleScript's text item delimiters to saveTID
return numWord
end NumberToWords
on FixLeadingNonAlphas(titleText)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
set titleList to characters of titleText
repeat
if item 1 of titleList is not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then
set titleList to the rest of titleList
else
exit repeat
end if
end repeat
if titleList is {} then set titleList to "A"
set titleText to titleList as text
set AppleScript's text item delimiters to saveTID
return titleText
end FixLeadingNonAlphas
on findAndFixNumbers(titleToFix)
set newTitle to {}
set x to 0
set titleSize to the count of characters in titleToFix
repeat
set x to x + 1
if x > the (titleSize) then exit repeat
set thisChar to character x of titleToFix
if thisChar is in "1234567890" then
set thisNum to {thisChar}
set lastChar to ""
repeat
set x to x + 1
if x > the (titleSize) then exit repeat
set thisChar to character x of titleToFix
if thisChar is in "1234567890" then
set the end of thisNum to thisChar
else
set lastChar to thisChar
exit repeat
end if
end repeat
set AppleScript's text item delimiters to ""
NumberToWords(thisNum as text)
set wordNum to the result
set the end of newTitle to wordNum
set the end of newTitle to lastChar
else
set the end of newTitle to thisChar
end if
end repeat
set AppleScript's text item delimiters to ""
return newTitle as text
end findAndFixNumbers