Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4128236
txt2php.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
txt2php.php
View Options
<?php
/**
* txt2php: Converts the text file of ISO codes to a PHP static array definition.
*
* Usage: php txt2php.php
*/
namespace
MediaWiki\Babel
;
use
Maintenance
;
use
Wikimedia\StaticArrayWriter
;
require_once
getenv
(
'MW_INSTALL_PATH'
)
!==
false
?
getenv
(
'MW_INSTALL_PATH'
)
.
"/maintenance/Maintenance.php"
:
__DIR__
.
'/../../../maintenance/Maintenance.php'
;
// phpcs:ignore MediaWiki.Files.ClassMatchesFilename.WrongCase
class
TXT2PHP
extends
Maintenance
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
addDescription
(
'Converts ISO code text file to PHP static array'
);
}
public
function
execute
()
{
$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
);
}
}
$maintClass
=
TXT2PHP
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 09:08 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
12/3b/7769b40d6ce52a447dbeaec91cc3
Default Alt Text
txt2php.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment