• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

marmelroy/Localize-Swift: Swift friendly localization and i18n with in-app langu ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

marmelroy/Localize-Swift

开源软件地址(OpenSource Url):

https://github.com/marmelroy/Localize-Swift

开源编程语言(OpenSource Language):

Swift 87.4%

开源软件介绍(OpenSource Introduction):

Platform Version Build Status Carthage compatible

Localize-Swift

Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app language switching.

Features

  • Keep the Localizable.strings file your app already uses.
  • Allow your users to change the app's language without changing their device language.
  • Use .localized() instead of NSLocalizedString(key,comment) - a more Swifty syntax.
  • Generate your strings with a new genstrings swift/python script that recognises .localized().

Usage

Import Localize at the top of each Swift file that will contain localized text.

If CocoaPods -

import Localize_Swift

Add .localized() following any String object you want translated:

textLabel.text = "Hello World".localized()

To get an array of available localizations:

Localize.availableLanguages()

To change the current language:

Localize.setCurrentLanguage("fr")

To update the UI in the view controller where a language change can take place, observe LCLLanguageChangeNotification:

NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)

To reset back to the default app language:

Localize.resetCurrentLanguageToDefault()

genstrings

To support this new i18n syntax, Localize-Swift includes custom genstrings swift script.

Copy the genstrings.swift file into your project's root folder and run with

./genstrings.swift

This will print the collected strings in the terminal. Select and copy to your default Localizable.strings.

The script includes the ability to specify excluded directories and files (by editing the script).

[Preferrred] Setting up with Swift Package Manager

The Swift Package Manager is now the preferred tool for distributing Localize-Swift.

From Xcode 11+ :

  1. Select File > Swift Packages > Add Package Dependency. Enter https://github.com/marmelroy/Localize-Swift.git in the "Choose Package Repository" dialog.
  2. In the next page, specify the version resolving rule as "Up to Next Major" with "3.2.0".
  3. After Xcode checked out the source and resolving the version, you can choose the "Localize-Swift" library and add it to your app target.

For more info, read Adding Package Dependencies to Your App from Apple.

Alternatively, you can also add Localize-Swift to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/marmelroy/Localize-Swift.git", .upToNextMajor(from: "3.2.0"))
]

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Localize-Swift into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/Localize-Swift"

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'Localize-Swift', '~> 3.2'



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
binaryage/totalfinder-i18n: Localization for TotalFinder发布时间:2022-08-15
下一篇:
OCA/l10n-italy: Odoo Italian localization发布时间:2022-08-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap