summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2020-10-02 15:24:06 -0400
committerBrian Evans <grknight@gentoo.org>2020-10-02 15:24:06 -0400
commit60dd5fd95847643eab04ce173f0774c9c584e795 (patch)
tree52299ac4e3c5c69df75997bfd7d62b71ef9e0089 /MLEB/Babel/txt2php.php
parentUpdate Widgets to 1.35 (diff)
downloadextensions-60dd5fd95847643eab04ce173f0774c9c584e795.tar.gz
extensions-60dd5fd95847643eab04ce173f0774c9c584e795.tar.bz2
extensions-60dd5fd95847643eab04ce173f0774c9c584e795.zip
Update MLEB to 2020.07
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'MLEB/Babel/txt2php.php')
-rw-r--r--MLEB/Babel/txt2php.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/MLEB/Babel/txt2php.php b/MLEB/Babel/txt2php.php
new file mode 100644
index 00000000..71a8cb01
--- /dev/null
+++ b/MLEB/Babel/txt2php.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * txt2php: Converts the text file of ISO codes to a PHP static array definition.
+ *
+ * Usage: php txt2php.php
+ */
+
+ use Wikimedia\StaticArrayWriter;
+
+$dir = __DIR__;
+$IP = "$dir/../..";
+
+require_once "$IP/maintenance/commandLine.inc";
+
+$dir = __DIR__;
+
+$names = [];
+$codes = [];
+$fr = fopen( "$dir/codes.txt", 'r' );
+
+while ( true ) {
+ $line = fgets( $fr );
+ if ( !$line ) {
+ break;
+ }
+
+ // Format is code1 code2 "language name"
+ $line = explode( ' ', $line, 3 );
+ $iso1 = trim( $line[0] );
+ $iso3 = trim( $line[1] );
+ // Strip quotes
+ $name = substr( trim( $line[2] ), 1, -1 );
+ if ( $iso1 !== '-' ) {
+ $codes[ $iso1 ] = $iso1;
+ if ( $iso3 !== '-' ) {
+ $codes[ $iso3 ] = $iso1;
+ }
+ $names[ $iso1 ] = $name;
+ $names[ $iso3 ] = $name;
+ } elseif ( $iso3 !== '-' ) {
+ $codes[ $iso3 ] = $iso3;
+ $names[ $iso3 ] = $name;
+ }
+}
+
+fclose( $fr );
+
+$writer = new StaticArrayWriter();
+$header = 'This file is generated by txt2php.php. Do not edit it directly.';
+$code = $writer->create( $names, $header );
+file_put_contents( "$dir/names.php", $code );
+
+$code = $writer->create( $codes, $header );
+file_put_contents( "$dir/codes.php", $code );