Convert a number to a verbal representation

  • Thread starter Thread starter Picho
  • Start date Start date
P

Picho

Hi group.

This must have come up a few times before but I found no specific resources
regarding this.

the problem is simple: convert the number 55 to the string "Fifty five"
(obviously with any given number...)

The algorithm is quite simple and I would not have bothered you with such a
simple problem.

alas...

must be with Globalization in mind. specificly, the first problem I have is
converting numbers to hebrew strings and as you know, hebrew is not so
simple since there are differences with male/female etc.

my question is simple: What are the guidlines I should follow for this
component to be scaleable, globalized and well designed?
What kind of data source should I use for this component that will be easly
changed (add cultures translation and grammer rules)? where should I keep
this data source (embedded resource?), How shall I design this so that users
(administrators?) could modify/add/remove culture variations?

any specific thoughts about the design and signatures for the convertion
method will be deeply appriciated (should I use CultureInfo with a specific
culture as a parameter etc)

thanx,

Picho

P.S - maybe this can be done by the framework itself and I missed something?
 
Picho,

In my opinion, forget to do it with globalization.

I know that it has in 2 languages this exceptions for let say 98 in words
(in English Words)
What is in a lot of languages like English: Ninty eight
In German/Dutch: Eight and ninty
In French/French: Four times twenty and ten eight
Belgian/French like the English

I once saw a link given by Peter Huang about VB6, it is so simple that it
should be made in C# just changing a little bit in my opinion to use the
words.

http://www.vbexplorer.com/VBExplorer/tips/src36.asp

I hope this helps?

Cor
 
I dont believe there is much to help you, this is cutom work.....not
especially difficult though.

Given the numbers are the same regardless your problem lies in representing
the wording (cant help with the hebrew I'm afraid) in each language and you
could simply use a series of xml files, or nodes in one file, to hold your
lookup tables extracting the relevent values for the methods replacement (ie
4 to four) from a language specific file. The methods and calculations to
replace the numerics therefore would remain the same only the replacement of
the value needs to change.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
Thank you Cor and John,

I had no intention to do ALL languages....

I was simply asking about design guidlines that will make it easier on
consumers to add their own language (culture) grammer rules.

thanx again,

Picho
 
Create a class that will do the conversion, with methods that accept
CultureInfo objects. Then, all someone has to do to add additional language
support is subclass your class. Your stock implementation will support the
cultures you want, and exception out for others.
 
Thanx Sean,

I was thinking more how a non-programmer would be able to extend the culture
definitions. that is an external method other than subclassing.

Picho
 
Ouch! That'd be seriously tricky. Given the vast amounts of combinations
available, you'd have to write a fairly complex set of classes and UI's
around this.
 
Back
Top