Skip to content

Commit 58eba13

Browse files
author
zeng.wenbin
committed
Update Swift4.2
0 parents  commit 58eba13

35 files changed

Lines changed: 2275 additions & 0 deletions

.gitignore

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## Build generated
6+
build/
7+
DerivedData/
8+
WBLanguageDemo/Slack
9+
10+
## Various settings
11+
*.pbxuser
12+
!default.pbxuser
13+
*.mode1v3
14+
!default.mode1v3
15+
*.mode2v3
16+
!default.mode2v3
17+
*.perspectivev3
18+
!default.perspectivev3
19+
xcuserdata/
20+
21+
## Other
22+
*.moved-aside
23+
*.xccheckout
24+
*.xcscmblueprint
25+
*.DS_Store
26+
27+
## Obj-C/Swift specific
28+
*.hmap
29+
*.ipa
30+
*.dSYM.zip
31+
*.dSYM
32+
33+
## Playgrounds
34+
timeline.xctimeline
35+
playground.xcworkspace
36+
37+
# Swift Package Manager
38+
#
39+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
40+
# Packages/
41+
# Package.pins
42+
.build/
43+
44+
# CocoaPods
45+
#
46+
# We recommend against adding the Pods directory to your .gitignore. However
47+
# you should judge for yourself, the pros and cons are mentioned at:
48+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
49+
#
50+
Pods/
51+
52+
# Carthage
53+
#
54+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
55+
# Carthage/Checkouts
56+
57+
Carthage/Build
58+
59+
# fastlane
60+
#
61+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
62+
# screenshots whenever they are needed.
63+
# For more information about the recommended setup visit:
64+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
65+
66+
fastlane/report.xml
67+
fastlane/Preview.html
68+
fastlane/screenshots
69+
fastlane/test_output

.swift-version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
4.0
2+

