Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriate article (a/an) in String.Format

I'm looking for a culturally-sensitive way to properly insert a noun into a sentence while using the appropriate article (a/an). It could use String.Format, or possibly something else if the appropriate way to do this exists elsewhere.

For example:

Base Sentence: "You are looking at a/an {0}"

This should format to: "You are looking at a carrot" or "You are looking at an egg."

I'm currently doing this by manually checking the first character of the word to be inserted and then manually inserting "a" or "an." But I'm concerned that this might limit me when the application is localized to other languages.

Is there a best practice for approaching this problem?

RESOLUTION: It appears that the problem is complicated to the point that there does not exist a utility or framework to solve this problem in the way I originally phrased. It appears that the best solution (in my situation) is to store the article in the database along with the noun so that the translators can have the level of control they need. Thanks for all of the suggestions!

like image 724
DivisionByZorro Avatar asked May 05 '09 16:05

DivisionByZorro


1 Answers

The problem is even in English, a-vs-an is not determined by the starting letter, but the starting sound. You can make a pretty good assumption in English based on the starting letter, but there are some exceptions (e.g. "hour", "user").

The best thing to do is have access to a word's pronunciation to be able to choose.

Barring that, the next best thing to do is have a list of common exceptions, then guess the rest.


From Wikipedia:

The choice of "a" or "an" is determined by phonetic rules rather than by spelling convention. "An" is employed in speech to remove the awkward glottal stop (momentary silent pause) that is otherwise required between "a" and a following word e.g. "an X-ray" ... The following paragraphs are spelling rules for "an" which can be used if the phonetic rule is not understood.

like image 162
lc. Avatar answered Nov 11 '22 22:11

lc.