From 5d4534098d75797fdf19142808ecfe58c9778c68 Mon Sep 17 00:00:00 2001 From: Roman Shevtsov Date: Tue, 3 Nov 2015 14:50:20 +0100 Subject: [PATCH 01/11] Much type-safer swift .localize implementation. Does not crash if string is not localized. --- Localize/Localize.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Localize/Localize.swift b/Localize/Localize.swift index 556e1a8..685a8e9 100644 --- a/Localize/Localize.swift +++ b/Localize/Localize.swift @@ -17,19 +17,19 @@ public let LCLLanguageChangeNotification : String = "LCLLanguageChangeNotificati // Swift 1.x friendly localization syntax, replaces NSLocalizedString public func Localized(string: String) -> String { - let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj") - let bundle = NSBundle(path: path!) - let string = bundle?.localizedStringForKey(string, value: nil, table: nil) - return string! + if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { + return bundle.localizedStringForKey(string, value: nil, table: nil) + } + return string } // Swift 2 friendly localization syntax, replaces NSLocalizedString public extension String { func localized() -> String { - let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj") - let bundle = NSBundle(path: path!) - let string = bundle?.localizedStringForKey(self, value: nil, table: nil) - return string! + if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { + return bundle.localizedStringForKey(self, value: nil, table: nil) + } + return self } } From e6718027e5e5d859f07711f57a48132eaa187bd3 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Tue, 3 Nov 2015 15:08:38 +0100 Subject: [PATCH 02/11] Travis bug fix and release 0.5 --- .travis.yml | 4 ++-- Localize-Swift.podspec | 2 +- Localize.xcodeproj/project.pbxproj | 8 ++++---- Localize/Info.plist | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e277061..ada4ab3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ env: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 before_install: - - brew update; - - brew reinstall xctool + - brew update || brew update + - brew outdated xctool || brew upgrade xctool - gem install cocoapods - xcrun simctl list install: echo "<3" diff --git a/Localize-Swift.podspec b/Localize-Swift.podspec index f85a884..5db1729 100644 --- a/Localize-Swift.podspec +++ b/Localize-Swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Localize-Swift" - s.version = "0.4" + s.version = "0.5" s.summary = "Swift-friendly localization and i18n with in-app language switching." s.description = "Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app language switching." s.homepage = "https://github.com/marmelroy/Localize-Swift" diff --git a/Localize.xcodeproj/project.pbxproj b/Localize.xcodeproj/project.pbxproj index 1796288..bbbd39b 100644 --- a/Localize.xcodeproj/project.pbxproj +++ b/Localize.xcodeproj/project.pbxproj @@ -162,7 +162,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -210,7 +210,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -238,7 +238,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4; + DYLIB_CURRENT_VERSION = 5; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -257,7 +257,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4; + DYLIB_CURRENT_VERSION = 5; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Localize/Info.plist b/Localize/Info.plist index 7df2112..f02db55 100644 --- a/Localize/Info.plist +++ b/Localize/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.4 + 0.5 CFBundleSignature ???? CFBundleVersion - 4 + 5 NSPrincipalClass From 9b6e5efca64ab13d80870077a0c478249acacf79 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Tue, 3 Nov 2015 15:17:54 +0100 Subject: [PATCH 03/11] Podspec update --- Localize-Swift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Localize-Swift.podspec b/Localize-Swift.podspec index 5db1729..d81967b 100644 --- a/Localize-Swift.podspec +++ b/Localize-Swift.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.license = "MIT" s.author = { "Roy Marmelstein" => "hello@roysapps.com" } s.social_media_url = "http://twitter.com/marmelroy" - s.source = { :git => "https://github.com/marmelroy/Localize-Swift.git", :tag => "0.4" } + s.source = { :git => "https://github.com/marmelroy/Localize-Swift.git", :tag => "0.5" } s.source_files = "Localize" s.platform = :ios s.ios.deployment_target = "8.0" From f6aae16ed646a6203a86936ab8ad74ef6eb71eca Mon Sep 17 00:00:00 2001 From: James Hartt Date: Wed, 11 Nov 2015 20:00:24 +0000 Subject: [PATCH 04/11] Spelling issue --- Localize/Localize.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Localize/Localize.swift b/Localize/Localize.swift index 685a8e9..76e67f6 100644 --- a/Localize/Localize.swift +++ b/Localize/Localize.swift @@ -87,7 +87,7 @@ public class Localize: NSObject { } // Resets the current language to the default - public class func resetCurrentLanaguageToDefault() { + public class func resetCurrentLanguageToDefault() { setCurrentLanguage(self.defaultLanguage()) } From 2ea29073c777e5f3d673e84bec193803861478aa Mon Sep 17 00:00:00 2001 From: James Hartt Date: Wed, 11 Nov 2015 20:02:10 +0000 Subject: [PATCH 05/11] Spelling mistake in readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 547c6c4..e1dd54c 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ NSNotificationCenter.defaultCenter().addObserver(self, selector: "setText", name To reset back to the default app language: ``` -Localize.resetCurrentLanaguageToDefault() +Localize.resetCurrentLanguageToDefault() ``` ## genstrings From 5356f7ab9172afd58e7706b7ececa70c0b2c286e Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 11 Nov 2015 22:09:36 +0100 Subject: [PATCH 06/11] Fixing broken test --- examples/LanguageSwitch/Sample/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/LanguageSwitch/Sample/ViewController.swift b/examples/LanguageSwitch/Sample/ViewController.swift index a9a28d1..9db4879 100644 --- a/examples/LanguageSwitch/Sample/ViewController.swift +++ b/examples/LanguageSwitch/Sample/ViewController.swift @@ -66,7 +66,7 @@ class ViewController: UIViewController { } @IBAction func doResetLanguage(sender: AnyObject) { - Localize.resetCurrentLanaguageToDefault() + Localize.resetCurrentLanguageToDefault() } } From b9656a6d890e1dfbf6de8f883491ec9a89eed7e3 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 11 Nov 2015 22:16:29 +0100 Subject: [PATCH 07/11] Adding a changelog --- CHANGELOG.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..73be287 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,50 @@ +# Change Log + +## [Unreleased](https://github.com/marmelroy/Localize-Swift/tree/HEAD) + +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.5...HEAD) + +**Merged pull requests:** + +- Spellings [\#10](https://github.com/marmelroy/Localize-Swift/pull/10) ([jameshartt](https://github.com/jameshartt)) + +## [0.5](https://github.com/marmelroy/Localize-Swift/tree/0.5) (2015-11-03) +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.4...0.5) + +**Merged pull requests:** + +- Much type-safer swift .localize implementation [\#9](https://github.com/marmelroy/Localize-Swift/pull/9) ([rshev](https://github.com/rshev)) + +## [0.4](https://github.com/marmelroy/Localize-Swift/tree/0.4) (2015-10-10) +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.3...0.4) + +**Closed issues:** + +- Can not get localized string in swift files using genstrings.py [\#8](https://github.com/marmelroy/Localize-Swift/issues/8) +- Suggestion: Change the Localized\(\) method name to localized\(\) to match style best practices [\#7](https://github.com/marmelroy/Localize-Swift/issues/7) + +## [0.3](https://github.com/marmelroy/Localize-Swift/tree/0.3) (2015-09-28) +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.2...0.3) + +## [0.2](https://github.com/marmelroy/Localize-Swift/tree/0.2) (2015-09-26) +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.1...0.2) + +**Closed issues:** + +- Swift 2.0 Compatibility [\#6](https://github.com/marmelroy/Localize-Swift/issues/6) +- Add unit tests [\#5](https://github.com/marmelroy/Localize-Swift/issues/5) +- Add support for plurals with .stringsdict [\#4](https://github.com/marmelroy/Localize-Swift/issues/4) + +## [0.1](https://github.com/marmelroy/Localize-Swift/tree/0.1) (2015-08-06) +[Full Changelog](https://github.com/marmelroy/Localize-Swift/compare/0.0.1...0.1) + +**Closed issues:** + +- Create Localize-Swift genstrings equivalent [\#3](https://github.com/marmelroy/Localize-Swift/issues/3) +- Add example code [\#2](https://github.com/marmelroy/Localize-Swift/issues/2) +- Add notification on language change [\#1](https://github.com/marmelroy/Localize-Swift/issues/1) + +## [0.0.1](https://github.com/marmelroy/Localize-Swift/tree/0.0.1) (2015-08-05) + + +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 6dbda18b409af73ee47d51f2827f0b8c76a0d784 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 11 Nov 2015 22:17:34 +0100 Subject: [PATCH 08/11] Fixing broken test --- examples/LanguageSwitch/SampleTests/SampleTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/LanguageSwitch/SampleTests/SampleTests.swift b/examples/LanguageSwitch/SampleTests/SampleTests.swift index 136c9c6..d437ebf 100644 --- a/examples/LanguageSwitch/SampleTests/SampleTests.swift +++ b/examples/LanguageSwitch/SampleTests/SampleTests.swift @@ -13,7 +13,7 @@ class SampleTests: XCTestCase { override func setUp() { super.setUp() - Localize.resetCurrentLanaguageToDefault() + Localize.resetCurrentLanguageToDefault() } func testSwift1Syntax() { @@ -36,7 +36,7 @@ class SampleTests: XCTestCase { XCTAssertEqual(testString.localized(), "Hola mundo") Localize.setCurrentLanguage("de") XCTAssertEqual(testString.localized(), "Hallo Welt") - Localize.resetCurrentLanaguageToDefault() + Localize.resetCurrentLanguageToDefault() XCTAssertEqual(testString.localized(), "Hello world") } From 622a136da199c96fce94e76baf569e80641a528e Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Fri, 13 Nov 2015 07:00:43 +0100 Subject: [PATCH 09/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1dd54c..b438aca 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ To integrate Localize-Swift into your Xcode project using Carthage, specify it i github "marmelroy/Localize-Swift" ``` -### Setting up with [CocoaPods](http://cocoapods.org/?q=libPhoneNumber-iOS) +### Setting up with [CocoaPods](http://cocoapods.org/?q=Localize-Swift) ``` source 'https://github.com/CocoaPods/Specs.git' pod 'Localize-Swift', '~> 0.2' From 2683e146d29d0a765a576da64c65b0f6b8e9e98d Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Fri, 13 Nov 2015 15:49:15 +0000 Subject: [PATCH 10/11] Improve documentation --- Localize/Localize.swift | 45 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/Localize/Localize.swift b/Localize/Localize.swift index 76e67f6..b957880 100644 --- a/Localize/Localize.swift +++ b/Localize/Localize.swift @@ -8,14 +8,22 @@ import Foundation +/// Internal current language key let LCLCurrentLanguageKey : String = "LCLCurrentLanguageKey" + +/// Default language. English. If English is unavailable defaults to base localization. let LCLDefaultLanguage : String = "en" +/// Name for language change notification public let LCLLanguageChangeNotification : String = "LCLLanguageChangeNotification" // MARK: Localization Syntax -// Swift 1.x friendly localization syntax, replaces NSLocalizedString +/** +Swift 1.x friendly localization syntax, replaces NSLocalizedString +- Parameter string: Key to be localized. +- Returns: The localized string. +*/ public func Localized(string: String) -> String { if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { return bundle.localizedStringForKey(string, value: nil, table: nil) @@ -23,8 +31,11 @@ public func Localized(string: String) -> String { return string } -// Swift 2 friendly localization syntax, replaces NSLocalizedString public extension String { + /** + Swift 2 friendly localization syntax, replaces NSLocalizedString + - Returns: The localized string. + */ func localized() -> String { if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { return bundle.localizedStringForKey(self, value: nil, table: nil) @@ -38,12 +49,18 @@ public extension String { public class Localize: NSObject { - // Returns a list of available localizations + /** + List available languages + - Returns: Array of available languages. + */ public class func availableLanguages() -> [String] { return NSBundle.mainBundle().localizations } - // Returns the current language + /** + Current language + - Returns: The current language. String. + */ public class func currentLanguage() -> String { var currentLanguage : String = String() if ((NSUserDefaults.standardUserDefaults().objectForKey(LCLCurrentLanguageKey)) != nil){ @@ -55,7 +72,10 @@ public class Localize: NSObject { return currentLanguage } - // Change the current language + /** + Change the current language + - Parameter language: Desired language. + */ public class func setCurrentLanguage(language: String) { var selectedLanguage: String = String() let availableLanguages : [String] = self.availableLanguages() @@ -72,7 +92,10 @@ public class Localize: NSObject { } } - // Returns the app's default language + /** + Default language + - Returns: The app's default language. String. + */ class func defaultLanguage() -> String { var defaultLanguage : String = String() let preferredLanguage = NSBundle.mainBundle().preferredLocalizations.first! @@ -86,12 +109,18 @@ public class Localize: NSObject { return defaultLanguage } - // Resets the current language to the default + /** + Resets the current language to the default + */ public class func resetCurrentLanguageToDefault() { setCurrentLanguage(self.defaultLanguage()) } - // Returns the app's full display name in the current language + /** + Get the current language's display name for a language. + - Parameter language: Desired language. + - Returns: The localized string. + */ public class func displayNameForLanguage(language: String) -> String { let currentLanguage : String = self.currentLanguage() let locale : NSLocale = NSLocale(localeIdentifier: currentLanguage) From 39d856dec2025ca0900f2bf276a81bdbffa5bef8 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Thu, 19 Nov 2015 08:18:48 +0100 Subject: [PATCH 11/11] Release 0.6 --- .gitignore | 3 ++- Localize-Swift.podspec | 4 ++-- Localize.xcodeproj/project.pbxproj | 8 ++++---- Localize/Info.plist | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 25bc5ee..3d9960b 100644 --- a/.gitignore +++ b/.gitignore @@ -71,4 +71,5 @@ examples/LanguageSwitch/Pods/Target Support Files/Pods/Pods-umbrella.h examples/LanguageSwitch/Pods/Target Support Files/Pods/Pods.debug.xcconfig examples/LanguageSwitch/Pods/Target Support Files/Pods/Pods.modulemap examples/LanguageSwitch/Pods/Target Support Files/Pods/Pods.release.xcconfig -examples/LanguageSwitch/Sample.xcworkspace/xcuserdata/marmelroy.xcuserdatad/UserInterfaceState.xcuserstate \ No newline at end of file +examples/LanguageSwitch/Sample.xcworkspace/xcuserdata/marmelroy.xcuserdatad/UserInterfaceState.xcuserstate +build diff --git a/Localize-Swift.podspec b/Localize-Swift.podspec index d81967b..8d35382 100644 --- a/Localize-Swift.podspec +++ b/Localize-Swift.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = "Localize-Swift" - s.version = "0.5" + s.version = "0.6" s.summary = "Swift-friendly localization and i18n with in-app language switching." s.description = "Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app language switching." s.homepage = "https://github.com/marmelroy/Localize-Swift" s.license = "MIT" s.author = { "Roy Marmelstein" => "hello@roysapps.com" } s.social_media_url = "http://twitter.com/marmelroy" - s.source = { :git => "https://github.com/marmelroy/Localize-Swift.git", :tag => "0.5" } + s.source = { :git => "https://github.com/marmelroy/Localize-Swift.git", :tag => "0.6" } s.source_files = "Localize" s.platform = :ios s.ios.deployment_target = "8.0" diff --git a/Localize.xcodeproj/project.pbxproj b/Localize.xcodeproj/project.pbxproj index bbbd39b..09e8207 100644 --- a/Localize.xcodeproj/project.pbxproj +++ b/Localize.xcodeproj/project.pbxproj @@ -162,7 +162,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -210,7 +210,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -238,7 +238,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 5; + DYLIB_CURRENT_VERSION = 6; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -257,7 +257,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 5; + DYLIB_CURRENT_VERSION = 6; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Localize/Info.plist b/Localize/Info.plist index f02db55..a930cf7 100644 --- a/Localize/Info.plist +++ b/Localize/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.5 + 0.6 CFBundleSignature ???? CFBundleVersion - 5 + 6 NSPrincipalClass