Search code examples
phpsingularplural

function switching between singular and plural?


I'm looking for a function that given a string it switches the string to singular/plural. I need it to work for european languages other than English.

Are there any functions that can do the trick? (Given a string to convert and the language?)

Thanks


Solution

  • There is no function built into PHP for this type of operation. There are, however, some tools that you may be able to use to help accomplish your goal.

    There is an unofficial Google Dictionary API which contains information on plurals. You can read more about that method here. You'll need to parse a JSON object to find the appropriate items and this method tends to be a little bit slow.

    The other method that comes to mind is to use aspell, or one of its relatives. I'm not sure how accurate the dictionaries are for languages other than English but I've used aspell to expand words into their various forms.

    I know this is not the most helpful answer, but hopefully it gives you a general direction to search in.