5.项目中使用: let str = NSLocalizedString("test", comment: "") print(str) 以上就是配置流程 如果你没有用上面的文件名创建 记得在读取的时候填写对应参数 /// Returns a localized string, using the main bundle if one is not specified. public func NSLocalizedString
Dialog"; "btnTitle" = "Cancel"; "title" = "温馨提示"; "message" = "这是一个对话框"; "btnTitle" = "取消"; 在需要的地方使用NSLocalizedString NSLocalizedString("title", comment: "") NSLocalizedString("message", comment: "") NSLocalizedString(" btnTitle", comment: "") 图片国际化 图片和文本国际化的使用方式一样,首先在Localizable.strings中进行图片名称的设置,然后通过NSLocalizedString( let imageName = NSLocalizedString("img", comment: "") let image = UIImage(named: imageName) imageView.image
alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; NSString *generalV = NSLocalizedString (@"General Version", nil); NSString *America = NSLocalizedString(@"United States", nil); NSString *France = NSLocalizedString(@"France", nil); NSString *China = NSLocalizedString(@"China", nil); NSString *Japan = NSLocalizedString(@"Japan", nil); NSString *Taiwan = NSLocalizedString(@"Taiwan changeRegion = array[i]; [self.tableView reloadData]; }]]; } NSString *cancel = NSLocalizedString
UIBarStyleBlackTranslucent; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString handleActionBarDone:)]; _prevNext = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString (@"Previous", @""), NSLocalizedString(@"Next", @""), nil]]; _prevNext.momentary = YES; _prevNext.segmentedControlStyle
} else { UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString 禁止用户的教具操作 ture为禁止 [_room disableDeviceInputs:YES]; } else { self.title = NSLocalizedString @"加入失败", nil); UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString
BPInternational/Introduction/Introduction.html#//apple_ref/doc/uid/10000171i I 本地化 开发规范:始终把面向用户的字符串用 NSLocalizedString genstrings ViewController.m genstrings苹果推出的一个用于自动从代码的NSLocalizedString提取生成国际化字符串的工具,genstrings 会浏览每个所选的源文件 ,以及每个使用 NSLocalizedString 的源文件,把键和注释追加到目标文件。 在运行时,NSLocalizedString 会确定首选的语言,并在应用程序包中找到相应的 Localizable.strings 文件,例如法语文件fr.lproj/Localizable.strings #define NSLocalizedString(key, comment) \ [NSBundle.mainBundle localizedStringForKey:(key) value
UIAlertView alloc] initWithTitle:@"提示" message:@"您的手机没有打开程序内付费购买" delegate:nil cancelButtonTitle:NSLocalizedString NSLog(@"-------弹出错误信息----------"); UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:NSLocalizedString (@"Alert",NULL) message:[error localizedDescription] delegate:nil cancelButtonTitle:NSLocalizedString UIAlertView alloc] initWithTitle:@"" message:@"购买成功" delegate:nil cancelButtonTitle:NSLocalizedString initWithTitle:@"提示" message:@"购买失败,请重新尝试购买" delegate:nil cancelButtonTitle:NSLocalizedString
UIApplicationShortcutIcon(type: .confirmation) let firstItem = UIMutableApplicationShortcutItem(type: "1", localizedTitle: NSLocalizedString (type: .taskCompleted) let firstItem1 = UIMutableApplicationShortcutItem(type: "2", localizedTitle: NSLocalizedString UIApplicationShortcutIcon(type: .task) let firstItem2 = UIMutableApplicationShortcutItem(type: "3", localizedTitle: NSLocalizedString UIApplicationShortcutIcon(type: .add) let firstItem3 = UIMutableApplicationShortcutItem(type: "4", localizedTitle: NSLocalizedString
{ switch self { case .forgotten: return NSLocalizedString("I forgot it") case .lost: return NSLocalizedString("I lost it") case .dogAteIt: return NSLocalizedString("The dog ate it") }
{ set { guard let newValue = newValue else { return } text = NSLocalizedString { set { guard let newValue = newValue else { return } setTitle(NSLocalizedString { set { guard let newValue = newValue else { return } placeholder = NSLocalizedString
在这里插入图片描述 在代码中使用NSLocalizedString(key, comment)来读取本地化字符串,key是Localizable.strings文件中等号左边的字符串,comment纯粹是注释 #define NSLocalizedString(key, comment) \ [NSBundle.mainBundle localizedStringForKey:(key) value NSString *)table { //假如为跟随系统 if (self.languageType==HZLanguageTypeSystem) { return NSLocalizedString (@"cancel") cancleBlock:nil sureString:QCTLocal(@"sure") sureBlock:^{ 如果没有对字符串进行本地化 或者 找不到key对应的值,NSLocalizedString
,我是全栈君 添加多个button,同样只能加入一个 UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString registerClick:)]; UIBarButtonItem *anotherButton2 = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString
Tip"="Tip"; zh-Hans.lproj/Localizable.strings "Connected" = "已连接"; "Tip"="提示"; 在这里插入图片描述 在代码中使用NSLocalizedString (key, comment)来读取本地化字符串,key是Localizable.strings文件中等号左边的字符串,comment纯粹是注释 #define NSLocalizedString(key NSString *)table { //假如为跟随系统 if (self.languageType==HZLanguageTypeSystem) { return NSLocalizedString (@"cancel") cancleBlock:nil sureString:QCTLocal(@"sure") sureBlock:^{ 如果没有对字符串进行本地化 或者 找不到key对应的值,NSLocalizedString NSString *)table { //假如为跟随系统 if (self.languageType==HZLanguageTypeSystem) { return NSLocalizedString
*timeValue = dic[@"Time"]; NSString *waterValue = dic[@"Water"]; NSString *title = NSLocalizedString (@"Title", nil); NSString *bluetooth = NSLocalizedString(@"Choose Success!" , nil); NSString *confirm = NSLocalizedString(@"Confirm", nil); UIAlertController *alert
Snip20160619_15.png 我们只需要使用Foundation框架自带的NSLocalizedString(key, comment)这个宏根据Key获取对应的字符串,然后赋值给代码中的字符串 #define NSLocalizedString(key, comment) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" 但是上面介绍的代码中字符串的本地化是使用的是默认的文件名"Localizable",因为启动程序时,系统将根据语言加载相应的文件得到其对应的字符串文件,这个字符串可以通过系统将NSLocalizedString (四)图片本地化 本地化图片,有两种方式,第一种方式和本地化代码中的字符串一样,通过NSLocalizedString(key,comment)来获取相应的字符串,然后根据这个字符串再获取图片。 方式一 NSString *imageName = NSLocalizedString(@"icon", nil); UIImage *image = [UIImage imageNamed:imageName
NSString *)table { //假如为跟随系统 if (self.languageType==HZLanguageTypeSystem) { return NSLocalizedString -s substring substitute 'substring' for NSLocalizedString. the genstrings(1) man page for full documentation 生成字符串资源文件的另一种方式(通过终端命令genstrings) 苹果推出的一个用于自动从代码的NSLocalizedString key, tbl, comment)来获取字符串,资源文件会以tbl参数作为文件名 使用步骤: 首先添加获取字符串的代码,比如在ViewController.m NSString *tip = NSLocalizedString (@"Tip", @"dialog title"); NSString *ok = NSLocalizedString(@"Ok", @"dialog button"); NSString
文件里面主要存的是配置文件信息的不同语言键值对,如“CFBundleDisplayName”是APP的名字;Localizable.strings主要存的是自定义的一些字符串;(本人自己的理解,欢迎指教) //NSLocalizedString NSLocalizedStringFromTable(<#key#>, <#tbl#>, <#comment#>)文件名不为Localizable时取字符串的方法 NSString * string = NSLocalizedString
: let numberOfPeople = 1 let numberOfCmoputer = 10 let text = NSString.localizedStringWithFormat(NSLocalizedString 当然要记得代码里需要国际化的字符串使用NSLocalizedString 或者 [NSString localizedStringWithFormat...]
为了能够更精确的对本地化后的文本进行排序,我们也可以对Drink的比较函数做近一步修改: //将lhs.name < rhs.name//改为NSLocalizedString(lhs.name,comment : "") < NSLocalizedString(rhs.name,comment: "") NSLocalizedString可以通过给定的文本键获取对应后的文本值 将InfoView中的 var list:String { order.list.map(\.drink.name).joined(separator: " ")} 改为: order.list.map{NSLocalizedString name: String, price: Double, calories: Double) { self.name = String.localizedStringWithFormat(NSLocalizedString var list:String { order.list.map{NSLocalizedString($0.drink.name, comment: "")}.formatted(.list
现在,我们在storyboard中向视图里添加两个Label,一个用于说明,一个用来显示不同的语言: 将用来显示不同语言的Label关联到代码里去,然后在代码里设置Label所显示的内容: // 使用NSLocalizedString Localization文件中设置的内容实现本地化 // 第一个参数是要显示的内容对应的key值,第二个参数是注释,暂时没发现有什么用 self.locallizedLabel.text = NSLocalizedString (@"LabelText", nil); 如注释所说,这里用到了NSLocalizedString这个方法,这个方法就是用来关联我们刚才创建的Localizable.strings文件的,如果文件名错了