.travis.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
language: swift
2+
osx_image: xcode9.1
3+
cache: bundler
4+
5+
env:
6+
global:
7+
- LC_CTYPE=en_US.UTF-8
8+
- LANG=en_US.UTF-8
9+
10+
before_install:
11+
- env
12+
- locale
13+
- brew update
14+
- brew upgrade carthage || true
15+
- carthage version
16+
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
17+
- xcpretty --version
18+
- xcodebuild -version
19+
- xcodebuild -showsdks
20+
21+
script:
22+
- set -o pipefail
23+
24+
- echo Check if the library described by the podspec can be built
25+
- carthage bootstrap
26+
27+
- echo Build as static library
28+
- xcodebuild clean build -project WBLanguage.xcodeproj -scheme 'WBLanguage iOS' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
29+
30+
- echo Build as dynamic framework
31+
- xcodebuild clean build -project WBLanguage.xcodeproj -scheme 'WBLanguage iOS' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
32+
33+
- echo Build the Demo apps
34+
- xcodebuild clean build -project WBLanguage.xcodeproj -scheme 'WBLanguage' -configuration Debug -destination 'name=iPhone 7' | xcpretty -c
35+
36+
after_success:
37+
- bash <(curl -s https://codecov.io/bash)

Cartfile

Whitespace-only changes.

Cartfile.resolved

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 zwb
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
WBLanguage
2+
==========
3+
4+
[![Build Status](https://api.travis-ci.org/JsonBin/WBLanguage.svg?branch=master)](https://travis-ci.org/JsonBin/WBLanguage)
5+
![Pod version](https://img.shields.io/cocoapods/v/WBLanguage.svg?style=flat)
6+
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
7+
[![Platform info](https://img.shields.io/cocoapods/p/WBLanguage.svg?style=flat)](http://cocoadocs.org/docsets/WBLanguage)
8+
9+
![gif](https://github.com/JsonBin/WBLanguage/blob/master/demo.gif "demogif")
10+
11+
## What
12+
13+
WBLanguage is a high level LanguageKit. It provides a High Level API set international language for your app.
14+
15+
## Features
16+
17+
* Less time to switch the language
18+
* Set the language more convenient
19+
* Supported languages: English/French/Italian/German/Russian/Chinese-Hans/Chinese-Hant
20+
* Subsequent can add more national languages
21+
22+
## Installation
23+
WBLanguage supports multiple methods for installing the library in a project.
24+
25+
## CocoaPods
26+
27+
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like WBAlamofire in your projects. You can install it with the following command:
28+
29+
```bash
30+
$ gem install cocoapods
31+
```
32+
33+
> CocoaPods 1.2.0+ is required to build WBLanguage.
34+
35+
#### Podfile
36+
37+
To integrate WBLanguage into your Xcode project using CocoaPods, specify it in your `Podfile`:
38+
39+
```ruby
40+
source 'https://github.com/CocoaPods/Specs.git'
41+
platform :ios, '8.0'
42+
43+
target 'TargetName' do
44+
use_frameworks!
45+
46+
pod 'WBLanguage'
47+
48+
end
49+
```
50+
51+
Then, run the following command:
52+
53+
```bash
54+
$ pod install
55+
```
56+
57+
## Carthage
58+
59+
60+
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
61+
62+
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
63+
64+
```bash
65+
$ brew update
66+
$ brew install carthage
67+
```
68+
69+
To integrate WBLanguage into your Xcode project using Carthage, specify it in your `Cartfile`:
70+
71+
```ogdl
72+
github "JsonBin/WBLanguage"
73+
```
74+
75+
Run `carthage` to build the framework and drag the built `WBLanguage.framework` into your Xcode project.
76+
77+
## Requirements
78+
79+
- iOS 8+
80+
- Xcode 9.0+
81+
- Swift 4.0+
82+
83+
| WBLanguage Version | Minimum iOS Target | Note |
84+
|:------------------:|:-------------------:|:-----|
85+
| 1.x | iOS 8 | Xcode 9+ is required. |
86+
87+
you must create a 'Language.bundle' resources in your project to hold the international language.
88+
89+
## Usage
90+
91+
### WBLanguageManager class
92+
93+
We can set WBLanguageManager's property at the beggining of app launching, the sample is below:
94+
95+
```swift
96+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
97+
WBLanguageManager.duration = 2.0
98+
return true
99+
}
100+
```
101+
102+
if you want to set a new language, you can use `setLanguage(_:)` to update the UI. And it will automatically save the language of your choice.
103+
104+
```swift
105+
WBLanguageManager.setLanguage(type)
106+
```
107+
108+
you can use `textForKey(_:, value:)` to get the local text from *.lproj.
109+
110+
```swift
111+
let string = WBLanguageManager.textForKey("key")
112+
```
113+
114+
### WBLanguage class
115+
116+
WBLanguage supports serializing and deserializing any custom type as long as it conforms to the `WBLanguageProtocol` protocol.
117+
118+
```swift
119+
public extension WBLanguageProtocol {
120+
public var lt: WBLanguage<Self> {
121+
return WBLanguage(self)
122+
}
123+
}
124+
125+
extension `yourCustom` : WBLanguageProtocol {}
126+
```
127+
Note: `WBLanguageProtocol` is a protocol that WBLanguage uses internally to directly. So you need to complete the language setting.
128+
129+
For example:
130+
131+
```swift
132+
133+
private func setLanguagePicker(
134+
_ object: NSObject,
135+
Selector selector: String,
136+
Picker picker: WBLanguagePicker?
137+
) {
138+
object.languagePickers[selector] = picker
139+
object.performLanguage(selector, Picker: picker)
140+
}
141+
142+
public extension WBLanguage where T : UILabel {
143+
public func setPicker(_ picker: WBLanguageTextPicker?) {
144+
setLanguagePicker(value, Selector: "setText:", Picker: picker)
145+
}
146+
public func setAttributedPicker(_ picker: WBLanguageDictionaryPicker?) {
147+
setLanguagePicker(value, Selector: "setAttributedText:", Picker: picker)
148+
}
149+
public var picker: WBLanguageTextPicker? {
150+
set{ setLanguagePicker(value, Selector: "setText:", Picker: newValue) }
151+
get{ return getLanguagePicker(value, Selector: "setText:") as? WBLanguageTextPicker }
152+
}
153+
public var attributedPicker: WBLanguageDictionaryPicker? {
154+
set{ setLanguagePicker(value, Selector: "setAttributedText:", Picker: newValue) }
155+
get{ return getLanguagePicker(value, Selector: "setAttributedText:") as? WBLanguageDictionaryPicker }
156+
}
157+
}
158+
```
159+
160+
## UIKit
161+
162+
### UILabel
163+
164+
```swift
165+
let label = UILabel()
166+
label.lt.picker = "Label"
167+
```
168+
`UILabel` can use `*.lt.picker` or `*.lt.setPicker(_:)` to load text.
169+
170+
Of course, if you want to add attributes to the font, you can use `WBLanguageDictionaryPicker` or `WBLanguageManager.textForKey("key")`
171+
172+
to take out the text first and then add attributes.
173+
174+
use `WBLanguageDictionaryPicker`:
175+
176+
```swift
177+
label.lt.attributedPicker = WBLanguageDictionaryPicker(dicts: ["picker": "Label", NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17)])
178+
```
179+
another:
180+
181+
```swift
182+
if let text = WBLanguageManager.textForKey("Label") {
183+
let att = NSAttributedString(string: text, attributes: [.font: UIFont.boldSystemFont(ofSize: 17), .foregroundColor: UIColor.black])
184+
label.attributedText = att
185+
}
186+
```
187+
188+
### UITextField
189+
190+
The use of the `UITextField` and `UILabel` is same, just more placeholder:
191+
192+
```swift
193+
let textfield = UITextField()
194+
textfield.lt.placeHolderPicker = "Label"
195+
```
196+
197+
attribute picker:
198+
199+
```swift
200+
textfield.lt.attributedPlaceHolderPicker = WBLanguageDictionaryPicker(dicts: ["picker": "Label", NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17)])
201+
```
202+
203+
### UIButton
204+
205+
```swift
206+
let button = UIButton(type: .system)
207+
button.lt.setPicker("Button", forState: .normal)
208+
```
209+
210+
attribute text:
211+
212+
```swift
213+
let picker = WBLanguageDictionaryPicker(dicts: ["picker": "Button", NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17), NSAttributedStringKey.strikethroughStyle:NSUnderlineStyle.styleDouble.rawValue])
214+
button.lt.setAttributedPicker(picker, forState: .normal)
215+
```
216+
217+
### UISegmentedControl
218+
219+
```swift
220+
let segment = UISegmentedControl(items: ["","","","",""])
221+
segment.lt.setPicker("English", forSegmentAt: 0)
222+
segment.lt.setPicker("Russian", forSegmentAt: 1)
223+
segment.lt.setPicker("French", forSegmentAt: 2)
224+
segment.lt.setPicker("Italian", forSegmentAt: 3)
225+
segment.lt.setPicker("German", forSegmentAt: 4)
226+
```
227+
`UISegmentedControl` just has one method to set text picker.
228+
229+
## License
230+
231+
WBLanguage is available under the [MIT License](https://raw.github.com/rs/SDWebImage/master/LICENSE). See the LICENSE file for more info.

Source/Support Files/Info.plist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.2.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>$(CURRENT_PROJECT_VERSION)</string>
23+
<key>NSPrincipalClass</key>
24+
<string></string>
25+
</dict>
26+
</plist>

0 commit comments

Comments
 (0)