Localizability

0.1.0

🌐 Swifty and modern NSLocalizedString
yk4to/Localizability

What's New

v0.1.0

2022-07-02T17:10:07Z

Initial Release

Localizability

Swifty and modern NSLocalizedString

Localizability is a simple Swift library to localize strings easily.

Inspired by sindresorhus/Defaults.

Install

Swift PM

Add https://github.com/Fus1onDev/Localizability in Swift Package Manager.

Features

Usage

First, add some keys and values to Localizable.strings.

"thisIsASampleText" = "This is a sample text.";

"iLikeString" = "I like %@.";

Next, declare the keys.

import Localizability

extension Localized.Keys {
    static let thisIsASampleText = Key("thisIsASampleText")
    static let iLikeString = Key("iLikeString")
}

Finally, you can access it like this:

let str = Localized[.thisIsASampleText]
print(str)

// "This is a sample text." (in your language)

String Templates

If arguments are added, the localized string is used as a template.

let str = Localized[.iLikeString, "apples"]
print(str)

// "I like apples." (in your language)

SwiftUI Supports

These SwiftUI components are also available.

var body: some View {
    LocalizedText(key: .thisIsASampleText)
    // or
    LocalizedText[.thisIsASampleText]
}

LICENSE

MIT

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Oct 22 2024 18:03:31 GMT-0900 (Hawaii-Aleutian Daylight Time)