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 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 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.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 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.3.2 + 1.4.0 CFBundleSignature ???? CFBundleVersion 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/Regex.swift b/Swifternalization/Regex.swift index 150e957..12a5048 100644 --- a/Swifternalization/Regex.swift +++ b/Swifternalization/Regex.swift @@ -27,7 +27,7 @@ final class Regex { regexp(pattern)?.enumerateMatches(in: str, options: NSRegularExpression.MatchingOptions.reportCompletion, range: range, using: { result, flags, stop in if let result = result { if let capturingGroupIdx = capturingGroupIdx, result.numberOfRanges > 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) } 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 } }