Skip to content

Commit

Permalink
Merge pull request #5 from nextbike/fix/localization-starts-with-key
Browse files Browse the repository at this point in the history
Fix: Localization starts with placeholder
  • Loading branch information
meierjan authored Dec 10, 2020
2 parents bccef50 + bd15da8 commit d6b85b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion PhraseSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Pod::Spec.new do |s|
s.name = 'PhraseSwift'
s.version = '0.1.1'
s.version = '0.1.2'
s.summary = 'A swift port of Squares Phrase library.'

# This description is used to generate tags and improve search results.
Expand Down
2 changes: 1 addition & 1 deletion PhraseSwift/PhraseSwift/Phrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class Phrase {

// Copy the original pattern to preserve all spans, such as bold, italic, etc.
let sb = NSMutableAttributedString(string: pattern)
while let t = head?.next {
while let t = head {
t.expand(target: sb, data: keysToValue)
head = head!.next
}
Expand Down
26 changes: 26 additions & 0 deletions PhraseSwift/PhraseSwiftTests/PhraseSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ class PhraseSwiftTests: XCTestCase {
XCTAssert(secondOutput == "Hi, Hope you {second} it")
}

func testStartsWithKeyLocalization() {
let firstOutput = Phrase(pattern: "{key} is awesome!")
.put(key: "key", value: "PhraseSwift")
.format()
XCTAssert(firstOutput == "PhraseSwift is awesome!")

let secondOutput = Phrase(pattern: "{one} is better than {two}.")
.put(key: "one", value: "Two")
.put(key: "two", value: "one")
.format()
XCTAssert(secondOutput == "Two is better than one.")
}

func testEndsWithKeyLocalization() {
let firstOutput = Phrase(pattern: "PhraseSwift is {stupid}")
.put(key: "stupid", value: "awesome")
.format()
XCTAssert(firstOutput == "PhraseSwift is awesome")

let secondOutput = Phrase(pattern: "{one} is better than {two}")
.put(key: "one", value: "Two")
.put(key: "two", value: "one")
.format()
XCTAssert(secondOutput == "Two is better than one")
}

func testSpacedKeyLocalization() {
let firstOutput = Phrase(pattern: "Hi, this is a {key one} test with {key two} keys.")
.put(key: "key two", value: "multiple")
Expand Down

0 comments on commit d6b85b8

Please sign in to comment.