blob: 7af8bc0b60d0d645792842a97d4a38b7624bfd8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?php
/**
* tab2txt: Converts the original tabulated data file of ISO codes to a three
* column text file (ISO 639-1, ISO 639-3, Natural Name).
*
* Usage: <tab file> | php tab2txt.php > codes.txt
*/
$dir = __DIR__;
$IP = "$dir/../..";
if ( file_exists( "$dir/../../CorePath.php" ) ) {
include "$dir/../../CorePath.php"; // Allow override
}
require_once "$IP/maintenance/commandLine.inc";
$fr = fopen( 'php://stdin', 'r' );
$fw = fopen( 'php://stdout', 'w' );
// Read and discard header line.
fgets( $fr );
while ( $line = fgets( $fr ) ) {
$line = explode( "\t", $line );
$iso1 = trim( $line[3] );
if ( $iso1 === '' ) {
$iso1 = '-';
}
$iso3 = trim( $line[0] );
$name = $line[6];
fwrite( $fw, "$iso1 $iso3 \"$name\"\n" );
}
fclose( $fr );
fclose( $fw );
|