I often see FileMaker developers mishandle pluralisation of words in dialog boxes or error messages. Well the problem isn’t limited to just FileMaker developers of course, and you no doubt have come across error messages such as:

"You cannot update 1 items."

This is lazy programming as it does not handle pluralisation at all. It does not look professional to your users. Please don’t be lazy.

At the very least, you can pluralise the key word using brackets like this:

"You cannot update 1 item(s)."

But personally, I don’t like doing this as this too, in my opinion is lazy.

As you no doubt already know, if you want to address pluralisation in messages, then you’ll need to resort to some code.

I have seen developers take various approaches over the years, and although some of the approaches may work, they aren’t necessarily the best way to handle pluralisation.

Using scripts

I’ve seen FileMaker developers handle pluralisation using several script steps as follows:

IF [$number = 1]
Show Custom Dialog  [ "You cannot update 1 item." ]
ELSE
Show Custom Dialog [ "You cannot update " $items & " items." ]
END IF

But this is way too cumbersome and tedious to write over and over again as there are too many script steps involved. Yuck!

There are more elegant ways to handle pluralisation that don’t involve so many script steps.

Using calculations

A better way to handle the above code would be to use an IF statement with your ‘Show Custom Dialog’ calculation formula as follows:

If ($items = 1, "You cannot update 1 item.", "You cannot update" & $items & " items.")

Another approach I’ve seen FileMaker developers use is to simply append an “s” at the end of the word you want to pluralise using an IF statement as follows:

"You cannot update " & $items & " item" & If($items <> 1, "s") & "."

Another approach is to wrap the IF statement around the word you want to pluralise as follows:

"You cannot update " & $items & " " & If($items <> 1, "items", "item") & "."

Any of these work fine. But writing lots of IF statements is still tedious especially if you have a sizeable FileMaker Solution with lots of error handling or messages.

Using a Custom Function

In FileMaker, the best approach is to write a Custom Function that handles pluralisation for you and simply call that Custom Function from your message strings.

Looking at the above code, we can rule out appending an ‘s’ at the end of a word to pluralise it – this wont suit a Custom Function.

Why wont this suit? Well not all words can be pluralised by adding an ‘s’ at the end of it. For example ‘entry’ is pluralised as ‘entries’ – the ‘y’ is dropped and ‘ies’ is added. Another example is ‘box’ which is pluralised as ‘boxes’ by adding ‘es’ at the end of it. Then there’s ‘quiz’ which is pluralised as ‘quizzes’ by adding ‘zes’

Actually, you could write a complex custom function that checks the singular word and determines which grammatical rule to use – but why bother. Too much effort.

I have found the best approach (and the most flexible) is to wrap the word you want to pluralise and pass both the singular and plural version of the word. Oh, and it will work for any language not just English.

For example your message calculation formula would look something like this:

"You cannot update " & Plural($items, "item", "items") & "."

Creating the Custom Function

In case you are new to FileMaker, to create a Custom Function you will need FileMaker Pro Advanced. The standard version FileMaker Pro does not allow you to create custom functions. To create a custom function, go to File -> Manage -> Custom Functions, then click ‘New’.

Give your custom Function a name, call it: Plural

FileMaker Custom Function Name

Add the 3 parameters: Number, SingleWord, PluralWord (Enter the parameter names one by one and hit the ‘+’ button)

FileMaker Custom Function Parameters

Enter the formulation:

Number & " " & Case(Number = 1; SingularWord; PluralWord)

FileMaker Custom Function Formulation

Save your Custom Function and you are now ready to pluralise words within your messages.

Using the Custom Function

Now all you have to do is call the Custom Function within your dialog boxes as follows:

Plural(Number, SingularWord, PluralWord)

Number:  The value that you are passing to test whether it contains a 1 or more.
SingularWord: The singular version of the word to be displayed if ‘Number’ is equal to 1.
PluralWord: The plural version of the word to be displayed if ‘Number’ is more than 1.

Here’s an example of the Custom Function in use:

Plural($items, "item", "items")

The Custom Function simply evaluates the first parameter (number) and decides whether to show the Singular word or the Plural word.

If $items contains a 1, then the Custom Function will return “1 item”, whereas if $items contains a 3 then the Custom Function will return “3 items”.

Well that wraps it up for today. If you have a better method or can see any issue with my method above, please feel free to leave your comments below.

Have a great day.