From 59ef790a2dbe65289a1b447cbbf7fe2c29cace56 Mon Sep 17 00:00:00 2001 From: Tomasz Szulc Date: Fri, 21 Oct 2016 22:54:22 +0200 Subject: [PATCH 1/6] Add note about Swift 3 support --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index cc1a644..d70a180 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ # Swifternalization Swift library that helps in localizing apps in a different, better, simpler, more powerful way than system localization does. It uses json files instead of strings files. +# Swift 3 +Swift 3 compatible version is available on `swift3` branch. No pod available yet, though. Encountering issue with code sign and xcode 8 during validating podspec. Will try to solve it. + # Features - [x] Pluralization support - Without using *stringdict* files - [x] Length variations support - Supported since iOS 8.0 (instead of iOS 9.0 like system does) and avoids using *stringsdict* files From bfe96d3cd0ead7901bbabf89e7336d53627ae51e Mon Sep 17 00:00:00 2001 From: Peyman Khanjan Date: Wed, 13 Sep 2017 14:23:03 +0100 Subject: [PATCH 2/6] Version 1.3.3 (Swift 3 Support) --- Swifternalization/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swifternalization/Info.plist b/Swifternalization/Info.plist index 0bf3342..7c9982c 100644 --- a/Swifternalization/Info.plist +++ b/Swifternalization/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.3.2 + 1.3.3 CFBundleSignature ???? CFBundleVersion From 82ce23c18962056176255d73d645f6789293d98a Mon Sep 17 00:00:00 2001 From: Peyman Khanjan Date: Wed, 13 Sep 2017 14:29:09 +0100 Subject: [PATCH 3/6] Swift 4 Compatibility. --- Swifternalization.xcodeproj/project.pbxproj | 30 ++++++++++++++----- .../xcschemes/Swifternalization.xcscheme | 4 ++- .../xcschemes/SwifternalizationTests.xcscheme | 4 ++- Swifternalization/Regex.swift | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Swifternalization.xcodeproj/project.pbxproj b/Swifternalization.xcodeproj/project.pbxproj index a51545e..d437dfb 100644 --- a/Swifternalization.xcodeproj/project.pbxproj +++ b/Swifternalization.xcodeproj/project.pbxproj @@ -383,19 +383,19 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Tomasz Szulc"; TargetAttributes = { 6D5004471B3EF91600A54B36 = { CreatedOnToolsVersion = 6.3.2; DevelopmentTeamName = "Snupps Limited"; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 6D5004521B3EF91600A54B36 = { CreatedOnToolsVersion = 6.3.2; DevelopmentTeam = NPGLBT5EYF; DevelopmentTeamName = "Snupps Limited"; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -552,14 +552,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -604,14 +610,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -659,7 +671,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -683,7 +696,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -702,7 +716,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.tomaszszulc.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -718,7 +733,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.tomaszszulc.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Swifternalization.xcodeproj/xcshareddata/xcschemes/Swifternalization.xcscheme b/Swifternalization.xcodeproj/xcshareddata/xcschemes/Swifternalization.xcscheme index b74237c..6824ccc 100644 --- a/Swifternalization.xcodeproj/xcshareddata/xcschemes/Swifternalization.xcscheme +++ b/Swifternalization.xcodeproj/xcshareddata/xcschemes/Swifternalization.xcscheme @@ -1,6 +1,6 @@ capturingGroupIdx { - resultString = self.substring(str, range: result.rangeAt(capturingGroupIdx)) + resultString = self.substring(str, range: result.range(at: capturingGroupIdx)) } else { resultString = self.substring(str, range: result.range) } From 63ad2b936f91d43ed5b84db704c241afa7ff7c44 Mon Sep 17 00:00:00 2001 From: Tomasz Szulc Date: Fri, 15 Sep 2017 10:31:08 +0200 Subject: [PATCH 4/6] Support Swift 4 --- Swifternalization.podspec | 4 ++-- Swifternalization/Info.plist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Swifternalization.podspec b/Swifternalization.podspec index 43604a4..ef5ee93 100644 --- a/Swifternalization.podspec +++ b/Swifternalization.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Swifternalization" - s.version = "1.3.2" + s.version = "1.4.0" s.summary = "Swift Framework which helps in localizing apps using JSON files." s.homepage = "https://github.com/tomkowz/Swifternalization" @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.platform = :ios, '8.0' - s.source = { :git => "https://github.com/tomkowz/Swifternalization.git", :tag => "v1.3.2" } + s.source = { :git => "https://github.com/tomkowz/Swifternalization.git", :tag => "v1.4.0" } s.source_files = 'Classes', 'Swifternalization/**/*.{swift,h}' s.requires_arc = true diff --git a/Swifternalization/Info.plist b/Swifternalization/Info.plist index 7c9982c..fc63f14 100644 --- a/Swifternalization/Info.plist +++ b/Swifternalization/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.3.3 + 1.4.0 CFBundleSignature ???? CFBundleVersion From 593015a4341cf8c831c95585cf41e9103bc97cdc Mon Sep 17 00:00:00 2001 From: Tomasz Szulc Date: Fri, 15 Sep 2017 10:38:01 +0200 Subject: [PATCH 5/6] Add .swift-version file --- .swift-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0 From 4a08d3d84f984e448aa72c92ede44716f8727667 Mon Sep 17 00:00:00 2001 From: Paul Rolfe Date: Mon, 13 Mar 2017 11:12:17 -0400 Subject: [PATCH 6/6] So we can support the language if it exists. --- Swifternalization/JSONFileLoader.swift | 2 +- Swifternalization/Swifternalization.swift | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Swifternalization/JSONFileLoader.swift b/Swifternalization/JSONFileLoader.swift index b419ae2..3ad7fac 100644 --- a/Swifternalization/JSONFileLoader.swift +++ b/Swifternalization/JSONFileLoader.swift @@ -40,7 +40,7 @@ final class JSONFileLoader { :param: bundle A bundle when file is located. :returns: JSON or nil if file cannot be loaded. */ - private class func load(_ fileName: String, bundle: Bundle) -> JSONDictionary? { + class func load(_ fileName: String, bundle: Bundle) -> JSONDictionary? { if let fileURL = bundle.url(forResource: fileName, withExtension: "json") { return load(fileURL) } diff --git a/Swifternalization/Swifternalization.swift b/Swifternalization/Swifternalization.swift index 32d3678..377843b 100644 --- a/Swifternalization/Swifternalization.swift +++ b/Swifternalization/Swifternalization.swift @@ -191,7 +191,16 @@ final public class Swifternalization { Get preferred language of user's device. */ private func getPreferredLanguage(_ bundle: Bundle) -> CountryCode { - // Get preferred language, the one which is set on user's device - return bundle.preferredLocalizations.first! as CountryCode + // Get preferred language, the one which is set on user's device and that we have a file for + let all = bundle.preferredLocalizations + let first = all.first! as CountryCode + var supported: CountryCode? + for lang in all { + if let _ = JSONFileLoader.load(lang, bundle: bundle) { + supported = lang + break + } + } + return supported ?? first } }