-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Antondomashnev/master
Add russian support
- Loading branch information
Showing
6 changed files
with
184 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// SharedRussianExpression.swift | ||
// Swifternalization | ||
// | ||
// Created by Anton Domashnev on 8/24/15. | ||
// Copyright (c) 2015 Tomasz Szulc. All rights reserved. | ||
// | ||
|
||
/** | ||
Contains Russian expressions. | ||
*/ | ||
class SharedRussianExpression: SharedExpressionProtocol { | ||
|
||
/** | ||
Return expressions that are valid in Poland. | ||
*/ | ||
static func allExpressions() -> [SharedExpression] { | ||
return [ | ||
/** | ||
1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, … | ||
|
||
v = 0 and | ||
i % 10 = 1 and | ||
i % 100 != 11 | ||
|
||
e.g. | ||
- из 1 книги за 1 день | ||
*/ | ||
SharedExpression(identifier: "one", pattern: "exp:(^1$)|(^[^1]1$)|(^[1-9][0-9]?[0,2,3,4,5,6,7,8,9]+1$)"), | ||
|
||
/** | ||
2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, … | ||
|
||
v = 0 and | ||
i % 10 = 2..4 and | ||
i % 100 != 12..14 | ||
|
||
e.g. | ||
- из 2 книг за 2 дня | ||
*/ | ||
SharedExpression(identifier: "few", pattern: "exp:(^[2-4]$)|(^[2-9][2-4]$)|([1-9]+[0-9]*[^1][2-4]$)"), | ||
|
||
/** | ||
0, 5~20, 100, 1000, 10000, 100000, 1000000, … | ||
|
||
v = 0 and | ||
i % 10 = 0 or | ||
v = 0 and | ||
i % 10 = 5..9 or | ||
v = 0 and | ||
i % 100 = 11..14 | ||
|
||
e.g. | ||
- из 5 книг за 5 дней | ||
*/ | ||
SharedExpression(identifier: "many", pattern: "exp:(^[05-9]$)|(^1[1-4]$)|(^[1-9]+[0-9]*[5-9]$)|(^[1-9]+[0-9]*1{1}[1-4]$)|([1-9]+[0-9]*0$)"), | ||
] | ||
} | ||
} |
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,67 @@ | ||
// | ||
// SharedRussianExpressionTests.swift | ||
// Swifternalization | ||
// | ||
// Created by Anton Domashnev on 8/24/15. | ||
// Copyright (c) 2015 Tomasz Szulc. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
class SharedRussianExpressionTests: XCTestCase { | ||
|
||
func testOne() { | ||
let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "one"}).first! | ||
let expression = Expression(pattern: sharedExp.pattern, value: "") | ||
|
||
XCTAssertTrue(expression.validate("1"), "Should match 1") | ||
XCTAssertTrue(expression.validate("21"), "Should match 21") | ||
XCTAssertTrue(expression.validate("101"), "Should match 151") | ||
XCTAssertTrue(expression.validate("451"), "Should match 451") | ||
XCTAssertTrue(expression.validate("1441"), "Should match 1441") | ||
XCTAssertTrue(expression.validate("3441"), "Should match 3441") | ||
|
||
XCTAssertFalse(expression.validate("11"), "Should not match 11") | ||
XCTAssertFalse(expression.validate("25"), "Should not match 25") | ||
XCTAssertFalse(expression.validate("111"), "Should not match 111") | ||
XCTAssertFalse(expression.validate("1211"), "Should not match 1211") | ||
} | ||
|
||
func testFew() { | ||
let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "few"}).first! | ||
let expression = Expression(pattern: sharedExp.pattern, value: "") | ||
|
||
XCTAssertTrue(expression.validate("2"), "Should match 2") | ||
XCTAssertTrue(expression.validate("23"), "Should match 23") | ||
XCTAssertTrue(expression.validate("564"), "Should match 564") | ||
XCTAssertTrue(expression.validate("1873"), "Should match 1873") | ||
|
||
XCTAssertFalse(expression.validate("5"), "Should not match 5") | ||
XCTAssertFalse(expression.validate("12"), "Should not match 12") | ||
XCTAssertFalse(expression.validate("18"), "Should not match 18") | ||
XCTAssertFalse(expression.validate("39"), "Should not match 39") | ||
XCTAssertFalse(expression.validate("1413"), "Should not match 1413") | ||
XCTAssertFalse(expression.validate("41511"), "Should not match 41511") | ||
} | ||
|
||
func testMany() { | ||
let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "many"}).first! | ||
let expression = Expression(pattern: sharedExp.pattern, value: "") | ||
|
||
XCTAssertTrue(expression.validate("0"), "Should match 0") | ||
XCTAssertTrue(expression.validate("6"), "Should match 6") | ||
XCTAssertTrue(expression.validate("10"), "Should match 10") | ||
XCTAssertTrue(expression.validate("18"), "Should match 18") | ||
XCTAssertTrue(expression.validate("1009"), "Should match 1009") | ||
XCTAssertTrue(expression.validate("2011"), "Should match 2011") | ||
XCTAssertTrue(expression.validate("8314"), "Should match 8314") | ||
|
||
XCTAssertFalse(expression.validate("22"), "Should not match 22") | ||
XCTAssertFalse(expression.validate("24"), "Should not match 24") | ||
XCTAssertFalse(expression.validate("153"), "Should not match 153") | ||
XCTAssertFalse(expression.validate("454"), "Should not match 454") | ||
XCTAssertFalse(expression.validate("1443"), "Should not match 1443") | ||
XCTAssertFalse(expression.validate("3443"), "Should not match 3443") | ||
} | ||
} |
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,32 @@ | ||
{ | ||
"welcome": "добро пожаловать", | ||
|
||
"cars": { | ||
"one": "%d машина", | ||
"few": "%d машины", | ||
"more": "%d машин" | ||
}, | ||
|
||
"forgot-password": { | ||
"@100": "Забыли пароль? Помощь.", | ||
"@200": "Забыли пароль? Используйте справку.", | ||
}, | ||
|
||
"car-sentence": { | ||
"one": { | ||
"@100": "одна машина", | ||
"@200": "только одна машина", | ||
"@300": "у вас есть только одна машина" | ||
}, | ||
|
||
"few": { | ||
"@100": "%d машиы", | ||
"@300": "у вас есть %d машины" | ||
} | ||
|
||
"more": { | ||
"@100": "%d машин", | ||
"@300": "у вас есть %d машин" | ||
} | ||
} | ||
} |