-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe1ffb9
commit 203b315
Showing
14 changed files
with
309 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.2.0" | ||
s.version = "2.3.0" | ||
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" => "[email protected]" } | ||
s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.2.0" } | ||
s.source = { :git => "https://github.com/andresilvagomez/Localize.git", :tag => "2.3.0" } | ||
|
||
s.ios.deployment_target = '9.0' | ||
s.source_files = "Source/*.swift" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Pluralize.swift | ||
// Localize | ||
// | ||
// Copyright © 2019 @andresilvagomez. | ||
// | ||
|
||
import Foundation | ||
|
||
fileprivate extension Int { | ||
/// Get plural string value for Int value. | ||
var plural: String { | ||
switch self { | ||
case 0: | ||
return "zero" | ||
case 1: | ||
return "one" | ||
case 2: | ||
return "two" | ||
case 3...99: | ||
return "many" | ||
case 100...999: | ||
return "hundreds" | ||
case 1_000...999_999: | ||
return "thousand" | ||
case 1_000_000...999_999_999: | ||
return "millions" | ||
default: | ||
return "other" | ||
} | ||
} | ||
} | ||
|
||
/// Pluralize is a class focused in reduce your app logic for localized values | ||
/// you can pluralize | ||
public class Pluralize { | ||
|
||
/// Pluralize strings with numeric value | ||
/// get localized and pluralized key acording with the rules | ||
/// and value. | ||
/// | ||
/// - parameter String: The value could you pluralize | ||
/// | ||
/// - returns: Localized and Pluralized key according with the value. | ||
static func pluralize(key: String, value: Int, tableName: String? = nil) -> String { | ||
let key = "\(key).\(value.plural)" | ||
|
||
return key.localize(value: "\(value)", tableName: tableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// PluralizeJsonTest.swift | ||
// LocalizeTests | ||
// | ||
// Copyright © 2019 @andresilvagomez. | ||
// | ||
|
||
import XCTest | ||
import Localize | ||
|
||
class PluralizeJsonTest: XCTestCase { | ||
override func setUp() { | ||
super.setUp() | ||
Localize.update(provider: .json) | ||
Localize.update(bundle: Bundle(for: type(of: self))) | ||
Localize.update(language: "en") | ||
} | ||
|
||
func testPluralize() { | ||
XCTAssertEqual("people".pluralize(value: 0), "there are no people") | ||
XCTAssertEqual("people".pluralize(value: 1), "only one person") | ||
XCTAssertEqual("people".pluralize(value: 2), "two people") | ||
XCTAssertEqual("people".pluralize(value: 27), "many people") | ||
XCTAssertEqual("people".pluralize(value: 103), "hundreds of people") | ||
XCTAssertEqual("people".pluralize(value: 1010), "thousand of people") | ||
XCTAssertEqual("people".pluralize(value: 1000000), "millions of people") | ||
XCTAssertEqual("people".pluralize(value: -1), "not defined people") | ||
} | ||
|
||
func testPluralizeTable() { | ||
XCTAssertEqual("other.people".pluralize(value: 0, tableName: "other"), "there are no people") | ||
XCTAssertEqual("other.people".pluralize(value: 1, tableName: "other"), "only one person") | ||
XCTAssertEqual("other.people".pluralize(value: 2, tableName: "other"), "two people") | ||
XCTAssertEqual("other.people".pluralize(value: 27, tableName: "other"), "many people") | ||
XCTAssertEqual("other.people".pluralize(value: 103, tableName: "other"), "hundreds of people") | ||
XCTAssertEqual("other.people".pluralize(value: 1010, tableName: "other"), "thousand of people") | ||
XCTAssertEqual("other.people".pluralize(value: 1000000, tableName: "other"), "millions of people") | ||
XCTAssertEqual("other.people".pluralize(value: -1, tableName: "other"), "not defined people") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// PluralizeStringsTest.swift | ||
// LocalizeTests | ||
// | ||
// Created by Andres Silva Gomez on 4/30/19. | ||
// Copyright © 2019 Kekiiwaa. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import Localize | ||
|
||
class PluralizeStringsTest: XCTestCase { | ||
override func setUp() { | ||
super.setUp() | ||
Localize.update(provider: .strings) | ||
Localize.update(bundle: Bundle(for: type(of: self))) | ||
Localize.update(language: "en") | ||
Localize.update(fileName: "Strings") | ||
} | ||
|
||
func testPluralize() { | ||
XCTAssertEqual("people".pluralize(value: 0), "there are no people") | ||
XCTAssertEqual("people".pluralize(value: 1), "only one person") | ||
XCTAssertEqual("people".pluralize(value: 2), "two people") | ||
XCTAssertEqual("people".pluralize(value: 27), "many people") | ||
XCTAssertEqual("people".pluralize(value: 103), "hundreds of people") | ||
XCTAssertEqual("people".pluralize(value: 1010), "thousand of people") | ||
XCTAssertEqual("people".pluralize(value: 1000000), "millions of people") | ||
XCTAssertEqual("people".pluralize(value: -1), "not defined people") | ||
} | ||
|
||
func testPluralizeTable() { | ||
XCTAssertEqual("other.people".pluralize(value: 0, tableName: "Other"), "there are no people") | ||
XCTAssertEqual("other.people".pluralize(value: 1, tableName: "Other"), "only one person") | ||
XCTAssertEqual("other.people".pluralize(value: 2, tableName: "Other"), "two people") | ||
XCTAssertEqual("other.people".pluralize(value: 27, tableName: "Other"), "many people") | ||
XCTAssertEqual("other.people".pluralize(value: 103, tableName: "Other"), "hundreds of people") | ||
XCTAssertEqual("other.people".pluralize(value: 1010, tableName: "Other"), "thousand of people") | ||
XCTAssertEqual("other.people".pluralize(value: 1000000, tableName: "Other"), "millions of people") | ||
XCTAssertEqual("other.people".pluralize(value: -1, tableName: "Other"), "not defined people") | ||
} | ||
} |
Oops, something went wrong.