Spain has a traditional problem with foreign languages. Spaniards younger than 40 are supposed to know English from school but the plain fact is that the level of English is close to zero almost everywhere.
So there're basically two type of software environments: code that's supposed to be shared with international parties (open source projects, Spanish offices of foreign multinationals, vendors who sell abroad) and code that's sold locally. The former is of course written in English but the latter is normally written in Spanish, both variable names and documentation. Words in variables lose accents and tildes as required to fit into 7-bit ASCII (dirección
-> direccion
) and English bits may be used when they represent a standard language feature (getDireccion
) or a concept without an universally accepted translation (abrirSocket
).
It happens that the Spanish word for year (año) becomes the word for anus when you remove the tilde. I don't have any problem with writing ano
but most other programmers avoid it at any cost and produce all sort of funny alternatives like anno
or anyo
:)
Some samples:
/**
* Devuelve una cadena aleatoria de la longitud indicada elegidos entre la lista proporcionada;
* contempla caracteres multi-byte
*/
function mb_cadena_aleatoria($longitud=16, $caracteres='0123456789abcdefghijklmnopqrstuvwxyz'){ // v2010-06-03
$cadena = '';
$max = mb_strlen($caracteres)-1;
for($i=0; $i<$longitud; $i++){
$cadena .= mb_substr($caracteres, mt_rand(0, $max), 1);
}
return $cadena;
}
/*
* Da formato a un número para su visualización
*
* numero (Number o String) - Número que se mostrará
* decimales (Number, opcional) - Nº de decimales (por defecto, auto)
* separador_decimal (String, opcional) - Separador decimal (por defecto, coma)
* separador_miles (String, opcional) - Separador de miles (por defecto, ninguno)
*/
function formato_numero(numero, decimales, separador_decimal, separador_miles){ // v2007-08-06
numero=parseFloat(numero);
if(isNaN(numero)){
return "";
}
if(decimales!==undefined){
// Redondeamos
numero=numero.toFixed(decimales);
}
// Convertimos el punto en separador_decimal
numero=numero.toString().replace(".", separador_decimal!==undefined ? separador_decimal : ",");
if(separador_miles){
// Añadimos los separadores de miles
var miles=new RegExp("(-?[0-9]+)([0-9]{3})");
while(miles.test(numero)) {
numero=numero.replace(miles, "$1" + separador_miles + "$2");
}
}
return numero;
}