|
|
|
|
@@ -20,12 +20,13 @@
|
|
|
|
|
|
|
|
|
|
include __DIR__ . '/spyc.php';
|
|
|
|
|
|
|
|
|
|
print( "Reading langdb.yaml...\n" );
|
|
|
|
|
print "Reading langdb.yaml...\n";
|
|
|
|
|
$yamlLangdb = file_get_contents( 'langdb.yaml' );
|
|
|
|
|
$parsedLangdb = spyc_load( $yamlLangdb );
|
|
|
|
|
|
|
|
|
|
$supplementalDataFilename = 'supplementalData.xml';
|
|
|
|
|
$supplementalDataUrl = "http://unicode.org/repos/cldr/trunk/common/supplemental/$supplementalDataFilename";
|
|
|
|
|
$supplementalDataUrl =
|
|
|
|
|
"http://unicode.org/repos/cldr/trunk/common/supplemental/$supplementalDataFilename";
|
|
|
|
|
|
|
|
|
|
$curl = curl_init( $supplementalDataUrl );
|
|
|
|
|
$supplementalDataFile = fopen( $supplementalDataFilename, 'w' );
|
|
|
|
|
@@ -33,7 +34,7 @@ $supplementalDataFile = fopen( $supplementalDataFilename, 'w' );
|
|
|
|
|
curl_setopt( $curl, CURLOPT_FILE, $supplementalDataFile );
|
|
|
|
|
curl_setopt( $curl, CURLOPT_HEADER, 0 );
|
|
|
|
|
|
|
|
|
|
print( "Trying to download $supplementalDataUrl...\n" );
|
|
|
|
|
print "Trying to download $supplementalDataUrl...\n";
|
|
|
|
|
$curlSuccess = curl_exec( $curl );
|
|
|
|
|
curl_close( $curl );
|
|
|
|
|
fclose( $supplementalDataFile );
|
|
|
|
|
@@ -41,7 +42,7 @@ fclose( $supplementalDataFile );
|
|
|
|
|
if ( !$curlSuccess ) {
|
|
|
|
|
die( "Failed to download CLDR data from $supplementalDataUrl.\n" );
|
|
|
|
|
}
|
|
|
|
|
print( "Downloaded $supplementalDataFilename, trying to parse...\n" );
|
|
|
|
|
print "Downloaded $supplementalDataFilename, trying to parse...\n";
|
|
|
|
|
|
|
|
|
|
$supplementalData = simplexml_load_file( $supplementalDataFilename );
|
|
|
|
|
|
|
|
|
|
@@ -49,7 +50,7 @@ if ( !( $supplementalData instanceof SimpleXMLElement ) ) {
|
|
|
|
|
die( "Attempt to load CLDR data from $supplementalDataFilename failed.\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print( "CLDR supplemental data parsed successfully, reading territories info...\n" );
|
|
|
|
|
print "CLDR supplemental data parsed successfully, reading territories info...\n";
|
|
|
|
|
$parsedLangdb['territories'] = array();
|
|
|
|
|
|
|
|
|
|
foreach ( $supplementalData->territoryInfo->territory as $territoryRecord ) {
|
|
|
|
|
@@ -64,10 +65,11 @@ foreach ( $supplementalData->territoryInfo->territory as $territoryRecord ) {
|
|
|
|
|
// Lower case is a convention for language codes in ULS.
|
|
|
|
|
// '_' is used in CLDR for compound codes and it's replaced with '-' here.
|
|
|
|
|
$parsedLangdb['territories'][$territoryCode][] =
|
|
|
|
|
strtr( strtolower( (string) $languageCodeAttr[0] ), '_', '-' ); }
|
|
|
|
|
strtr( strtolower( (string) $languageCodeAttr[0] ), '_', '-' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print( "Writing JSON langdb...\n" );
|
|
|
|
|
print "Writing JSON langdb...\n";
|
|
|
|
|
$json = json_encode( $parsedLangdb );
|
|
|
|
|
$js = <<<JAVASCRIPT
|
|
|
|
|
// Please do not edit. This file is generated from data/langdb.yaml by ulsdata2json.php
|
|
|
|
|
@@ -80,4 +82,4 @@ $js = <<<JAVASCRIPT
|
|
|
|
|
JAVASCRIPT;
|
|
|
|
|
file_put_contents( '../src/jquery.uls.data.js', $js );
|
|
|
|
|
|
|
|
|
|
print( "Done.\n" );
|
|
|
|
|
print "Done.\n";
|
|
|
|
|
|