IOS 国际化自动配置

此处只有生成国际化文件的步骤,Project中需要增加语言的操作,不知道的自行百度;

1、批量替换字符串
使用正则表达式:@"[^"][\u4E00-\u9FA5]+[^"\n]?" 批量查找项目中的中文字符;
注意:查找条件设置为:
​​

2、批量替换
使用正则表达式:NSLocalizedString($0, nil) 批量替换项目中的中文;

3、自动生成多语言文件(使用xcode自带命令行)

然后执行下面的命令:
find . -name \*.m | xargs genstrings -o zh-Hans.lproj
find . -name \*.m | xargs genstrings -o en.lproj
在 en.lproj 和 zh-Hans.lproj 文件夹中生成对应的Localizable.string文件,
Localizable.string文件就是我们需要的国际化文件;

4、在项目文件中找到生成的

​​
将en.lproj 和 zh-Hans.lproj 文件夹拖入工程项目中就可以了;

5、最后就是翻译的事;

注:在此期间如果出现Error:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

可以执行:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer 来解决
或者重新安装xcode

另外Excel转化:https://github.com/CatchZeng/Localizable.strings2Excel

猜你喜欢

转载自www.cnblogs.com/zhanghouqi/p/11098964.html