diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2e523..298eba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # Change Log --- +## [5.9.0](https://github.com/Decybel07/L10n-swift/tree/5.9.0) (2021-05-26) + * Bugfix - calling wrong function when using `String.l10n()` without parameters + ## [5.8.1](https://github.com/Decybel07/L10n-swift/tree/5.8.1) (2021-05-03) * Configure basic logger diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index df416d9..29d70ec 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -590,7 +590,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Example iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = bobrowski.adrian.iOS; @@ -647,7 +647,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Example iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = bobrowski.adrian.iOS; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/L10n-swift.podspec b/L10n-swift.podspec index 58fd03e..b65c9ec 100644 --- a/L10n-swift.podspec +++ b/L10n-swift.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.name = 'L10n-swift' spec.module_name = 'L10n_swift' - spec.version = '5.8.1' + spec.version = '5.9.0' spec.summary = 'Localization of an application with ability to change language "on the fly" and support for plural forms in any language.' spec.description = <<-DESC diff --git a/L10n_swift.xcodeproj/project.pbxproj b/L10n_swift.xcodeproj/project.pbxproj index b76ffa0..741065c 100644 --- a/L10n_swift.xcodeproj/project.pbxproj +++ b/L10n_swift.xcodeproj/project.pbxproj @@ -1451,7 +1451,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-iOS"; @@ -1514,7 +1514,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-iOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; @@ -1694,7 +1694,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-watchOS"; @@ -1757,7 +1757,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-watchOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; @@ -1824,7 +1824,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-tvOS"; @@ -1886,7 +1886,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-tvOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; @@ -2061,7 +2061,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-macOS"; @@ -2124,7 +2124,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; - MARKETING_VERSION = 5.8.1; + MARKETING_VERSION = 5.9.0; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "CodingLifestyle.L10n-macOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; diff --git a/README.md b/README.md index 9ba9290..d79f4a4 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,13 @@ pod try L10n-swift ### [CocoaPods](http://cocoapods.org) ```ruby - pod 'L10n-swift', '~> 5.8' + pod 'L10n-swift', '~> 5.9' ``` ### [Carthage](https://github.com/Carthage/Carthage) ```ogdl -github "Decybel07/L10n-swift", ~> 5.8 +github "Decybel07/L10n-swift", ~> 5.9 ``` ### [Swift Package Manager](https://swift.org/package-manager/) diff --git a/Source/Core/L10n.swift b/Source/Core/L10n.swift index f453e59..7d69074 100644 --- a/Source/Core/L10n.swift +++ b/Source/Core/L10n.swift @@ -154,14 +154,14 @@ open class L10n { - parameter key: The key for a string in resource. - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. - parameter fittingWidth: The desired width of the string variation. - - parameter args: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). + - parameter arg: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found. */ - public func plural(for key: String, resource: String? = nil, fittingWidth: Int? = nil, _ args: CVarArg...) -> String { - return self.plural(for: key, resource: resource, fittingWidth: fittingWidth, args: args) + public func plural(for key: String, resource: String? = nil, fittingWidth: Int? = nil, _ arg: CVarArg) -> String { + return self.plural(for: key, resource: resource, fittingWidth: fittingWidth, args: [arg]) } - + /** Returns a localized plural version of the string designated by the specified `key` and `args` and residing in `resource`. @@ -271,6 +271,6 @@ extension L10n { self.logger?.info("L10n - Argument \(key.debugDescription) is not a number.") return key } - return self.plural(for: key, resource: resource, fittingWidth: fittingWidth, arg) + return self.plural(for: key, resource: resource, fittingWidth: fittingWidth, args: [arg]) } } diff --git a/Source/Extensions/String+Localizable.swift b/Source/Extensions/String+Localizable.swift index d7a116f..6e1f3ac 100644 --- a/Source/Extensions/String+Localizable.swift +++ b/Source/Extensions/String+Localizable.swift @@ -20,19 +20,7 @@ extension String: Localizable { } /** - Returns a localized version of the string designated by the `self` and residing in `resource`. - - - parameter instance: The instance of `L10n` used for localization. - - parameter fittingWidth: The desired width of the string variation. - - - returns: A localized version of the string designated by `self` or `self` if not found. - */ - public func l10n(_ instance: L10n = .shared, fittingWidth: Int?) -> String { - return instance.string(for: self, fittingWidth: fittingWidth) - } - - /** - Returns a localized version of the string designated by the `self` and residing in `resource`. + Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. - parameter instance: The instance of `L10n` used for localization. - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. @@ -40,45 +28,9 @@ extension String: Localizable { - returns: A localized version of the string designated by `self` or `self` if not found. */ - public func l10n(_ instance: L10n = .shared, resource: String?, fittingWidth: Int? = nil) -> String { + public func l10n(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int? = nil) -> String { return instance.string(for: self, resource: resource, fittingWidth: fittingWidth) } - - /** - Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. - - - parameter args: The values used to fill. - - - returns: A localized version of the string designated by `self` or `self` if not found. - */ - public func l10n(_ args: CVarArg...) -> String { - return self.l10n(.shared, resource: nil, fittingWidth: nil, args: args) - } - - /** - Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. - - - parameter instance: The instance of `L10n` used for localization. - - parameter args: The values used to fill. - - - returns: A localized version of the string designated by `self` or `self` if not found. - */ - public func l10n(_ instance: L10n = .shared, _ args: CVarArg...) -> String { - return self.l10n(instance, resource: nil, fittingWidth: nil, args: args) - } - - /** - Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. - - - parameter instance: The instance of `L10n` used for localization. - - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. - - parameter args: The values used to fill. - - - returns: A localized version of the string designated by `self` or `self` if not found. - */ - public func l10n(_ instance: L10n = .shared, resource: String, _ args: CVarArg...) -> String { - return self.l10n(instance, resource: resource, fittingWidth: nil, args: args) - } /** Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. @@ -86,14 +38,14 @@ extension String: Localizable { - parameter instance: The instance of `L10n` used for localization. - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. - parameter fittingWidth: The desired width of the string variation. - - parameter args: The values used to fill. + - parameter arg: The value used to fill. - returns: A localized version of the string designated by `self` or `self` if not found. */ - public func l10n(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int, _ args: CVarArg...) -> String { - return self.l10n(instance, resource: resource, fittingWidth: fittingWidth, args: args) + public func l10n(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int? = nil, _ arg: CVarArg) -> String { + return self.l10n(instance, resource: resource, fittingWidth: fittingWidth, args: [arg]) } - + /** Returns a localized version of the string designated by the `self`, residing in `resource` and filled with the values of the arguments. @@ -106,59 +58,24 @@ extension String: Localizable { */ public func l10n(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int? = nil, args: [CVarArg]) -> String { let localizedFormat = instance.string(for: self, resource: resource, fittingWidth: fittingWidth) - return instance.string(format: localizedFormat, args: args) - } - - /** - Returns a localized plural version of the string designated by the specified `self` and `args` and residing in `resource`. - - - parameter args: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). - - - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found. - */ - public func l10nPlural(_ args: CVarArg...) -> String { - return self.l10nPlural(.shared, resource: nil, fittingWidth: nil, args: args) + return args.isEmpty ? localizedFormat : instance.string(format: localizedFormat, args: args) } - /** - Returns a localized plural version of the string designated by the specified `self` and `args` and residing in `resource`. - - - parameter instance: The instance of `L10n` used for localization. - - parameter args: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). - - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found. - */ - public func l10nPlural(_ instance: L10n, _ args: CVarArg...) -> String { - return self.l10nPlural(instance, resource: nil, fittingWidth: nil, args: args) - } - - /** - Returns a localized plural version of the string designated by the specified `self` and `args` and residing in `resource`. - - - parameter instance: The instance of `L10n` used for localization. - - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. - - parameter args: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). - - - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found. - */ - public func l10nPlural(_ instance: L10n = .shared, resource: String, _ args: CVarArg...) -> String { - return self.l10nPlural(instance, resource: resource, fittingWidth: nil, args: args) - } - /** Returns a localized plural version of the string designated by the specified `self` and `args` and residing in `resource`. - parameter instance: The instance of `L10n` used for localization. - parameter resource: The receiver’s string resource to search. If resource is nil or is an empty string, the method attempts to use the resource in **Localizable** files. - parameter fittingWidth: The desired width of the string variation. - - parameter args: The values for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). + - parameter arg: The value for which the appropriate plural form is selected. If you want to modify the argument to be displayed, use `PluralArg` (eg. `NumericPluralArg`). - returns: A localized plural version of the string designated by `key`. This method returns `key` when `key` not found. */ - public func l10nPlural(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int, _ args: CVarArg...) -> String { - return self.l10nPlural(instance, resource: resource, fittingWidth: fittingWidth, args: args) + public func l10nPlural(_ instance: L10n = .shared, resource: String? = nil, fittingWidth: Int? = nil, _ arg: CVarArg) -> String { + return self.l10nPlural(instance, resource: resource, fittingWidth: fittingWidth, args: [arg]) } - + /** Returns a localized plural version of the string designated by the specified `self` and `args` and residing in `resource`. diff --git a/Tests/L10n/L10nPluralTests.swift b/Tests/L10n/L10nPluralTests.swift index 2f2f595..607d5bc 100644 --- a/Tests/L10n/L10nPluralTests.swift +++ b/Tests/L10n/L10nPluralTests.swift @@ -93,7 +93,7 @@ final class L10nPluralTests: L10nBaseTest { private func checkPlurals(_ array: [(key: String, value: Int, expected: String)]) { array.forEach { key, value, expected in - print(expected, key.l10nPlural(self.l10nInstance, value)) + print(expected, key.l10nPlural(self.l10nInstance, [value])) // XCTAssertEqual(expected, key.l10nPlural(self.l10nInstance, value)) // XCTAssertEqual(expected, self.l10nInstance.plural(for: key, value)) } diff --git a/Tests/L10n/L10nStringTests.swift b/Tests/L10n/L10nStringTests.swift index 78828a1..a7cfd0f 100644 --- a/Tests/L10n/L10nStringTests.swift +++ b/Tests/L10n/L10nStringTests.swift @@ -21,6 +21,9 @@ final class L10nStringTests: L10nBaseTest { func testStringBaseLanguage() { self.l10nInstance.language = "Base" self.checkBaseEnglishStrings() + + XCTAssertEqual("Hello %@!", "parameters.oneArg".l10n()) + XCTAssertEqual("Hello %@!", self.l10nInstance.string(for: "parameters.oneArg")) } func testStringSupportedLanguage() { @@ -52,6 +55,7 @@ final class L10nStringTests: L10nBaseTest { (key: "hello.world.deeper", expected: "hello.world.deeper"), (key: "parameters", expected: "parameters"), (key: "other", expected: "other"), + (key: "parameters.oneArg", expected: "Hello %@!"), ]) }