Skip to content

Commit

Permalink
Merge branch 'swift3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
marmelroy committed Sep 18, 2016
2 parents cdb0180 + 170db30 commit 274d7bd
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 59 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
osx_image: xcode7.3
osx_image: xcode8
language: objective-c
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
before_install:
- brew update || brew update
- brew outdated xctool || brew upgrade xctool
- gem install cocoapods
- brew update
- gem install cocoapods --pre
- xcrun simctl list
install: echo "<3"
env:
Expand All @@ -19,3 +18,4 @@ script: ./build.sh $MODE
branches:
only:
- master
- swift3.0
19 changes: 18 additions & 1 deletion Localize_Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = {
3433F2351C518AF7003AE34D = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
3433F23F1C518AF7003AE34D = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -404,8 +406,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -452,8 +456,10 @@
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_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -473,6 +479,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -484,6 +491,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand All @@ -497,13 +505,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
3433F24C1C518AF7003AE34D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand All @@ -515,6 +525,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-Swift";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -525,6 +536,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-SwiftTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -535,6 +547,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-SwiftTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -582,6 +595,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand All @@ -603,6 +617,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand All @@ -622,6 +637,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand All @@ -643,6 +659,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Localize_SwiftTests/Localize_SwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Localize_SwiftTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}
Expand Down
54 changes: 28 additions & 26 deletions Sources/Localize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Swift 1.x friendly localization syntax, replaces NSLocalizedString
- Parameter string: Key to be localized.
- Returns: The localized string.
*/
public func Localized(string: String) -> String {
public func Localized(_ string: String) -> String {
return string.localized()
}

Expand All @@ -36,7 +36,7 @@ public func Localized(string: String) -> String {
- Parameter string: Key to be localized.
- Returns: The formatted localized string with arguments.
*/
public func Localized(string: String, arguments: CVarArgType...) -> String {
public func Localized(_ string: String, arguments: CVarArg...) -> String {
return String(format: string.localized(), arguments: arguments)
}

Expand All @@ -48,7 +48,7 @@ public func Localized(string: String, arguments: CVarArgType...) -> String {

- returns: Pluralized localized string.
*/
public func LocalizedPlural(string: String, argument: CVarArgType) -> String {
public func LocalizedPlural(_ string: String, argument: CVarArg) -> String {
return string.localizedPlural(argument)
}

Expand All @@ -59,11 +59,13 @@ public extension String {
- 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)
if let path = Bundle.main.path(forResource: Localize.currentLanguage(), ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: nil)
}
else if let path = NSBundle.mainBundle().pathForResource(LCLBaseBundle, ofType: "lproj"), bundle = NSBundle(path: path) {
return bundle.localizedStringForKey(self, value: nil, table: nil)
else if let path = Bundle.main.path(forResource: LCLBaseBundle, ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: nil)
}
return self
}
Expand All @@ -72,7 +74,7 @@ public extension String {
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString)
- Returns: The formatted localized string with arguments.
*/
func localizedFormat(arguments: CVarArgType...) -> String {
func localizedFormat(_ arguments: CVarArg...) -> String {
return String(format: localized(), arguments: arguments)
}

Expand All @@ -83,26 +85,26 @@ public extension String {

- returns: Pluralized localized string.
*/
func localizedPlural(argument: CVarArgType) -> String {
return NSString.localizedStringWithFormat(localized(), argument) as String
func localizedPlural(_ argument: CVarArg) -> String {
return NSString.localizedStringWithFormat(localized() as NSString, argument) as String
}
}



// MARK: Language Setting Functions

public class Localize: NSObject {
open class Localize: NSObject {

/**
List available languages
- Returns: Array of available languages.
*/
public class func availableLanguages(excludeBase: Bool = false) -> [String] {
var availableLanguages = NSBundle.mainBundle().localizations
open class func availableLanguages(_ excludeBase: Bool = false) -> [String] {
var availableLanguages = Bundle.main.localizations
// If excludeBase = true, don't include "Base" in available languages
if let indexOfBase = availableLanguages.indexOf("Base") where excludeBase == true {
availableLanguages.removeAtIndex(indexOfBase)
if let indexOfBase = availableLanguages.index(of: "Base") , excludeBase == true {
availableLanguages.remove(at: indexOfBase)
}
return availableLanguages
}
Expand All @@ -111,8 +113,8 @@ public class Localize: NSObject {
Current language
- Returns: The current language. String.
*/
public class func currentLanguage() -> String {
if let currentLanguage = NSUserDefaults.standardUserDefaults().objectForKey(LCLCurrentLanguageKey) as? String {
open class func currentLanguage() -> String {
if let currentLanguage = UserDefaults.standard.object(forKey: LCLCurrentLanguageKey) as? String {
return currentLanguage
}
return defaultLanguage()
Expand All @@ -122,22 +124,22 @@ public class Localize: NSObject {
Change the current language
- Parameter language: Desired language.
*/
public class func setCurrentLanguage(language: String) {
open class func setCurrentLanguage(_ language: String) {
let selectedLanguage = availableLanguages().contains(language) ? language : defaultLanguage()
if (selectedLanguage != currentLanguage()){
NSUserDefaults.standardUserDefaults().setObject(selectedLanguage, forKey: LCLCurrentLanguageKey)
NSUserDefaults.standardUserDefaults().synchronize()
NSNotificationCenter.defaultCenter().postNotificationName(LCLLanguageChangeNotification, object: nil)
UserDefaults.standard.set(selectedLanguage, forKey: LCLCurrentLanguageKey)
UserDefaults.standard.synchronize()
NotificationCenter.default.post(name: Notification.Name(rawValue: LCLLanguageChangeNotification), object: nil)
}
}

/**
Default language
- Returns: The app's default language. String.
*/
public class func defaultLanguage() -> String {
open class func defaultLanguage() -> String {
var defaultLanguage: String = String()
guard let preferredLanguage = NSBundle.mainBundle().preferredLocalizations.first else {
guard let preferredLanguage = Bundle.main.preferredLocalizations.first else {
return LCLDefaultLanguage
}
let availableLanguages: [String] = self.availableLanguages()
Expand All @@ -153,7 +155,7 @@ public class Localize: NSObject {
/**
Resets the current language to the default
*/
public class func resetCurrentLanguageToDefault() {
open class func resetCurrentLanguageToDefault() {
setCurrentLanguage(self.defaultLanguage())
}

Expand All @@ -162,9 +164,9 @@ public class Localize: NSObject {
- Parameter language: Desired language.
- Returns: The localized string.
*/
public class func displayNameForLanguage(language: String) -> String {
open class func displayNameForLanguage(_ language: String) -> String {
let locale : NSLocale = NSLocale(localeIdentifier: currentLanguage())
if let displayName = locale.displayNameForKey(NSLocaleLanguageCode, value: language) {
if let displayName = (locale as NSLocale).displayName(forKey: NSLocale.Key.languageCode, value: language) {
return displayName
}
return String()
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# **** Update me when new Xcode versions are released! ****
PLATFORM="platform=iOS Simulator,OS=9.3,name=iPhone 6s"
PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 6s"
SDK="iphonesimulator"


Expand Down
Loading

0 comments on commit 274d7bd

Please sign in to comment.