-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SSDK-622] Add language parameter to offline tileset descriptor creat…
…ion (#202) ### Description Fixes [SSDK-622](https://mapbox.atlassian.net/browse/SSDK-622) Add optional `language` parameter that has two modes: 1. Absent language parameter / `nil` value will use existing behavior of _just_ the dataset name. 2. A given language parameter will be appended to the dataset name. ### Checklist - [x] Update `CHANGELOG` - [x] Add a non-English language test after #199 is merged
- Loading branch information
Showing
4 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 53 additions & 4 deletions
57
Sources/MapboxSearch/InternalAPI/CoreSearchEngineStatics.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,60 @@ | ||
import Foundation | ||
|
||
enum CoreSearchEngineStatics { | ||
static func createTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor { | ||
CoreSearchEngine.createTilesetDescriptor(forDataset: dataset, version: version) | ||
enum Constants { | ||
static let delimiter = "_" | ||
} | ||
|
||
static func createPlacesTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor { | ||
CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: dataset, version: version) | ||
static func createTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon | ||
.TilesetDescriptor { | ||
let identifier: String | ||
if let language { | ||
if ISOLanguages.contains(language: language) { | ||
identifier = dataset + Constants.delimiter + language | ||
} else { | ||
_Logger.searchSDK | ||
.warning( | ||
"Provided language code '\(language)' for tileset is non-ISO. Dataset '\(dataset)' without language will be used." | ||
) | ||
identifier = dataset | ||
} | ||
} else { | ||
identifier = dataset | ||
} | ||
return CoreSearchEngine.createTilesetDescriptor(forDataset: identifier, version: version) | ||
} | ||
|
||
static func createPlacesTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon | ||
.TilesetDescriptor { | ||
let identifier: String | ||
if let language { | ||
if ISOLanguages.contains(language: language) { | ||
identifier = dataset + Constants.delimiter + language | ||
} else { | ||
_Logger.searchSDK | ||
.warning( | ||
"Provided language code '\(language)' for places tileset is non-ISO. Dataset '\(dataset)' without language will be used." | ||
) | ||
identifier = dataset | ||
} | ||
} else { | ||
identifier = dataset | ||
} | ||
return CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: identifier, version: version) | ||
} | ||
} | ||
|
||
enum ISOLanguages { | ||
static func contains(language: String) -> Bool { | ||
var validLanguage: Bool | ||
if #available(iOS 16, *) { | ||
validLanguage = Locale.LanguageCode.isoLanguageCodes | ||
.map(\.identifier) | ||
.contains(language) | ||
} else { | ||
validLanguage = Locale.isoLanguageCodes | ||
.contains(language) | ||
} | ||
return validLanguage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters