目录
目录README.md

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.

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

关于
37.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号