Unity Localization incorrect plural formatter behaviour

tl;dr: Please, remove unnecessary code leading to exceptions

Currently I’m working on a game localization using Unity Localization package, and I’ve encountered quite strange behaviour of a plural formatter.

Chinese language doesn’t have different words for plural form. So, I expect following phrases to be handled the same
Make combo {0:plural:1 time|{} times}
完成 次组合 {0:plural:{} 次}

However, plural formatter breaks and throws exceptions. To be more specific it breaks due to a following check in the PluralLocalizationFormatter

public override bool TryEvaluateFormat(IFormattingInfo formattingInfo)
{
//...
This extension requires at least two plural words:
if (pluralWords.Count == 1) return false;
//...
}

I understand, that using plural formatter when there is actually no plurals in the language might appear like a nonsensable behaviour, but I believe keeping the consistency here is better.
Besides UnityEngine.Localization.SmartFormat.Utilities.PluralRules actually contains logic for handling Singular plural forms.

So, is that possible to remove that line on your side?

Hi,
We don’t have any plans to remove the check, doing so would make the implicit formatting unpredictable, and the plural formatter would start to handle more values than before.
We do have plans to upgrade the library in the future, the newer version does only do this check when implicit formatting is used so for your use case it would bypass it. I understand you want to be consistent but for now, you should avoid the plural formatter for singulars or modify the library locally and remove that line.

1 Like