iOS-L10n 0.2.0

iOS-L10n 0.2.0

Dani Manuel维护。



iOS-L10n 0.2.0

  • 作者:
  • Dani Manuel Céspedes Lara

iOS-L10n

License Platform

关于

iOS-L10n是一个用于iOS应用程序的本地化框架,允许对Storyboards和源代码进行本地化。

注意

为了避免在导出或导入.xiff文件时出现问题,请取消选中使用基础国际化,并使用其他语言,例如en作为基础。

您的Storyboard不需要按每种本地化语言分割,您可以保留默认设置,如下面的图片所示,以避免管理多个相同的Storyboard副本。

示例

要运行示例项目,请克隆仓库,并首先从示例目录运行pod install

如何在Storyboard中使用iOS-L10n

所有Storyboard对象在检查器属性中公开以下字段:

  • 包标识符:此字段允许您使用给定的标识符创建一个包实例,生成的包用于本地化,如果没有定义标识符,则默认使用 Bundle.main
  • 表名:允许定义用于本地化的表,如果未定义值,则默认使用 Localizable
  • 默认语言:允许您定义一个基础语言,如果没有在当前手机的当前语言中设置要本地化的键,我们将使用默认语言,默认使用 en(英语en.lproj

UIBarItem 的子类

属性检查器允许定义与元素标题相关联的键

UIButton

属性检查器允许为每个可能的状态(normalhighlightedselecteddisabled)定义与按钮的 title 相关的键

UILabel

属性检查器允许定义与标签标题相关联的键

UINavigationItem

属性检查器允许定义与元素的 titleprompt 相关联的键

UISearchBar

属性检查器允许定义与 titleplaceholderprompt 相关的键

属性检查器允许定义与段标题相关联的键,每个键由 , 分隔

UISegmentedControl

UITextField

属性检查器允许定义与 textplaceholder 关联的密钥

UIViewController

属性检查器允许定义与 ViewController 的标题以及与标签栏关联的元素标题相关的密钥

如何在源代码中使用 iOS-L10n

定义你的字符串

MessagesStrings.strings

"welcome_message_key" = "Welcome to use iOS-L10n %@ %@";
"bye_message_key" = "See you soon";

创建一些类型(枚举最好),使其符合 iOS-L10n

MessagesStrings.swift

	import iOS-L10n
	
	enum MessagesStrings: String, iOS-L10n{
		case welcomeMessage = "welcome_message_key" 
		case byeMessage = "bye_message_key"
		
		//var tableName: String = "TableName" //If no defined on code iOS-L10n will infer the table name using the same name that this instance 'MessagesStrings'
		//baseLanguage: String = "es" // If no defined iOS-L10n will use by default 'en'
		//bundle: Bundle = MiFramework.bundle // If no defined iOS-L10n will use by default 'Bundle.main'
		
		// Return the localization value based on self, If no defined iOS-L10n will return the localized value based on this instance's values
		//public var localized: String {
       // return rawValue.localized(bundle: self.bundle, tableName: self.tableName, baseLanguage: self.baseLanguage)
    	//}
	}

使用符合 iOS-L10n 的实例

	let welcomeMessage = MessagesStrings.localize(.welcomeMessage, ["Mr.", "iOS Developer"])
	print(welcomeMessage) //Will print "Welcome to use iOS-L10n Mr. iOS Developer"
	
	let byeMessage = MessagesStrings.localize(.byeMessage)
	print(byeMessage) //Will print "See you soon"
	
	let byeMessageAlt = MessagesStrings.byeMessage.localized
	print(byeMessageAlt) //Will print "See you soon"

要求

  • iOS 8+
  • Swift 4.0

安装

CocoaPods

iOS-L10n 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到你的 Podfile 中

pod 'iOS-L10n'

作者

Dani Manuel Céspedes Lara, [email protected]

许可证

iOS-L10n 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。