Closed soukicz closed 6 years ago
Maybe an easier solution is just check whether the plural form has any letter different than n
?
Somethin like this (not tested):
if (preg_match('/[A-Ma-mO-Zo-z]/', str_replace('return ', '', $code)) {
throw new \InvalidArgumentException('Invalid Plural form: ' . $code);
}
Just an idea, what do you think?
It would be also better to check it in setter before variable substitution. I will updated it.
We can also test the regexp with all possible formulas to be sure that doesn't fail with any valid plural formula.
$languages = Gettext\Languages\Language::getAll();
foreach ($languages as $language) {
//test $language->formula
}
I have simplified validation and added testing for predefined plural forms.
Great. Thank you 👍
My previous PR https://github.com/oscarotero/Gettext/pull/156 missed some characters in plural forms validation