Skip to content

Instantly share code, notes, and snippets.

@wookay
Created February 5, 2016 06:41
Show Gist options
  • Save wookay/8762075000583304ee83 to your computer and use it in GitHub Desktop.
Save wookay/8762075000583304ee83 to your computer and use it in GitHub Desktop.
import Foundation
class TestTranslate: WTestCase {
func test_locales() {
let en = NSLocale(localeIdentifier: "en_US")
Assert.equal("just now", en.translate("just now"))
let ko = NSLocale(localeIdentifier: "ko_KR")
Assert.equal("방금", ko.translate("just now"))
Assert.equal("1시간 전", ko.translate("%d hours ago", n: 1))
}
func test_dates() {
Assert.equal("ko", NSLocale.currentLocale().languageCode)
let d1 = NSDate(type: .today, hour: 1, min: 0, sec: 0)
Assert.equal("just now".translate, d1.since(d1))
Assert.equal("방금", d1.since(d1))
let d2 = NSDate(type: .today, hour: 1, min: 5, sec: 0)
Assert.equal("%d mins ago".translate(5), d2.since(d1))
let d3 = NSDate(type: .today, hour: 2, min: 5, sec: 0)
Assert.equal("%d hours ago".translate(1), d3.since(d1))
let d4 = NSDate(type: .yesterday, hour: 1, min: 0, sec: 0)
Assert.equal("어제", d1.since(d4))
let d5 = NSDate(type: .tomorrow, hour: 1, min: 0, sec: 0)
Assert.equal("어제", d5.since(d1))
Assert.equal("미래", d1.since(d5))
}
}
@wookay
Copy link
Author

wookay commented Feb 5, 2016

screen shot 2016-02-05 at 3 41 56 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment