Skip to content

Commit

Permalink
Merge pull request #11 from Antondomashnev/master
Browse files Browse the repository at this point in the history
Add russian support
  • Loading branch information
tomkowz committed Aug 24, 2015
2 parents 06c9f69 + 5845e16 commit b203c03
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Swifternalization.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
6D19ABDD1B6D23730063FE1E /* SharedBaseExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */; };
6D19ABDE1B6D23730063FE1E /* SharedPolishExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */; };
6D19ABDF1B6D23730063FE1E /* SharedPolishExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */; };
6D43BA181B8BA8460072DEA6 /* SharedRussianExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */; };
6D43BA1A1B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */; };
6D43BA1B1B8BADB50072DEA6 /* SharedRussianExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */; };
6D43BA1D1B8BBA270072DEA6 /* ru.json in Resources */ = {isa = PBXBuildFile; fileRef = 6D43BA1C1B8BBA270072DEA6 /* ru.json */; };
6D477E701B6D258F001F1904 /* SharedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D477E6F1B6D258F001F1904 /* SharedExpression.swift */; };
6D477E711B6D258F001F1904 /* SharedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D477E6F1B6D258F001F1904 /* SharedExpression.swift */; };
6D4C4EAF1B6AA48F00B7839A /* LoadedTranslation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EAE1B6AA48F00B7839A /* LoadedTranslation.swift */; };
Expand Down Expand Up @@ -103,6 +107,9 @@
6D140F431B56D03D00359143 /* RandomNumbers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomNumbers.swift; sourceTree = "<group>"; };
6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedBaseExpression.swift; path = Swifternalization/SharedBaseExpression.swift; sourceTree = SOURCE_ROOT; };
6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedPolishExpression.swift; path = Swifternalization/SharedPolishExpression.swift; sourceTree = SOURCE_ROOT; };
6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedRussianExpression.swift; path = Swifternalization/SharedRussianExpression.swift; sourceTree = SOURCE_ROOT; };
6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharedRussianExpressionTests.swift; sourceTree = "<group>"; };
6D43BA1C1B8BBA270072DEA6 /* ru.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ru.json; sourceTree = "<group>"; };
6D477E6F1B6D258F001F1904 /* SharedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedExpression.swift; path = Swifternalization/SharedExpression.swift; sourceTree = SOURCE_ROOT; };
6D4C4EAE1B6AA48F00B7839A /* LoadedTranslation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslation.swift; sourceTree = "<group>"; };
6D4C4EB21B6AAE3200B7839A /* LoadedTranslationsProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslationsProcessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -247,6 +254,7 @@
6DD3B9431B5ED55500C79EAC /* SharedExpressionsLoaderTests.swift */,
6D5BA6031B6537D5000D7E49 /* SharedExpressionsProcessorTests.swift */,
6DBB6C971B4077FA002F39A3 /* SharedPolishExpressionTests.swift */,
6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */,
6D50045A1B3EF91600A54B36 /* SwifternalizationTests.swift */,
6D5BA5EF1B651796000D7E49 /* TranslationsLoaderTests.swift */,
6D6282931B3F052B00E65FCD /* TranslatablePairTests.swift */,
Expand Down Expand Up @@ -289,13 +297,15 @@
6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */,
6D477E6F1B6D258F001F1904 /* SharedExpression.swift */,
6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */,
6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */,
);
path = "Shared Expressions";
sourceTree = "<group>";
};
6DD3B93D1B5ED35600C79EAC /* Localizable Files */ = {
isa = PBXGroup;
children = (
6D43BA1C1B8BBA270072DEA6 /* ru.json */,
6DD3B9381B5ED35200C79EAC /* expressions.json */,
6DD3B9371B5ED35200C79EAC /* base.json */,
6DD3B9391B5ED35200C79EAC /* pl.json */,
Expand Down Expand Up @@ -421,6 +431,7 @@
6DD3B93A1B5ED35200C79EAC /* base.json in Resources */,
6D5004961B3EFFC100A54B36 /* Info.plist in Resources */,
6DD3B93C1B5ED35200C79EAC /* pl.json in Resources */,
6D43BA1D1B8BBA270072DEA6 /* ru.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -435,6 +446,7 @@
6D6282A31B3F247000E65FCD /* ExpressionMatcher.swift in Sources */,
6D5004661B3EF92600A54B36 /* Swifternalization.swift in Sources */,
6D62829A1B3F17CA00E65FCD /* Regex.swift in Sources */,
6D43BA181B8BA8460072DEA6 /* SharedRussianExpression.swift in Sources */,
6D6282B51B3F3C4100E65FCD /* InequalitySign.swift in Sources */,
6D4C4EBD1B6ABE0700B7839A /* Translation.swift in Sources */,
6DB3CC901B5EC29600A1220F /* ExpressionPatternType.swift in Sources */,
Expand Down Expand Up @@ -465,6 +477,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6D43BA1B1B8BADB50072DEA6 /* SharedRussianExpression.swift in Sources */,
6D6282C91B3F4F6700E65FCD /* RegexExpressionParser.swift in Sources */,
6DBB6C981B4077FA002F39A3 /* SharedPolishExpressionTests.swift in Sources */,
6DD3B9441B5ED55500C79EAC /* SharedExpressionsLoaderTests.swift in Sources */,
Expand Down Expand Up @@ -493,6 +506,7 @@
6DBB6C521B401B8A002F39A3 /* Swifternalization.swift in Sources */,
6D5BA5F01B651796000D7E49 /* TranslationsLoaderTests.swift in Sources */,
6D4C4EC41B6ACF2C00B7839A /* Translation.swift in Sources */,
6D43BA1A1B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift in Sources */,
6D6282BF1B3F42CA00E65FCD /* InequalityExpressionMatcherTests.swift in Sources */,
6D5BA6041B6537D5000D7E49 /* SharedExpressionsProcessorTests.swift in Sources */,
6D6282B31B3F3C2800E65FCD /* InequalityExtendedExpressionParser.swift in Sources */,
Expand Down
59 changes: 59 additions & 0 deletions Swifternalization/SharedRussianExpression.swift
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$)"),
]
}
}
4 changes: 4 additions & 0 deletions SwifternalizationTests/JSONFileLoaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class JSONFileLoaderTests: XCTestCase {
XCTAssertFalse(loadExpressions("pl").isEmpty, "")
}

func testShouldLoadRUExpressions() {
XCTAssertFalse(loadExpressions("ru").isEmpty, "")
}

func testShouldNotLoadDEExpressions() {
XCTAssertTrue(loadExpressions("de").isEmpty, "")
}
Expand Down
67 changes: 67 additions & 0 deletions SwifternalizationTests/SharedRussianExpressionTests.swift
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")
}
}
8 changes: 8 additions & 0 deletions SwifternalizationTests/expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
"few": "exp:(((?!1).[2-4]{1})$)|(^[2-4]$)",
"two": "ie:x=2",
"three": "ie:x=3"
},

"ru": {
"one": "exp:(^1$)|(^[^1]1$)|(^[1-9][0-9]?[0,2,3,4,5,6,7,8,9]+1$)",
"few": "exp:(^[2-4]$)|(^[2-9][2-4]$)|([1-9]+[0-9]*[^1][2-4]$)",
"many": "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$)",
"two": "ie:x=2",
"three": "ie:x=3"
}
}
32 changes: 32 additions & 0 deletions SwifternalizationTests/ru.json
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 машин"
}
}
}

0 comments on commit b203c03

Please sign in to comment.