Description: Use curly bracket placeholders within strings just like on Android. We created this in order to use the same translation phrases for both our Android and iOS apps.
This is a lightweight port of Phrase - Android string formatting into Swift 5 and used in production for our iOS customer app. It has no other dependencies and can be installed using Swift Package Manager or CocoaPods.
- Replace placeholders with curly brackets within strings with corresponding content (
"Hello, my name is {name}"
becomes"Hello, my name is Ada"
) - Supports multiple placeholders per string
- When using Phrase for Android and PhraseSwift for iOS, you can use the same translation sources for both platforms
- Licence: Apache 2.0
This is the recommended way to install and use this library.
In Project Settings, on the tab "Package Dependencies", click "+" and add github.com/nextbike/phrase-swift
- Add a dependency in Package.swift:
dependencies: [ .package(url: "https://github.com/nextbike/phrase-swift", from: "1.0.1") ]
- For each relevant target, add a dependency
.target( name: "Example", dependencies: [ .product(name: "PhraseSwift", package: "phrase-swift"), ] )
Also check out Editing a package dependency as a local package to work in local changes within your existing project that uses this package.
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website.
pod 'PhraseSwift', :git => 'https://github.com/nextbike/phrase-swift.git', '~> 1.0.1
import PhraseSwift
let source = "Hello {world}"
let output = Phrase.localize(source, keyValues: ["world": "nextbike"])
// output: "Hello nextbike"
Includes a suite of unit tests to cover frequent cases of placeholder location and handling within strings. Run swift test
or open up the Swift Package within Xcode.