Skip to content

Commit

Permalink
v2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilvagomez committed Sep 27, 2018
1 parent 4211ec2 commit 8cd1669
Show file tree
Hide file tree
Showing 33 changed files with 562 additions and 488 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ script:
- xcodebuild -version
- xcodebuild -showsdks

# Build Framework
- xcodebuild -workspace "$WORKSPACE" -scheme "Localize" -sdk "$SDK" -destination "$DESTINATION"

# Build Framework in Debug and Run Tests if specified
- if [ $RUN_TESTS == "YES" ]; then
xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty;
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
`Localize` adheres to [Semantic Versioning](http://semver.org/).

## [2.0.5](https://github.com/andresilvagomez/Localize/releases/tag/2.0.5)
- Swift 4.2 Support.
- By [Gustavo Graña](https://github.com/ggrana) in Pull Request [#36](https://github.com/andresilvagomez/Localize/pull/36).
Released on 2018-09-26.

## [2.0.4](https://github.com/andresilvagomez/Localize/releases/tag/2.0.4)
- Swift 4.2 Support.
- By [Daniel Clelland](https://github.com/dclelland) in Pull Request [#34](https://github.com/andresilvagomez/Localize/pull/34).
Expand Down
27 changes: 13 additions & 14 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)
-> Bool {

let localize = Localize.shared
// Set your localize provider.
localize.update(provider: .json)
Expand All @@ -30,38 +33,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print(localize.currentLanguage)
// List of aviable languajes
print(localize.availableLanguages)

// Or you can use static methods for all

Localize.update(fileName: "lang")
Localize.update(defaultLanguage: "fr")
Localize.update(language: "en-DE")

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

}

26 changes: 18 additions & 8 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@ class ViewController: UIViewController {
}

@IBAction func updateLanguage(_ sender: Any) {
let actionSheet = UIAlertController(title: nil, message: "app.update.language".localize(), preferredStyle: UIAlertControllerStyle.actionSheet)
let actionSheet = UIAlertController(
title: nil,
message: "app.update.language".localize(),
preferredStyle: UIAlertControllerStyle.actionSheet
)

for language in Localize.availableLanguages {
let displayName = Localize.displayNameForLanguage(language)
let languageAction = UIAlertAction(title: displayName, style: .default, handler: {
(alert: UIAlertAction!) -> Void in
Localize.update(language: language)
let languageAction = UIAlertAction(
title: displayName,
style: .default,
handler: { (_: UIAlertAction!) -> Void in

Localize.update(language: language)
})
actionSheet.addAction(languageAction)
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: {
(alert: UIAlertAction) -> Void in
})
let cancelAction = UIAlertAction(
title: "Cancel",
style: UIAlertActionStyle.cancel,
handler: nil
)

actionSheet.addAction(cancelAction)
self.present(actionSheet, animated: true, completion: nil)
}

}

4 changes: 2 additions & 2 deletions Localize.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|

s.name = "Localize"
s.version = "2.0.4"
s.version = "2.0.5"
s.license = 'MIT'
s.summary = "Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings."
s.homepage = "https://github.com/andresilvagomez/Localize"
s.author = { "Andres Silva" => "andresilvagomez@gmail.com" }
s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.0.4" }
s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.0.5" }

s.ios.deployment_target = '9.0'
s.source_files = "Source/*.swift"
Expand Down
22 changes: 22 additions & 0 deletions Localize.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
69F1B5701D955990000A2B87 /* Frameworks */,
69F1B5711D955990000A2B87 /* Headers */,
69F1B5721D955990000A2B87 /* Resources */,
9F80E5EE215C502D0048E0A6 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -340,6 +341,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
9F80E5EE215C502D0048E0A6 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
69F1B56F1D955990000A2B87 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import PackageDescription

let package = Package(
name: "Localize",
dependencies : [],
dependencies: [],
exclude: ["Tests"]
)
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
pod 'Localize' , '~> 2.0.4'
pod 'Localize' , '~> 2.0.5'
end
```

Expand Down
74 changes: 42 additions & 32 deletions Source/Localize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
// Copyright © 2017 @andresilvagomez.
//

import UIKit
import Foundation

/// Name for language change notification
public let LocalizeChangeNotification = "LocalizeChangeNotification"
public let localizeChangeNotification = "LocalizeChangeNotification"

/// Internal current language key
public let LocalizeStorageKey = "LocalizeDefaultLanguage"

public let localizeStorageKey = "LocalizeDefaultLanguage"

/// Different types to localize your app, using json files or strings default by Apple.
public enum LocalizeType {
Expand All @@ -25,31 +24,31 @@ public enum LocalizeType {
/// Is a pricipal class, contents all logic to localize your keys
/// read json and determinate all configurations.
public class Localize: NSObject {

// MARK: Properties

/// Shated instance
public static let shared: Localize = Localize()

/// Provider to localize your app.
private var provider: LocalizeProtocol = LocalizeStrings()

/// Show all aviable languajes whit criteria name
///
/// - returns: list with storaged languages code
public var availableLanguages: [String] {
return provider.availableLanguages
}

/// Return storaged language or default language in device
///
/// - returns: current used language
public var currentLanguage: String {
return provider.currentLanguage
}

// MARK: Public methods

/// Localize a string using your JSON File
/// If the key is not found return the same key
/// That prevent replace untagged values
Expand All @@ -58,51 +57,62 @@ public class Localize: NSObject {
public func localize(key: String, tableName: String? = nil) -> String {
return provider.localize(key: key, tableName: tableName)
}

/// Localize a string using your JSON File
/// That replace all % character in your string with replace value.
///
/// - parameter value: The replacement value
///
/// - returns: localized key or same text
public func localize(key: String, replace: String, tableName: String? = nil) -> String {
public func localize(
key: String,
replace: String,
tableName: String? = nil) -> String {

return provider.localize(key: key, replace: replace, tableName: tableName)
}

/// Localize a string using your JSON File
/// That replace each % character in your string with each replace value.
///
/// - parameter value: The replacement values
///
/// - returns: localized key or same text
public func localize(key: String, values: [Any], tableName: String? = nil) -> String {
public func localize(
key: String,
values: [Any],
tableName: String? = nil) -> String {

return provider.localize(key: key, values: values, tableName: tableName)
}

/// Localize string with dictionary values
/// Get properties in your key with rule :property
/// If property not exist in this string, not is used.
///
/// - parameter value: The replacement dictionary
///
/// - returns: localized key or same text
public func localize(key: String, dictionary: [String:String], tableName: String? = nil) -> String {
public func localize(
key: String,
dictionary: [String: String],
tableName: String? = nil) -> String {

return provider.localize(key: key, dictionary: dictionary, tableName: tableName)
}


// MARK: Config methods

/// Update default language, this stores a language key which can be retrieved the next time
public func update(language: String) -> Void {
public func update(language: String) {
provider.update(language: language)
}

/// Update base file name, searched in path.
public func update(fileName:String) {
public func update(fileName: String) {
provider.update(fileName: fileName)
}

/// Update the bundle used to load files from.
public func update(bundle: Bundle) {
provider.update(bundle: bundle)
Expand All @@ -112,28 +122,28 @@ public class Localize: NSObject {
public func update(defaultLanguage: String) {
provider.update(defaultLanguage: defaultLanguage)
}

/// This remove the language key storaged.
public func resetLanguage() -> Void {
public func resetLanguage() {
provider.resetLanguage()
}

/// Display name for current user language.
///
/// - return: String form language code in current user language
public func displayNameForLanguage(_ language: String) -> String {
return provider.displayNameForLanguage(language)
}

// MARK: Config providers

/// Update provider to localize your app.
public func update(provider: LocalizeType) {
if provider == .strings {
self.provider = LocalizeStrings()
}
if provider == .json {
switch provider {
case .json:
self.provider = LocalizeJson()
case .strings:
self.provider = LocalizeStrings()
}
}
}
Loading

0 comments on commit 8cd1669

Please sign in to comment.