Skip to content

Commit

Permalink
Merge pull request #64 from hyperoslo/feature/localizable-string-args
Browse files Browse the repository at this point in the history
Implement localized string with arguments
  • Loading branch information
zenangst committed Apr 1, 2016
2 parents c5920b0 + baab438 commit d686e0d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ And `.Custom()` for your own dispatch queues.

```swift
let string = localizedString("My Profile")
let formattedString = localizedString(key: "%d numbers", arguments: 10)
```

Swift access (pun intended) to `NSLocalizedString`, you will get more valid auto completion
Expand Down
6 changes: 6 additions & 0 deletions Source/Shared/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ public func localizedString(key: String, _ bundleClass: AnyClass? = nil, comment
return NSLocalizedString(key, bundle: NSBundle.mainBundle(), comment: (comment != nil) ? comment! : key)
}
}

public func localizedString(key: String, _ bundleClass: AnyClass? = nil, comment: String? = nil, arguments: CVarArgType...) -> String {
return withVaList(arguments) {
NSString(format: localizedString(key, bundleClass, comment: comment), locale: NSLocale.currentLocale(), arguments: $0)
} as String
}

0 comments on commit d686e0d

Please sign in to comment.