diff --git a/.travis.yml b/.travis.yml index 219e53b..a8ac27f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,3 @@ script: ./build.sh $MODE branches: only: - master - - swift3.0 diff --git a/Localize_Swift.xcodeproj/project.pbxproj b/Localize_Swift.xcodeproj/project.pbxproj index fd8be13..978668b 100644 --- a/Localize_Swift.xcodeproj/project.pbxproj +++ b/Localize_Swift.xcodeproj/project.pbxproj @@ -280,6 +280,9 @@ CreatedOnToolsVersion = 7.2; LastSwiftMigration = 0800; }; + 343A6DEA1D152E5A0081AA37 = { + LastSwiftMigration = 0800; + }; }; }; buildConfigurationList = 3433F2301C518AF7003AE34D /* Build configuration list for PBXProject "Localize_Swift" */; @@ -414,7 +417,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 10; + CURRENT_PROJECT_VERSION = 11; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -464,7 +467,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 10; + CURRENT_PROJECT_VERSION = 11; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -494,7 +497,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize_Swift/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -516,7 +519,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize_Swift/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -557,7 +560,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize_Swift/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -578,7 +581,7 @@ CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Localize_Swift/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -598,7 +601,7 @@ "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Localize_Swift-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -620,7 +623,7 @@ "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Localize_Swift-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -640,7 +643,7 @@ "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Localize_Swift/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -652,6 +655,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -662,7 +666,7 @@ "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 10; + DYLIB_CURRENT_VERSION = 11; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Localize_Swift/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -672,6 +676,7 @@ PRODUCT_NAME = Localize_Swift; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Localize_Swift/Info.plist b/Localize_Swift/Info.plist index 0ab82ed..d7b6b94 100644 --- a/Localize_Swift/Info.plist +++ b/Localize_Swift/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.5 + 1.6 CFBundleSignature ???? CFBundleVersion - 10 + 11 NSPrincipalClass diff --git a/Localize_SwiftTests/Info.plist b/Localize_SwiftTests/Info.plist index 19007b7..f969f37 100644 --- a/Localize_SwiftTests/Info.plist +++ b/Localize_SwiftTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.5 + 1.6 CFBundleSignature ???? CFBundleVersion - 10 + 11 diff --git a/README.md b/README.md index 1725379..5a472b3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Localize.setCurrentLanguage("fr") To update the UI in the viewcontroller where a language change can take place, observe LCLLanguageChangeNotification : ``` -NSNotificationCenter.defaultCenter().addObserver(self, selector: "setText", name: LCLLanguageChangeNotification, object: nil) +NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name( LCLLanguageChangeNotification), object: nil) ``` To reset back to the default app language: @@ -50,22 +50,17 @@ Localize.resetCurrentLanguageToDefault() ## genstrings -To support this new i18n syntax, Localize-Swift includes custom genstrings swift and python scripts. +To support this new i18n syntax, Localize-Swift includes custom genstrings swift script. -Copy the genstrings file (either .swift or .py) into your project's root folder and run with +Copy the genstrings.swift file into your project's root folder and run with ``` ./genstrings.swift ``` -or - -``` -python genstrings.py -``` This will print the collected strings in the terminal. Select and copy to your default Localizable.strings. -The swift genstrings includes the ability to specify excluded directories and files (by editing the script). +The script includes the ability to specify excluded directories and files (by editing the script). ### Setting up with Carthage @@ -87,5 +82,5 @@ github "marmelroy/Localize-Swift" ### Setting up with [CocoaPods](http://cocoapods.org/?q=Localize-Swift) ``` source 'https://github.com/CocoaPods/Specs.git' -pod 'Localize-Swift', '~> 1.5' +pod 'Localize-Swift', '~> 1.6' ``` diff --git a/build.sh b/build.sh index 76af1ea..e9d37f0 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash # **** Update me when new Xcode versions are released! **** -PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 6s" +PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 7" SDK="iphonesimulator" diff --git a/examples/LanguageSwitch/Sample/ViewController.swift b/examples/LanguageSwitch/Sample/ViewController.swift index 1fb5df9..a4fa906 100644 --- a/examples/LanguageSwitch/Sample/ViewController.swift +++ b/examples/LanguageSwitch/Sample/ViewController.swift @@ -29,7 +29,7 @@ class ViewController: UIViewController { // Add an observer for LCLLanguageChangeNotification on viewWillAppear. This is posted whenever a language changes and allows the viewcontroller to make the necessary UI updated. Very useful for places in your app when a language change might happen. override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(rawValue: LCLLanguageChangeNotification), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name( LCLLanguageChangeNotification), object: nil) } // Remove the LCLLanguageChangeNotification on viewWillDisappear diff --git a/genstrings.py b/genstrings.py deleted file mode 100644 index 3083aa5..0000000 --- a/genstrings.py +++ /dev/null @@ -1,147 +0,0 @@ -# Created by Johannes Schriewer on 2011-11-30. Modified by Roy Marmelstein 2015-08-05 -# Copyright (c) 2011 planetmutlu. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER -# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# This script is heavily copied from: https://github.com/dunkelstern/Cocoa-Localisation-Helper - -import os, re, subprocess -import fnmatch - -def fetch_files_recursive(directory, extension): - matches = [] - for root, dirnames, filenames in os.walk(directory): - for filename in fnmatch.filter(filenames, '*' + extension): - matches.append(os.path.join(root, filename)) - return matches - - -# prepare regexes -localizedStringComment = re.compile('NSLocalizedString\("([^"]*)",\s*"([^"]*)"\s*\)', re.DOTALL) -localizedStringNil = re.compile('NSLocalizedString\("([^"]*)",\s*nil\s*\)', re.DOTALL) -localized = re.compile('Localized\("([^"]*)"[^\n\r]*\)', re.DOTALL) -localizedSwift2 = re.compile('"([^"]*)".localized\(\)', re.DOTALL) -localizedSwift2WithFormat = re.compile('"([^"]*)".localizedFormat\([^\n\r]*\)', re.DOTALL) - -# get string list -uid = 0 -strings = [] -for file in fetch_files_recursive('.', '.swift'): - with open(file, 'r') as f: - content = f.read() - for result in localizedStringComment.finditer(content): - uid += 1 - strings.append((result.group(1), result.group(2), file, uid)) - for result in localizedStringNil.finditer(content): - uid += 1 - strings.append((result.group(1), '', file, uid)) - for result in localized.finditer(content): - uid += 1 - strings.append((result.group(1), '', file, uid)) - for result in localizedSwift2.finditer(content): - uid += 1 - strings.append((result.group(1), '', file, uid)) - for result in localizedSwift2WithFormat.finditer(content): - uid += 1 - strings.append((result.group(1), '', file, uid)) - -# prepare regexes -localizedString = re.compile('"[^=]*=\s*"([^"]*)";') - -# fetch files -for file in fetch_files_recursive('.', '.xib'): - tempFile = file + '.strings' - utf8tempFile = file + '.strings.utf8' - subprocess.call('ibtool --export-strings-file "' + tempFile + '" "' + file + '" 2>/dev/null', shell=True) - subprocess.call('iconv -s -f UTF-16 -t UTF-8 "' + tempFile + '" >"'+utf8tempFile+'" 2>/dev/null', shell=True) - - f = open(utf8tempFile, 'r') - for line in f: - result = localizedString.match(line) - if result: - uid += 1 - strings.append((result.group(1), '', file, uid)) - f.close() - - os.remove(utf8tempFile) - os.remove(tempFile) - -# find duplicates -duplicated = [] -filestrings = {} -for string1 in strings: - dupmatch = 0 - for string2 in strings: - if string1[3] == string2[3]: - continue - if string1[0] == string2[0]: - if string1[2] != string2[2]: - dupmatch = 1 - break - if dupmatch == 1: - dupmatch = 0 - for string2 in duplicated: - if string1[0] == string2[0]: - dupmatch = 1 - break - if dupmatch == 0: - duplicated.append(string1) - else: - dupmatch = 0 - if string1[2] in filestrings: - for fs in filestrings[string1[2]]: - if fs[0] == string1[0]: - dupmatch = 1 - break - else: - filestrings[string1[2]] = [] - if dupmatch == 0: - filestrings[string1[2]].append(string1) - -print '\n\n\n\n\n' -print '/*\n * SHARED STRINGS\n */\n' - -# output filewise -for key in filestrings.keys(): - print '/*\n * ' + key + '\n */\n' - - strings = filestrings[key] - for string in strings: - if string[1] == '': - print '"' + string[0] + '" = "' + string[0] + '";' - print - else: - print '/* ' + string[1] + ' */' - print '"' + string[0] + '" = "' + string[0] + '";' - print - -# output duplicates -for string in duplicated: - if string[1] == '': - print '"' + string[0] + '" = "' + string[0] + '";' - print - else: - print '/* ' + string[1] + ' */' - print '"' + string[0] + '" = "' + string[0] + '";' - print \ No newline at end of file