Freigeben über


Obtener locales instalados en Azure Websites (PaaS)

Hola a todos, hoy les quiero compartir la solución a un problema con el que acabo de toparme. Algo fantástico de PaaS, y especialmente de Azure Websites es la abstracción que se le da al desarrollador sobre lo que sucede por “debajo” de la app. Por ejemplo, si yo soy un desarrollador PHP (o .NET, Java, Node.JS, HTML y JS, etc.) pongo mi foco en escribir el código y me olvido sobre la instalación de PHP (u otro). configuración del web server, instalación y mantenimiento del sistema operativo (SO) y así podemos seguir bajando hasta el hardware. Esto agiliza muchísimo los tiempos de desarrollo y reduce también los costos de administración y mantenimiento.

No obstante, existen escenarios donde necesitamos conocer un poco más sobre la capa subyacente a mi aplicación. Por ejemplo, que pasa si necesitamos conocer la lista de locales instalados en el sistema operativo?

Con estos simples pasos, les muestro una manera de consultar vía PHP la lista de locales instalados.

El código que tenemos que ejecutar será el siguiente:

<?php
header( 'Content-Type: text/html; charset=utf-8' );
// source of the list:
//
https://msdn.microsoft.com/en-us/library/39cwe7zf(v=vs.90).aspx
$langs = array(
// language, sublanguage, codes
array( 'Chinese', 'Chinese', array( 'chinese' ) ),
array( 'Chinese', 'Chinese (simplified)', array( 'chinese-simplified', 'chs' ) ),
array( 'Chinese', 'Chinese (traditional)', array( 'chinese-traditional', 'cht' ) ),
array( 'Czech', 'Czech', array( 'csy', 'czech' ) ),
array( 'Danish', 'Danish', array( 'dan', 'danish' ) ),
array( 'Dutch', 'Dutch (default)', array( 'dutch', 'nld' ) ),
array( 'Dutch', 'Dutch (Belgium)', array( 'belgian', 'dutch-belgian', 'nlb' ) ),
array( 'English', 'English (default)', array( 'english' ) ),
array( 'English', 'English (Australia)', array( 'australian', 'ena', 'english-aus' ) ),
array( 'English', 'English (Canada)', array( 'canadian', 'enc', 'english-can' ) ),
array( 'English', 'English (New Zealand)', array( 'english-nz', 'enz' ) ),
array( 'English', 'English (United Kingdom)', array( 'eng', 'english-uk', 'uk' ) ),
array( 'English', 'English (United States)', array( 'american', 'american english', 'american-english', 'english-american', 'english-us', 'english-usa', 'enu', 'us', 'usa' ) ),
array( 'Finnish', 'Finnish', array( 'fin', 'finnish' ) ),
array( 'French', 'French (default)', array( 'fra', 'french' ) ),
array( 'French', 'French (Belgium)', array( 'frb', 'french-belgian' ) ),
array( 'French', 'French (Canada)', array( 'frc', 'french-canadian' ) ),
array( 'French', 'French (Switzerland)', array( 'french-swiss', 'frs' ) ),
array( 'German', 'German (default)', array( 'deu', 'german' ) ),
array( 'German', 'German (Austria)', array( 'dea', 'german-austrian' ) ),
array( 'German', 'German (Switzerland)', array( 'des', 'german-swiss', 'swiss' ) ),
array( 'Greek', 'Greek', array( 'ell', 'greek' ) ),
array( 'Hungarian', 'Hungarian', array( 'hun', 'hungarian' ) ),
array( 'Icelandic', 'Icelandic', array( 'icelandic', 'isl' ) ),
array( 'Italian', 'Italian (default)', array( 'ita', 'italian' ) ),
array( 'Italian', 'Italian (Switzerland)', array( 'italian-swiss', 'its' ) ),
array( 'Japanese', 'Japanese', array( 'japanese', 'jpn' ) ),
array( 'Korean', 'Korean', array( 'kor', 'korean' ) ),
array( 'Norwegian', 'Norwegian (default)', array( 'norwegian' ) ),
array( 'Norwegian', 'Norwegian (Bokmal)', array( 'nor', 'norwegian-bokmal' ) ),
array( 'Norwegian', 'Norwegian (Nynorsk)', array( 'non', 'norwegian-nynorsk' ) ),
array( 'Polish', 'Polish', array( 'plk', 'polish' ) ),
array( 'Portuguese', 'Portuguese (default)', array( 'portuguese', 'ptg' ) ),
array( 'Portuguese', 'Portuguese (Brazil)', array( 'portuguese-brazilian', 'ptb' ) ),
array( 'Russian', 'Russian (default)', array( 'rus', 'russian' ) ),
array( 'Slovak', 'Slovak', array( 'sky', 'slovak' ) ),
array( 'Spanish', 'Spanish (default)', array( 'esp', 'spanish' ) ),
array( 'Spanish', 'Spanish (Mexico)', array( 'esm', 'spanish-mexican' ) ),
array( 'Spanish', 'Spanish (Modern)', array( 'esn', 'spanish-modern' ) ),
array( 'Swedish', 'Swedish', array( 'sve', 'swedish' ) ),
array( 'Turkish', 'Turkish', array( 'trk', 'turkish' ) )
);
echo '<table>'."\n";
echo '<tr>'."\n";
echo ' <th>Languange</th>'."\n";
echo ' <th>Sub-Languange</th>'."\n";
echo ' <th>Languange String</th>'."\n";
echo '</tr>'."\n";
foreach ( $langs as $lang ) {
echo '<tr>'."\n";
echo ' <td>'.$lang[0].'</td>'."\n";
echo ' <td>'.$lang[1].'</td>'."\n";
$a = array();
foreach ( $lang[2] as $lang_code ) {
$loc = setlocale( LC_ALL, $lang_code );
$a []= $lang_code.' '.( false === $loc ? '✖' : '✔ - '.$loc );
}
echo ' <td>'.implode( '<br>', $a ).'</td>'."\n";
echo '</tr>'."\n";
}
echo '</table>'."\n";
?>

