From a19bccf4dad983e65cd2bf402a6d6544f16ae620 Mon Sep 17 00:00:00 2001 From: Alex Beaty Date: Sat, 26 Sep 2020 21:50:43 -0500 Subject: [PATCH] Merged 'Dynamic-translations-OFFUrlsHelper' --- Sources/Helpers/OFFUrlsHelper.swift | 25 +++++++++++-------- .../Common/IngredientsAnalysisView.swift | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Sources/Helpers/OFFUrlsHelper.swift b/Sources/Helpers/OFFUrlsHelper.swift index 5aeda723093..380ca613a97 100644 --- a/Sources/Helpers/OFFUrlsHelper.swift +++ b/Sources/Helpers/OFFUrlsHelper.swift @@ -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 @@ -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())/")! } } diff --git a/Sources/Views/Products/Detail/Common/IngredientsAnalysisView.swift b/Sources/Views/Products/Detail/Common/IngredientsAnalysisView.swift index 6d560b472b3..8922dd1ec99 100644 --- a/Sources/Views/Products/Detail/Common/IngredientsAnalysisView.swift +++ b/Sources/Views/Products/Detail/Common/IngredientsAnalysisView.swift @@ -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)