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

nullic/DPLocalizationManager: Provides way to change localization inside applica ...

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

开源软件名称(OpenSource Name):

nullic/DPLocalizationManager

开源软件地址(OpenSource Url):

https://github.com/nullic/DPLocalizationManager

开源编程语言(OpenSource Language):

Objective-C 57.7%

开源软件介绍(OpenSource Introduction):

Build Status Carthage compatible Swift Package Manager compatible Version License Platform

DPLocalization

DPLocalization provide easy enough way to change localization inside application.

Usage

###Dynamic localization

  1. Use autolocalizationKey property in code or as user defined runtime attribute in xib:
	myLabel.autolocalizationKey = @"my_label_localization_key";
	myButton.autolocalizationKey = @"my_button_name";
  1. Use -[setupAutolocalizationWithKey:keyPath:] or -[setupAutolocalizationWithKey:keyPath:arguments:] method of NSObject:
	[myLabel setupAutolocalizationWithKey:@"my_label_localization_key" keyPath:@"text"];
	[myLabel setupAutolocalizationWithKey:@"my_label_localization_template_key" keyPath:@"text" arguments:@[@"first", @"second"]];

Now after changing language (for example: dp_set_current_language(@"de")) all objects, which was configured for dynamic localization, update their content.

###Static localization

For static localization select language (for example: dp_set_current_language(@"de")) and use DPLocalizedString() macro in NSLocalizedString() maner.

###Proxy objects

Use DPAutolocalizationProxy class methods or their replacements.

    NSString *str = [NSString autolocalizingStringWithLocalizationKey:@"language"];

    dp_set_current_language(@"en");
    CFShow((__bridge CFTypeRef)(str));
    dp_set_current_language(@"ru");
    CFShow((__bridge CFTypeRef)(str));

Output example:

	English
	Russian

Plural rules

List of all supported languages. Currently library suported only cardinal type. Library use .stringsdict files (Stringsdict File Format), with little changes:

  • NSStringFormatValueTypeKey is ignored
  • format specifiers must be 'Objective-C object'

Attributed strings

Some contols (since iOS 6) are support attributed values. You can specify attributes using special format (<attributes>{string}), it also reqire to set isAttributedKey property to YES. Attributes will apply for string inside {}, other parts will use parameters specified by control. For example:

/* Localizable.strings */
"TITLE" = "English <color=12,56,189 size=12>{(en)}";
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectZero];
myLabel.autolocalizationKey = @"TITLE";
myLabel.isAttributedKey = YES;

Will set attributedText property with string that can be described as:

English {
    NSColor = "UIDeviceWhiteColorSpace 0 1";
    NSFont = "<UICTFont: 0x79743450> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 17.00pt";
}(en){
    NSColor = "UIDeviceRGBColorSpace 0.0470588 0.219608 0.741176 1";
    NSFont = "<UICTFont: 0x79644cc0> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}

Avalible attributes:

  • name - set font name - <name=\"Courier-BoldOblique\">{string}
  • size - set font size - <size=12.0>{string} or <size=12>{string}
  • color - set text color in RGB or RGBA format - <color=12,56,189>{string} or <color=12,56,189,255>{string}
  • traits - set font traits: b (bold), i (italic); and text attributes u (underline), s (strikethrough), m (monospace); ! used for remove attibute - <traits=b>{string} or <traits=!b>{string}
  • kern - set font kerning
  • link - set link attribute - <link=\"https://github.com/nullic/DPLocalizationManager\">{link to DPLocalizationManager}
  • spacing - set space between paragraphs
  • linespacing - set space between lines
  • alignment - set alignment of paragraph <alignment=center>{Center\n}<alignment=left>{Left}. Valid values: left center right justified natural. Due to NSParagraphStyle behaviour each paragraph should be ended with \n and each section should have alignment if it is used in any place of localization string.

Replacements

You can specify replacement using next format: [<replacer>]. This feature also reqire set isAttributedKey property to YES. Example:

/* Localizable.strings */
"TITLE_WITH_IMAGE" = "Title [<img=\"image_name_here\">]";
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectZero];
myLabel.autolocalizationKey = @"TITLE_WITH_IMAGE";
myLabel.isAttributedKey = YES;

Avalible replacers:

  • img - insert image named - [<img=\"image_name_here\"> size=(16,16) offset=(0,0)] - size and offset are optinal parameters. By default size is (image.width, image.height); offset is (0, font.descender)

Installation

CocoaPods

DPLocalization is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "DPLocalization"

Carthage

To integrate DPLocalization into your Xcode project using Carthage, specify it in your Cartfile:

github "nullic/DPLocalizationManager"

Run carthage update to build the framework and drag the built DPLocalization.framework into your Xcode project.

Localization check

dpstrings.py it is Python script, that used for checking most common usage of library. It's scan {some} folder for sources and resoures and make validation for common errors (missing keys, duplication).

Usage example: python dpstrings.py -p "MyProjectPath" -l "en;ru;".
For more information: python dpstrings.py --help.

License

DPLocalization is available under the MIT license. See the LICENSE file for more info.




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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