]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/admin/country_languages.php
Cleaned tests of exceptions and fix phrase_settings.json test file name.
[nominatim.git] / lib-php / admin / country_languages.php
1 <?php
2 @define('CONST_LibDir', dirname(dirname(__FILE__)));
3
4 require_once(CONST_LibDir.'/init-cmd.php');
5
6 ini_set('memory_limit', '800M');
7 ini_set('display_errors', 'stderr');
8
9 $aCMDOptions
10  = array(
11     'Import country language data from osm wiki',
12     array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
13     array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
14     array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
15     array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'),
16    );
17 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
18
19 loadSettings($aCMDResult['project-dir'] ?? getcwd());
20 setupHTTPProxy();
21
22 if (true) {
23     $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes';
24     $sWikiPageXML = file_get_contents($sURL);
25     if (preg_match_all('#\\| ([a-z]{2}) \\|\\| [^|]+\\|\\| ([a-z,]+)#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
26         foreach ($aMatches as $aMatch) {
27             $aLanguages = explode(',', $aMatch[2]);
28             foreach ($aLanguages as $i => $s) {
29                 $aLanguages[$i] = '"'.pg_escape_string($s).'"';
30             }
31             echo "UPDATE country_name set country_default_language_codes = '{".join(',', $aLanguages)."}' where country_code = '".pg_escape_string($aMatch[1])."';\n";
32         }
33     }
34 }