Skip to content

Commit

Permalink
Bugfix - calling wrong function when using String.l10n without parame…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
Decybel07 committed May 26, 2021
1 parent 2b202a4 commit 68a6aa8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 113 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)";
Expand Down
2 changes: 1 addition & 1 deletion L10n-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions L10n_swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)";
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/L10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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])
}
}
105 changes: 11 additions & 94 deletions Source/Extensions/String+Localizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 +20,32 @@ 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.
- 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, 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.
- 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.
Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion Tests/L10n/L10nPluralTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/L10n/L10nStringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 %@!"),
])
}

Expand Down

0 comments on commit 68a6aa8

Please sign in to comment.