From d9931bd611ee87ee1bfde7b00b17ed7c139d10b2 Mon Sep 17 00:00:00 2001 From: Oleg Loginov Date: Wed, 1 Aug 2018 17:30:19 +0300 Subject: [PATCH] Add ability to get resource from base localization when it absent in current --- Sources/String+LocalizedBundleTableName.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/String+LocalizedBundleTableName.swift b/Sources/String+LocalizedBundleTableName.swift index 9cdd2f1..b89cb91 100644 --- a/Sources/String+LocalizedBundleTableName.swift +++ b/Sources/String+LocalizedBundleTableName.swift @@ -25,8 +25,15 @@ public extension String { func localized(using tableName: String?, in bundle: Bundle?) -> String { let bundle: Bundle = bundle ?? .main if let path = bundle.path(forResource: Localize.currentLanguage(), ofType: "lproj"), - let bundle = Bundle(path: path) { - return bundle.localizedString(forKey: self, value: nil, table: tableName) + let currentLanguageBundle = Bundle(path: path) { + let localizedString = currentLanguageBundle.localizedString(forKey: self, value: nil, table: tableName) + if localizedString == self, + let basePath = bundle.path(forResource: LCLBaseBundle, ofType: "lproj"), + let bundle = Bundle(path: basePath) { + return bundle.localizedString(forKey: self, value: nil, table: tableName) + } else { + return localizedString + } } else if let path = bundle.path(forResource: LCLBaseBundle, ofType: "lproj"), let bundle = Bundle(path: path) {