2 @define('CONST_LibDir', dirname(dirname(__FILE__)));
4 require_once(CONST_LibDir.'/init-cmd.php');
6 ini_set('memory_limit', '800M');
7 ini_set('display_errors', 'stderr');
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: .)'),
17 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
19 loadSettings($aCMDResult['project-dir'] ?? getcwd());
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).'"';
31 echo "UPDATE country_name set country_default_language_codes = '{".join(',', $aLanguages)."}' where country_code = '".pg_escape_string($aMatch[1])."';\n";