Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Merged 'Dynamic-translations-OFFUrlsHelper'
Browse files Browse the repository at this point in the history
  • Loading branch information
jncosideout authored and teolemon committed Sep 29, 2020
1 parent 6d770aa commit a19bccf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions Sources/Helpers/OFFUrlsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,40 @@ import UIKit

class OFFUrlsHelper: NSObject {

static let codeLang = Bundle.main.preferredLocalizations.first ?? "en"
static let baseUrl = "https://world-\(codeLang).openfoodfacts.org"
static func codeLang() -> String {
return Bundle.main.currentLocalization
}

static func baseUrl() -> String {
return "https://world-\(codeLang()).openfoodfacts.org"
}

static func url(forCategory category: Category) -> URL {
return URL(string: "\(baseUrl)/category/\(category.code)")!
return URL(string: "\(baseUrl())/category/\(category.code)")!
}

static func url(for country: Country) -> URL {
return URL(string: "\(baseUrl)/country/\(country.code)")!
return URL(string: "\(baseUrl())/country/\(country.code)")!
}

static func url(forAdditive additive: Additive) -> URL {
return URL(string: "\(baseUrl)/additive/\(additive.code)")!
return URL(string: "\(baseUrl())/additive/\(additive.code)")!
}

static func url(forAllergen allergen: Allergen) -> URL {
return URL(string: "\(baseUrl)/allergen/\(allergen.code)")!
return URL(string: "\(baseUrl())/allergen/\(allergen.code)")!
}

static func url(forMineral mineral: Mineral) -> URL {
return URL(string: "\(baseUrl)/mineral/\(mineral.code)")!
return URL(string: "\(baseUrl())/mineral/\(mineral.code)")!
}

static func url(forVitamin vitamin: Vitamin) -> URL {
return URL(string: "\(baseUrl)/vitamin/\(vitamin.code)")!
return URL(string: "\(baseUrl())/vitamin/\(vitamin.code)")!
}

static func url(forNucleotide nucleotide: Nucleotide) -> URL {
return URL(string: "\(baseUrl)/nucleotide/\(nucleotide.code)")!
return URL(string: "\(baseUrl())/nucleotide/\(nucleotide.code)")!
}

// Not sure if there is a taxonomy for this
Expand All @@ -48,6 +53,6 @@ class OFFUrlsHelper: NSObject {
}
*/
static func url(forEmbCodeTag tag: String) -> URL {
return URL(string: "\(baseUrl)/packager-code/\(tag)") ?? URL(string: "\(baseUrl)/packager-codes/") ?? URL(string: "\(baseUrl)/")!
return URL(string: "\(baseUrl())/packager-code/\(tag)") ?? URL(string: "\(baseUrl())/packager-codes/") ?? URL(string: "\(baseUrl())/")!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import Cartography

newPage.actionButtonTitle = "ingredients-analysis.help-translate.button".localized
newPage.actionHandler = { item in
if let url = URL(string: OFFUrlsHelper.baseUrl + "/ingredients?translate=1") {
if let url = URL(string: OFFUrlsHelper.baseUrl() + "/ingredients?translate=1") {
self.viewController()?.openUrlInApp(url)
}
item.manager?.dismissBulletin(animated: true)
Expand Down

0 comments on commit a19bccf

Please sign in to comment.