| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActiveSupport 13 * @subpackage Inflector 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 * @deprecated use AkInflector::pluralize('país',null,'es') to use spanish dictionary in (config/inflector/es.yml) 18 */ 19 20 require_once (AK_LIB_DIR.DS.'AkInflector.php'); 21 22 /** 23 * Spanish Inflector 24 */ 25 class AkInflexor extends AkInflector 26 { 27 28 function pluralize($word) 29 { 30 $plural = array( 31 '/([aeiou])x$/i'=> '\\1x', // This could fail if the word is oxytone. 32 '/([áéíóú])([ns])$/i'=> '|1\\2es', 33 '/(^[bcdfghjklmnñpqrstvwxyz]*)an$/i'=>'\\1anes', //clan->clanes 34 '/([áéíóú])s$/i'=> '|1ses', 35 '/(^[bcdfghjklmnñpqrstvwxyz]*)([aeiou])([ns])$/i'=>'\\1\\2\\3es', //tren->trenes 36 '/([aeiouáéó])$/i'=> '\\1s', // casa->casas, padre->padres, papá->papás 37 '/([aeiou])s$/i'=> '\\1s', // atlas->atlas, virus->virus, etc. 38 '/([éí])(s)$/i'=> '|1\\2es', // inglés->ingleses 39 '/z$/i'=> 'ces', // luz->luces 40 '/([íú])$/i' => '\\1es', // ceutí->ceutíes, tabú->tabúes 41 '/(ng|[wckgtp])$/'=>'\\1s', // Anglicismos como puenting, frac, crack, show (En que casos podría fallar esto?) 42 '/$/i'=> 'es', // ELSE +es (v.g. árbol->árboles) 43 ); // We should manage _orden_ -> _órdenes_, _joven_->_jóvenes_ and so. 44 45 $uncountable = array('tijeras','gafas', 'vacaciones','víveres','déficit'); 46 /* In fact these words have no singular form: you cannot say neither 47 "una gafa" nor "un vívere". So we should change the variable name to 48 $onlyplural or something alike.*/ 49 $irregular = array( 50 'país'=>'países', 51 'champú'=>'champús', 52 'jersey'=>'jerséis', 53 'carácter'=>'caracteres', 54 'espécimen'=>'especímenes', 55 'menú'=>'menús', 56 'régimen'=>'regímenes', 57 'curriculum' => 'currículos', 58 'ultimátum' => 'ultimatos', 59 'memorándum' => 'memorandos', 60 'referéndum' => 'referendos' 61 ); 62 $lowercased_word = strtolower($word); 63 64 65 foreach ($uncountable as $_uncountable){ 66 if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ 67 return $word; 68 } 69 } 70 71 foreach ($irregular as $_plural=> $_singular){ 72 if (preg_match('/('.$_plural.')$/i', $word, $arr)) { 73 return preg_replace('/('.$_plural.')$/i', substr($arr[0],0,1).substr($_singular,1), $word); 74 } 75 } 76 77 foreach ($plural as $rule => $replacement) { 78 if (preg_match($rule, $word, $match)) { 79 if(strstr($replacement,'|')){ 80 foreach ($match as $k=>$v){ 81 $replacement = str_replace("|$k",strtr($v,'ÁÉÍÓÚáéíóú','AEIOUaeiou'), $replacement); 82 } 83 } 84 $result = preg_replace($rule, $replacement, $word); 85 // Esto acentua los sustantivos que al pluralizarse se convierten en esdrújulos como esmóquines, jóvenes... 86 if(preg_match('/([aeiou]).{1,3}[aeiou]nes$/i',$result,$match) && !preg_match('/[áéíóú]/i',$word)){ 87 $result = str_replace($match[0], strtr($match[1],'AEIOUaeiou','ÁÉÍÓÚáéíóú').substr($match[0],1), $result); 88 } 89 return $result; 90 } 91 } 92 return false; 93 94 } 95 96 function singularize($word) 97 { 98 $singular = array ( 99 '/^([bcdfghjklmnñpqrstvwxyz]*)([aeiou])([ns])es$/i'=> '\\1\\2\\3', 100 '/([aeiou])([ns])es$/i'=> '~1\\2', 101 '/oides$/i'=> 'oide', //androides->androide 102 '/(ces)$/i' => 'z', 103 '/(sis|tis|xis)+$/i'=> '\\1', //crisis, apendicitis, praxis 104 '/(é)s$/i'=> '\\1', // bebés->bebé 105 '/([^e])s$/i'=> '\\1', // casas->casa 106 '/([bcdfghjklmnñprstvwxyz]{2,}e)s$/i'=>'\\1', // cofres->cofre 107 '/([ghñpv]e)s$/i'=>'\\1', // 24-01 llaves->llave 108 '/es$/i'=>'', // ELSE remove _es_ monitores->monitor 109 ); 110 111 112 $uncountable = array('paraguas','tijeras','gafas', 'vacaciones','víveres','lunes','martes','miércoles','jueves','viernes','cumpleaños','virus','atlas','sms'); 113 $irregular = array( 114 'jersey'=>'jerséis', 115 'espécimen'=>'especímenes', 116 'carácter'=>'caracteres', 117 'régimen'=>'regímenes', 118 'menú'=>'menús', 119 'régimen'=>'regímenes', 120 'curriculum' => 'currículos', 121 'ultimátum' => 'ultimatos', 122 'memorándum' => 'memorandos', 123 'referéndum' => 'referendos', 124 'sándwich' => 'sándwiches' 125 ); 126 127 $lowercased_word = strtolower($word); 128 foreach ($uncountable as $_uncountable){ 129 if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ 130 return $word; 131 } 132 } 133 134 foreach ($irregular as $_plural=> $_singular){ 135 if (preg_match('/('.$_singular.')$/i', $word, $arr)) { 136 return preg_replace('/('.$_singular.')$/i', substr($arr[0],0,1).substr($_plural,1), $word); 137 } 138 } 139 140 foreach ($singular as $rule => $replacement) { 141 if (preg_match($rule, $word, $match)) { 142 if(strstr($replacement,'~')){ 143 foreach ($match as $k=>$v){ 144 $replacement = str_replace("~$k",strtr($v,'AEIOUaeiou','ÁÉÍÓÚáéíóú'), $replacement); 145 } 146 } 147 148 $result = preg_replace($rule, $replacement, $word); 149 // Esta es una posible solución para el problema de dobles acentos. Un poco sucio pero funciona 150 $result = preg_match('/([áéíóú]).*([áéíóú])/',$result) ? strtr($result,'ÁÉÍÓÚáéíóú','AEIOUaeiou') : $result; 151 152 return $result; 153 } 154 } 155 156 return $word; 157 } 158 } 159 160 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |