- // check for roman numbers like VII, XIX...
- // Lookahead assertion ensures $roman doesn't match the empty string
- $roman = '/^(?=[MDCLXVI])M{0,4}(C[DM]|D?C{0,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3})$/u';
-
- # match any sub-string of the relevant letters and convert it
- $matches = preg_split( '/(\b|^)[^' . $letters . ']+(\b|$)/u',
- $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
- $mstart = 0;
- $ret = '';
- foreach ( $matches as $m ) {
- # copy over the non-matching bit
- $ret .= substr( $text, $mstart, $m[1] - $mstart );
- # skip certain classes of strings
-
- if ( array_key_exists( $m[0], $this->mExceptions ) ) {
- # if it's an exception, just copy down the right answer
- $ret .= $this->mExceptions[$m[0]];
- } elseif ( ! $m[0] || # empty strings
- preg_match( $roman, $m[0] ) || # roman numerals
- preg_match( '/[^' . $letters . ']/', $m[0] ) # mixed orthography
- ) {
- $ret .= $m[0];
- } else {
- # convert according to the rules
- $token = $this->regsConverter( $m[0], $toVariant );
- $ret .= parent::translate( $token, $toVariant );
- }
- $mstart = $m[1] + strlen( $m[0] );
- }
-
- # pick up stray quote marks