Skip to content

Commit

Permalink
Remove LengthVariationExpression and extend SimpleExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkowz committed Jul 31, 2015
1 parent cd2aca9 commit e00c3db
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 32 deletions.
6 changes: 0 additions & 6 deletions Swifternalization.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
6D4C4EB81B6AB6DE00B7839A /* LoadedTranslationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EB71B6AB6DE00B7839A /* LoadedTranslationType.swift */; };
6D4C4EB91B6AB6EF00B7839A /* LoadedTranslationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EB71B6AB6DE00B7839A /* LoadedTranslationType.swift */; };
6D4C4EBD1B6ABE0700B7839A /* TranslationWithExpressions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EBC1B6ABE0700B7839A /* TranslationWithExpressions.swift */; };
6D4C4EC11B6ACF2200B7839A /* LengthVariationExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EC01B6ACF2200B7839A /* LengthVariationExpression.swift */; };
6D4C4EC21B6ACF2600B7839A /* LengthVariationExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EC01B6ACF2200B7839A /* LengthVariationExpression.swift */; };
6D4C4EC41B6ACF2C00B7839A /* TranslationWithExpressions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EBC1B6ABE0700B7839A /* TranslationWithExpressions.swift */; };
6D4C4EC51B6AD01300B7839A /* LoadedTranslationsProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EB21B6AAE3200B7839A /* LoadedTranslationsProcessor.swift */; };
6D4C4EC61B6AD01D00B7839A /* SimpleExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D5BA6081B655F1D000D7E49 /* SimpleExpression.swift */; };
Expand Down Expand Up @@ -135,7 +133,6 @@
6D4C4EB41B6AB38400B7839A /* TranslationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslationType.swift; sourceTree = "<group>"; };
6D4C4EB71B6AB6DE00B7839A /* LoadedTranslationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslationType.swift; sourceTree = "<group>"; };
6D4C4EBC1B6ABE0700B7839A /* TranslationWithExpressions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslationWithExpressions.swift; sourceTree = "<group>"; };
6D4C4EC01B6ACF2200B7839A /* LengthVariationExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LengthVariationExpression.swift; sourceTree = "<group>"; };
6D5004481B3EF91600A54B36 /* Swifternalization.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swifternalization.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6D50044C1B3EF91600A54B36 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6D50044D1B3EF91600A54B36 /* Swifternalization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Swifternalization.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,7 +261,6 @@
6DB3CC731B5EBDA600A1220F /* TranslationsLoader.swift */,
6D4C4EB41B6AB38400B7839A /* TranslationType.swift */,
6D4C4EBC1B6ABE0700B7839A /* TranslationWithExpressions.swift */,
6D4C4EC01B6ACF2200B7839A /* LengthVariationExpression.swift */,
);
name = Next;
sourceTree = "<group>";
Expand Down Expand Up @@ -610,7 +606,6 @@
6DB3CC7A1B5EBDA600A1220F /* LengthVariation.swift in Sources */,
6D6464841B40146100C46C6D /* KeyValueType.swift in Sources */,
6DB3CC761B5EBDA600A1220F /* ExpressionType.swift in Sources */,
6D4C4EC11B6ACF2200B7839A /* LengthVariationExpression.swift in Sources */,
6DB3CC751B5EBDA600A1220F /* CountryCode.swift in Sources */,
6D4C4EB31B6AAE3200B7839A /* LoadedTranslationsProcessor.swift in Sources */,
6D4C4EAF1B6AA48F00B7839A /* LoadedTranslation.swift in Sources */,
Expand Down Expand Up @@ -683,7 +678,6 @@
6D6282AD1B3F327C00E65FCD /* InequalityExpressionMatcher.swift in Sources */,
6D4C4EC61B6AD01D00B7839A /* SimpleExpression.swift in Sources */,
6DD3B9491B5ED61800C79EAC /* ExpressionType.swift in Sources */,
6D4C4EC21B6ACF2600B7839A /* LengthVariationExpression.swift in Sources */,
6D62829D1B3F19CC00E65FCD /* RegexTests.swift in Sources */,
6D6282CB1B3F508C00E65FCD /* RegexExpressionParserTests.swift in Sources */,
6D6282C31B3F45A600E65FCD /* InequalityExtendedExpressionParserTests.swift in Sources */,
Expand Down
20 changes: 0 additions & 20 deletions Swifternalization/LengthVariationExpression.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Swifternalization/LoadedTranslationsProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LoadedTranslationsProcessor {
for (key, value) in $0.content as! Dictionary<String, String> {
lengthVariations.append(LengthVariation(length: self.parseNumberFromLengthVariation(key), value: value))
}
return TranslationWithExpressions(key: $0.key, expressions: [LengthVariationExpression(pattern: $0.key, variations: lengthVariations)])
return TranslationWithExpressions(key: $0.key, expressions: [SimpleExpression(pattern: $0.key, localizedValue: lengthVariations.last!.value, lengthVariations: lengthVariations)])

case .WithExpressionsAndLengthVariations:
// The most advanced translation type. It contains expressions
Expand All @@ -87,7 +87,7 @@ class LoadedTranslationsProcessor {
for (lvKey, lvValue) in value as! Dictionary<String, String> {
lengthVariations.append(LengthVariation(length: self.parseNumberFromLengthVariation(lvKey), value: lvValue))
}
expressions.append(LengthVariationExpression(pattern: pattern, variations: lengthVariations))
expressions.append(SimpleExpression(pattern: pattern, localizedValue: lengthVariations.last!.value, lengthVariations: lengthVariations))
} else if value is String {
expressions.append(SimpleExpression(pattern:pattern, localizedValue: value as! String))
}
Expand Down
15 changes: 13 additions & 2 deletions Swifternalization/SimpleExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
import Foundation

/**
Represents simple epxressions that has only pattern and localized value.
Represents simple epxressions.
*/
struct SimpleExpression: ExpressionType {
/// Pattern of expression.
let pattern: String

/// A localized value.
/// A localized value. If `lengthVariations` array is empty or you want to
/// get full localized value use this property.
let localizedValue: String

/// Array of length variations
let lengthVariations: [LengthVariation]

// Returns expression object
init(pattern: String, localizedValue: String, lengthVariations: [LengthVariation] = [LengthVariation]()) {
self.pattern = pattern
self.localizedValue = localizedValue
self.lengthVariations = lengthVariations
}
}
6 changes: 6 additions & 0 deletions Swifternalization/TranslationWithExpressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ struct TranslationWithExpressions: TranslationType {

/// Expressions that are related to a translation.
let expressions: [ExpressionType]

func validate(text: String, length: Int?) {
for expression in expressions {
// Do something
}
}
}
4 changes: 2 additions & 2 deletions SwifternalizationTests/LoadedTranslationsProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class LoadedTranslationsProcessorTests: XCTestCase {
let k2Translation = translations[1] as! TranslationWithExpressions
XCTAssertEqual(k2Translation.key, "k2", "")
XCTAssertEqual(k2Translation.expressions.count, 1, "")
let k2Expression = k2Translation.expressions[0] as! LengthVariationExpression
XCTAssertEqual(k2Expression.variations.count, 2, "")
let k2Expression = k2Translation.expressions[0] as! SimpleExpression
XCTAssertEqual(k2Expression.lengthVariations.count, 2, "")

/**
Check content of k3 translation
Expand Down

0 comments on commit e00c3db

Please sign in to comment.