文章目录
- 前言
- I 、 例子
- 1.1 效果
- see also
前言
对于在中英文语法的区别,在本地化字符串的时候,我们常常需要调整stringWithFormat的参数顺序
- 原理:在%和@中间加上
数值$
(1$,2$
),数字代表参数的顺序
I 、 例子
self.FORMATLab.text = [NSString stringWithFormat:KNLocal(@"FORMAT", nil), @"csdn", @"https://kunnan.blog.csdn.net/article/details/103733872"];
- en.lproj/Localizable.strings
"FORMAT" = "I am %2$@ from '%1$@'";
- zh-Hans.lproj/Localizable.strings
"FORMAT" = "我是来自“%1$@”的%2$@";
1.1 效果
see also
- 【iOS APP 内的国际化切换】1、字符串的本地化、2、自定义解析本地化字符串的工具类LanguageManager、3、例子:登录界面切换中英文。
附
@interface ViewController () /** 中英文lab,用于切换语言:处理切换中英文语言的动作事件 */ @property (weak, nonatomic) UILabel *languageLab; /** 用于测试指定参数顺序: 在%和@中间加上1$,2$等等就可以啦,数字代表参数的顺序。 */ @property (weak, nonatomic) UILabel *FORMATLab; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self languageLab]; self.view.backgroundColor = UIColor.whiteColor; self.FORMATLab.text = [NSString stringWithFormat:KNLocal(@"FORMAT", nil), @"csdn", @"https://kunnan.blog.csdn.net/article/details/103733872"]; if (@available(iOS 13.0, *)) { [self testUIPageControl]; } } - (UILabel *)FORMATLab{ if (!_FORMATLab) { UILabel *tmp = [[UILabel alloc]init]; _FORMATLab = tmp; tmp.textColor = rgb(51,51,51); tmp.font = kBoldFont(15); tmp.numberOfLines = 0; tmp.textAlignment = NSTextAlignmentCenter; [self.view addSubview:tmp]; __weak __typeof__(self) weakSelf = self; [tmp mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(weakSelf.view).offset(kAdjustRatio(-80)); make.centerX.equalTo(weakSelf.view).offset(-kAdjustRatio(0)); make.left.equalTo(weakSelf.view).offset(-kAdjustRatio(10)); make.right.equalTo(weakSelf.view).offset(-kAdjustRatio(10)); // make.size.mas_equalTo(CGSizeMake(kAdjustRatio(100), kAdjustRatio(40))); }]; } return _FORMATLab; }