You can also try to do so:
function ruta_iso( $ruta = '') {
$slugs = array(
'noticia' => array(
'es' => 'noticia',
'en' => 'post'
),
'pregunta' => array(
'es' => 'pregunta',
'en' => 'question'
),
'consejo' => array(
'es' => 'consejo',
'en' => 'tip'
),
'noticias' => array(
'es' => 'noticias',
'en' => 'news'
)
);
$idioma_defecto = 'es';
$idioma = 'en' ;
foreach( explode('/', $ruta) as $data){
if( !empty($data) ){
if( array_key_exists($data, $slugs)){
$result[] = $slugs[$data][$idioma];
}else{
$result[] = $data;
}
}
}
$result = '/'.$idioma.'/'.implode('/', $result).'/';
return $result;
}
echo '-------Ruta Iso '.ruta_iso('/noticias/');
echo ' -------Ruta Iso '.ruta_iso('/noticias/noticia/');
echo '-------Ruta Iso '.ruta_iso('/noticias/noticia/the-new');
Result:
-------Ruta Iso /en/news/ -------Ruta Iso /en/news/post/
-------Ruta Iso /en/news/post/the-new/