Skip to content

Commit

Permalink
argument[s] parameter in .localizePlural & .localizeFormat meth…
Browse files Browse the repository at this point in the history
…ods is on the first place now.
  • Loading branch information
nekrich committed Oct 9, 2016
1 parent c8948d3 commit daaef14
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 114 deletions.
82 changes: 41 additions & 41 deletions Sources/String+LocalizeBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ import Foundation

/// bundle friendly extension
public extension String {
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString
- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- Returns: The localized string.
*/
func localized(in bundle: Bundle?) -> String {
return localized(using: nil, in: bundle)
}
/**
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString)
- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- Parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).
- Returns: The formatted localized string with arguments.
*/
func localizedFormat(in bundle: Bundle?, arguments: CVarArg...) -> String {
return String(format: localized(in: bundle), arguments: arguments)
}
/**
Swift 2 friendly plural localization syntax with a format argument
- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- parameter argument: Argument to determine pluralisation
- returns: Pluralized localized string.
*/
func localizedPlural(in bundle: Bundle?, argument: CVarArg) -> String {
return NSString.localizedStringWithFormat(localized(in: bundle) as NSString, argument) as String
}
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: The localized string.
*/
func localized(in bundle: Bundle?) -> String {
return localized(using: nil, in: bundle)
}
/**
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString).
- parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: The formatted localized string with arguments.
*/
func localizedFormat(arguments: CVarArg..., in bundle: Bundle?) -> String {
return String(format: localized(in: bundle), arguments: arguments)
}
/**
Swift 2 friendly plural localization syntax with a format argument.
- parameter argument: Argument to determine pluralisation.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: Pluralized localized string.
*/
func localizedPlural(argument: CVarArg, in bundle: Bundle?) -> String {
return NSString.localizedStringWithFormat(localized(in: bundle) as NSString, argument) as String
}
}
28 changes: 14 additions & 14 deletions Sources/String+LocalizeTableName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@ import Foundation
public extension String {

/**
Swift 2 friendly localization syntax, replaces NSLocalizedString
Swift 2 friendly localization syntax, replaces NSLocalizedString.

- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- Returns: The localized string.
- returns: The localized string.
*/
func localized(using tableName: String?) -> String {
return localized(using: tableName, in: .main)
}

/**
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString)
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString).

- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
- parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).

- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- Parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).

- Returns: The formatted localized string with arguments.
- returns: The formatted localized string with arguments.
*/
func localizedFormat(using tableName: String?, arguments: CVarArg...) -> String {
func localizedFormat(arguments: CVarArg..., using tableName: String?) -> String {
return String(format: localized(using: tableName), arguments: arguments)
}

/**
Swift 2 friendly plural localization syntax with a format argument
Swift 2 friendly plural localization syntax with a format argument.

- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
- parameter argument: Argument to determine pluralisation.

- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- parameter argument: Argument to determine pluralisation

- returns: Pluralized localized string.
*/
func localizedPlural(using tableName: String?, argument: CVarArg) -> String {
func localizedPlural(argument: CVarArg, using tableName: String?) -> String {
return NSString.localizedStringWithFormat(localized(using: tableName) as NSString, argument) as String
}

Expand Down
118 changes: 59 additions & 59 deletions Sources/String+LocalizedBundleTableName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,63 @@ import Foundation

/// bundle & tableName friendly extension
public extension String {
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString
- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- Returns: The localized string.
*/
func localized(using tableName: String?, in bundle: Bundle?) -> String {
let bundle: Bundle = bundle ?? .main
if let path = bundle.path(forResource: Localize.currentLanguage(), ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
else if let path = bundle.path(forResource: LCLBaseBundle, ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
return self
}
/**
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString)
- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- Parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).
- Returns: The formatted localized string with arguments.
*/
func localizedFormat(using tableName: String?, in bundle: Bundle?, arguments: CVarArg...) -> String {
return String(format: localized(using: tableName, in: bundle), arguments: arguments)
}
/**
Swift 2 friendly plural localization syntax with a format argument
- Parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.

- Parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- parameter argument: Argument to determine pluralisation
- returns: Pluralized localized string.
*/
func localizedPlural(using tableName: String?, in bundle: Bundle?, argument: CVarArg) -> String {
return NSString.localizedStringWithFormat(localized(using: tableName, in: bundle) as NSString, argument) as String
}
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString.
- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: The localized string.
*/
func localized(using tableName: String?, in bundle: Bundle?) -> String {
let bundle: Bundle = bundle ?? .main
if let path = bundle.path(forResource: Localize.currentLanguage(), ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
else if let path = bundle.path(forResource: LCLBaseBundle, ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
return self
}
/**
Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString).
- parameter arguments: arguments values for temlpate (substituted according to the user’s default locale).
- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: The formatted localized string with arguments.
*/
func localizedFormat(arguments: CVarArg..., using tableName: String?, in bundle: Bundle?) -> String {
return String(format: localized(using: tableName, in: bundle), arguments: arguments)
}
/**
Swift 2 friendly plural localization syntax with a format argument.
- parameter argument: Argument to determine pluralisation.
- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: Pluralized localized string.
*/
func localizedPlural(argument: CVarArg, using tableName: String?, in bundle: Bundle?) -> String {
return NSString.localizedStringWithFormat(localized(using: tableName, in: bundle) as NSString, argument) as String
}
}

0 comments on commit daaef14

Please sign in to comment.