Skip to content

Commit

Permalink
Merge pull request #35 from dulgan/patch-1
Browse files Browse the repository at this point in the history
Use current locale to localize countries names
  • Loading branch information
kizitonwose authored Feb 23, 2019
2 parents 2a3c88f + 2797e43 commit 5d994ec
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CountryPickerView/CountryPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ extension CountryPickerViewController {

var header = Set<String>()
countriesArray.forEach{
let name = $0.name
let name = Locale.current.localizedString(forRegionCode: $0.code) ?? $0.name
header.insert(String(name[name.startIndex]))
}

var data = [String: [Country]]()

countriesArray.forEach({
let name = $0.name
let name = Locale.current.localizedString(forRegionCode: $0.code) ?? $0.name
let index = String(name[name.startIndex])
var dictValue = data[index] ?? [Country]()
dictValue.append($0)
Expand Down Expand Up @@ -144,8 +144,9 @@ extension CountryPickerViewController {

let country = isSearchMode ? searchResults[indexPath.row]
: countries[sectionsTitles[indexPath.section]]![indexPath.row]

let name = dataSource.showPhoneCodeInList ? "\(country.name) (\(country.phoneCode))" : country.name

let countryName = Locale.current.localizedString(forRegionCode: country.code) ?? country.name
let name = dataSource.showPhoneCodeInList ? "\(countryName) (\(country.phoneCode))" : countryName
cell.imageView?.image = country.flag

cell.flgSize = dataSource.cellImageViewSize
Expand Down Expand Up @@ -232,7 +233,10 @@ extension CountryPickerViewController: UISearchResultsUpdating {
indexArray = array
}

searchResults.append(contentsOf: indexArray.filter({ $0.name.lowercased().hasPrefix(text.lowercased()) }))
searchResults.append(contentsOf: indexArray.filter({
let countryName = Locale.current.localizedString(forRegionCode: $0.code) ?? $0.name
return countryName.lowercased().hasPrefix(text.lowercased())
}))
}
tableView.reloadData()
}
Expand Down

0 comments on commit 5d994ec

Please sign in to comment.