Fixed the plural string showing when it should show singular, and updated the README to document i18n

This commit is contained in:
Jeroen Wesbeek 2018-02-09 12:03:48 +01:00
parent 74d8d7c829
commit 5ccb7ec4ae
3 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'GHKit'
spec.version = '0.0.2'
spec.version = '0.0.3'
spec.summary = 'GHKit framework for version checks using GitHub releases'
spec.homepage = 'https://github.com/4np/GHKit'
spec.license = { type: 'APACHE', file: 'LICENSE' }

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/4np/GHKit.svg?branch=master)](https://travis-ci.org/4np/GHKit)
[![Release](https://img.shields.io/github/release/4np/GHKit.svg)](https://github.com/4np/GHKit/releases/latest)
[![Commits Since](https://img.shields.io/github/commits-since/4np/GHKit/0.0.2.svg?maxAge=3600)](https://github.com/4np/GHKit/commits/master)
[![Commits Since](https://img.shields.io/github/commits-since/4np/GHKit/0.0.3.svg?maxAge=3600)](https://github.com/4np/GHKit/commits/master)
[![Platform](https://img.shields.io/badge/platform-tvOS%2011-green.svg?maxAge=3600)](https://developer.apple.com/tvos/)
[![Swift](https://img.shields.io/badge/language-Swift-ed523f.svg?maxAge=3600)](https://swift.org)
[![Open Issues](https://img.shields.io/github/issues/4np/GHKit.svg?maxAge=3600)](https://github.com/4np/GHKit/issues)
@ -29,7 +29,7 @@ pod 'NPOKit', :git => 'https://github.com/4np/GHKit.git'
Add the following entry to your package's dependencies:
```swift
.package(url: "https://github.com/4np/GHKit.git", from: "0.0.2")
.package(url: "https://github.com/4np/GHKit.git", from: "0.0.3")
```
## Setup
@ -82,6 +82,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
In order you test, you could change the interval to 10 seconds (`TimeInterval(exactly: 10)`)
## Internationalization / i18n
Add the following strings to your `Localizable.strings` file(s):
```
/* GHKit - release alerts */
"New release available" = "New release available";
"You are %i releases behind" = "You are %i releases behind";
"Version '%@' is available for download at '%@'.\n\n%@" = "Version '%@' is available for download at '%@'.\n\n%@";
```
## How does it work?
`GHKit` will [Swizzle](http://nshipster.com/method-swizzling/) `UIViewController`'s `viewDidLoad` method to check for new releases _if_ the interval has passed. It uses the application bundle's version to check against the available GitHub releases and notify the end user if a new version is available. _Note that `GHKit` only reports that a new release is available; it does not download or install anything!_

View File

@ -55,7 +55,7 @@ extension UIViewController {
// i18n
let singularTitle = "New release available".localized(withComment: "New release alert title (singular)")
let pluralTitleFormat = "You are %i releases behind".localized(withComment: "New release alert title (plural)")
let title = (count > 0) ? String.localizedStringWithFormat(pluralTitleFormat, count) : singularTitle
let title = (count > 1) ? String.localizedStringWithFormat(pluralTitleFormat, count) : singularTitle
let messageFormat = "Version '%@' is available for download at '%@'.\n\n%@".localized(withComment: "New release alert message")
let message = String.localizedStringWithFormat(messageFormat, version, release.url.absoluteString, release.body)