getGrammarTransformations(); if ( isset( $grammarTransformations[$case] ) ) { foreach ( array_values( $grammarTransformations[$case] ) as $rule ) { $form = $rule[0]; if ( $form === '@metadata' ) { continue; } $replacement = $rule[1]; $regex = "/$form/"; if ( preg_match( $regex, $word ) ) { $word = preg_replace( $regex, $replacement, $word ); break; } } } return $word; } /** * Four-digit number should be without group commas (spaces) * See manual of style at https://ru.wikipedia.org/wiki/Википедия:Оформление_статей * So "1 234 567", "12 345" but "1234" * * @param string $_ * * @return string */ function commafy( $_ ) { if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) { return $_; } else { return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); } } }