动态添加新的语言字符串文件以在iOS中进行本地化

时间:2018-06-12 06:04:07

标签: ios xcode localization internationalization mainbundle

方法 我使用字符串文件实现了本地化,如下所示: enter image description here enter image description here

问题

可以在运行时添加新的语言文件吗?

1 个答案:

答案 0 :(得分:1)

您可以自己创建正确的捆绑目录和字符串文件,并使用更长版本的NSLocalizedString。

Alejandro Martinez的approach is described here

// The two important new parameters are `tableName` and `bundle`. 
// By default when using NSLocalizedString the system uses the App 
// main bundle and the Localizable table, *table* meaning the name 
// of the strings file. So to hook into the localization system we 
// just need to convert the object structure that we have in memory 
// to the proper file hierarchy that is expected on disk.
NSLocalizedString(_ key: String, tableName: String? = default, 
  bundle: Bundle = default, value: String = default, comment: String)
  -> String