We are planning on adding multi-language support for our ASP .Net Website. I understand the general process of pulling strings from resource files based on the current culture, but what is the best way to deal with the following situation?
Lets say that we want to display to the user how many Stack Overflow posts they have made today. Lets say that 'i' is the post count. You would then have the following code if you were just working in english.
if(i == 1)
{
postCountText = "You have made " + i + " post today";
} else {
postCountText = "You have made " + i + " posts today";
}
So the text is being created based on whether we are dealing in singular or plural posts.
What if we then want to create the post count text in any other language? Obviously we can't have lots of conditional statements like above, so the strings in the resource files need to work automatically to create the desired output text. In another language it may be that it isn't just the 'post(s)' word that changes, but maybe the word 'today' as well, when you move between singular and plural.
The only idea I have had so far is to store two strings in the external resource file, one for singular and one for plural, and then apply a String.Format to these to insert the post count in the correct location.
i.e.
The resource file for English would contain the following two strings:
singlePostCount : "You have made {0} post today"
pluralPostCount : "You have made {0} posts today"
Then I would have the following code to create the output text:
if(i == 1)
{
postCountText = String.Format(GetResourceString("singlePostCount"), i);
} else {
postCountText = String.Format(GetResourceString("pluralPostCount"), i);
}
This would then allow the text to change correctly for any languauge. But then, what if a certain language requires different text if there are zero posts? etc etc
Hopefully I have explained this ok. Thanks in advance for any help