$genericDefinition = null; $addressFormats = []; $groupedSubdivisions = []; foreach ($foundCountries as $countryCode) { $definition = file_get_contents('raw/' . $countryCode . '.json'); $definition = json_decode($definition, true); $extraKeys = array_diff(array_keys($definition), ['id', 'key', 'name']); if (empty($extraKeys)) { // This is an empty definition, skip it. continue; } if ($countryCode == 'MO') { // Fix for Macao, which has latin and non-latin formats, but no lang. $definition['lang'] = 'zh'; } $addressFormat = create_address_format_definition($countryCode, $definition); // Create a list of available translations. // Ignore Hong Kong because the listed translation (English) is already // provided through the lname property. $languages = []; if (isset($definition['languages']) && $countryCode != 'HK') { $languages = explode('~', $definition['languages']); array_shift($languages); } if (isset($definition['sub_keys'])) { $subdivisionPaths = []; $subdivisionKeys = explode('~', $definition['sub_keys']); foreach ($subdivisionKeys as $subdivisionKey) { $subdivisionPaths[] = $countryCode . '_' . $subdivisionKey; } $groupedSubdivisions += generate_subdivisions($countryCode, [$countryCode], $subdivisionPaths, $languages);
if (empty($extraKeys)) { // This is an empty definition, skip it. continue; } if ($countryCode == 'MO') { // Fix for Macao, which has latin and non-latin formats, but no lang. $definition['lang'] = 'zh'; } if ($countryCode == 'ZZ') { // Save the ZZ definitions so that they can be used later. $genericDefinition = $definition; } else { // Merge-in the defaults from ZZ. $definition += $genericDefinition; } $addressFormat = create_address_format_definition($definition); // Create a list of available translations. // Ignore Hong Kong because the listed translation (English) is already // provided through the lname property. $languages = []; if (isset($definition['languages']) && $countryCode != 'HK') { $languages = explode('~', $definition['languages']); array_shift($languages); } if (isset($definition['sub_keys'])) { $subdivisionPaths = []; $subdivisionKeys = explode('~', $definition['sub_keys']); foreach ($subdivisionKeys as $subdivisionKey) { $subdivisionPaths[] = $countryCode . '_' . $subdivisionKey; } $groupedSubdivisions += generate_subdivisions($countryCode, $countryCode, $subdivisionPaths, $languages);