Este script valida cuales son las locales instaladas, y en caso de estar instaladas, las imprime por pantalla.

Simplemente lo que hacemos es guardar este código en un archivo locale.php y lo subimos al web site. En mi caso, lo hice vía FTP. Luego finalmente ingreamos a nuestrositio.com/locale.php y veremos algo como lo siguiente:

image

A continuación el listado complete de locales soportadas por Azure Websites:

Chinese Chinese chinese ? - Chinese (Simplified)_China.936
Chinese Chinese (simplified) chinese-simplified ? - Chinese (Simplified)_China.936
chs ? - Chinese (Simplified)_China.936
Chinese Chinese (traditional) chinese-traditional ? - Chinese (Traditional)_Taiwan.950
cht ? - Chinese (Traditional)_Taiwan.950
Czech Czech csy ? - Czech_Czech Republic.1250
czech ? - Czech_Czech Republic.1250
Danish Danish dan ? - Danish_Denmark.1252
danish ? - Danish_Denmark.1252
Dutch Dutch (default) dutch ? - Dutch_Netherlands.1252
nld ? - Dutch_Netherlands.1252
Dutch Dutch (Belgium) belgian ? - Dutch_Belgium.1252
dutch-belgian ? - Dutch_Belgium.1252
nlb ? - Dutch_Belgium.1252
English English (default) english ? - English_United States.1252
English English (Australia) australian ? - English_Australia.1252
ena ? - English_Australia.1252
english-aus ? - English_Australia.1252
English English (Canada) canadian ? - English_Canada.1252
enc ? - English_Canada.1252
english-can ? - English_Canada.1252
English English (New Zealand) english-nz ? - English_New Zealand.1252
enz ? - English_New Zealand.1252
English English (United Kingdom) eng ? - English_United Kingdom.1252
english-uk ? - English_United Kingdom.1252
uk ? - English_United Kingdom.1252
English English (United States) american ? - English_United States.1252
american english ? - English_United States.1252
american-english ? - English_United States.1252
english-american ? - English_United States.1252
english-us ? - English_United States.1252
english-usa ? - English_United States.1252
enu ? - English_United States.1252
us ? - English_United States.1252
usa ? - English_United States.1252
Finnish Finnish fin ? - Finnish_Finland.1252
finnish ? - Finnish_Finland.1252
French French (default) fra ? - French_France.1252
french ? - French_France.1252
French French (Belgium) frb ? - French_Belgium.1252
french-belgian ? - French_Belgium.1252
French French (Canada) frc ? - French_Canada.1252
french-canadian ? - French_Canada.1252
French French (Switzerland) french-swiss ? - French_Switzerland.1252
frs ? - French_Switzerland.1252
German German (default) deu ? - German_Germany.1252
german ? - German_Germany.1252
German German (Austria) dea ? - German_Austria.1252
german-austrian ? - German_Austria.1252
German German (Switzerland) des ? - German_Switzerland.1252
german-swiss ? - German_Switzerland.1252
swiss ? - German_Switzerland.1252
Greek Greek ell ? - Greek_Greece.1253
greek ? - Greek_Greece.1253
Hungarian Hungarian hun ? - Hungarian_Hungary.1250
hungarian ? - Hungarian_Hungary.1250
Icelandic Icelandic icelandic ? - Icelandic_Iceland.1252
isl ? - Icelandic_Iceland.1252
Italian Italian (default) ita ? - Italian_Italy.1252
italian ? - Italian_Italy.1252
Italian Italian (Switzerland) italian-swiss ? - Italian_Switzerland.1252
its ? - Italian_Switzerland.1252
Japanese Japanese japanese ? - Japanese_Japan.932
jpn ? - Japanese_Japan.932
Korean Korean kor ? - Korean_Korea.949
korean ? - Korean_Korea.949
Norwegian Norwegian (default) norwegian ? - Norwegian (Bokm�l)_Norway.1252
Norwegian Norwegian (Bokmal) nor ? - Norwegian (Bokm�l)_Norway.1252
norwegian-bokmal ? - Norwegian (Bokm�l)_Norway.1252
Norwegian Norwegian (Nynorsk) non ? - Norwegian-Nynorsk_Norway.1252
norwegian-nynorsk ? - Norwegian-Nynorsk_Norway.1252
Polish Polish plk ? - Polish_Poland.1250
polish ? - Polish_Poland.1250
Portuguese Portuguese (default) portuguese ? - Portuguese_Brazil.1252
ptg ? - Portuguese_Portugal.1252
Portuguese Portuguese (Brazil) portuguese-brazilian ? - Portuguese_Brazil.1252
ptb ? - Portuguese_Brazil.1252
Russian Russian (default) rus ? - Russian_Russia.1251
russian ? - Russian_Russia.1251
Slovak Slovak sky ? - Slovak_Slovakia.1250
slovak ? - Slovak_Slovakia.1250
Spanish Spanish (default) esp ? - Spanish_Spain.1252
spanish ? - Spanish_Spain.1252
Spanish Spanish (Mexico) esm ? - Spanish_Mexico.1252
spanish-mexican ? - Spanish_Mexico.1252
Spanish Spanish (Modern) esn ? - Spanish_Spain.1252
spanish-modern ? - Spanish_Spain.1252
Swedish Swedish sve ? - Swedish_Sweden.1252
swedish ? - Swedish_Sweden.1252
Turkish Turkish trk ? - Turkish_Turkey.1254
turkish ? - Turkish_Turkey.1254