Skip to content

Commit 051fb9f

Browse files
authored
StringExtensions // Add all available parameters to String.localized(). (#1217)
1 parent 4429f00 commit 051fb9f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ The changelog for **SwifterSwift**. Also see the [releases](https://github.com/S
44

55
## Upcoming Release
66
### Added
7+
78
### Changed
9+
- **String**
10+
- `localized(comment:)` now supports all parameters provided by `NSLocalizedString(tableName:bundle:value:comment:)`. [#1217](https://github.com/SwifterSwift/SwifterSwift/pull/1217) by [Shiki Suen](https://github.com/ShikiSuen)
11+
812
### Fixed
13+
14+
### Deprecated
15+
916
### Removed
1017

1118
## [v7.0.0](https://github.com/SwifterSwift/SwifterSwift/releases/tag/7.0.0)

Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,22 @@ public extension String {
520520
///
521521
/// "Hello world".localized() -> Hallo Welt
522522
///
523-
/// - Parameter comment: Optional comment for translators.
524-
/// - Returns: Localized string.
525-
func localized(comment: String = "") -> String {
526-
return NSLocalizedString(self, comment: comment)
523+
/// - Parameters:
524+
/// - tableName: The name of the table containing the key-value pairs. Also, the suffix for the strings file (a
525+
/// file with the.strings extension) to store the localized string. This defaults to the table in
526+
/// `Localizable.strings` when tableName is nil or an empty string.
527+
/// - bundle: The bundle containing the table’s strings file. The main bundle is used if one isn’t specified.
528+
/// - value: The localized string for the development locale. For other locales, return this value if key isn’t
529+
/// found in the table.
530+
/// - comment: The comment to place above the key-value pair in the strings file. This parameter provides
531+
/// the translator with some context about the localized string’s presentation to the user.
532+
/// - Returns: Localized string. Please refer to the Xcode documentation of `NSLocalizedString()` API for details.
533+
func localized(
534+
tableName: String? = nil,
535+
bundle: Bundle = Bundle.main,
536+
value: String = "",
537+
comment: String = "") -> String {
538+
return NSLocalizedString(self, tableName: tableName, bundle: bundle, value: value, comment: comment)
527539
}
528540
#endif
529541

0 commit comments

Comments
 (0)