[iOS] 多國語系 (Localization)

Posted in :

首先要有字串檔案,在Resources中新增檔案,iOS->Resource->Strings File,命名為Localizable,不修改這個 file 的名字的話,預設是 File, 所以會開成一個 File.string 檔案,改一下會比較知道這個檔案的用途。

目前我用的是  Xcode v8.3.1

 

進入Xcode專案,首先點專案檔,PROJECT->Info->Localizations新增想要的語言,我是增加了中文,接下來要選擇那些檔案要被多國語言,有UI 的 storyboard  和剛才新增的 String file 可以選,由於UI可以共用,所以只選 String file.

其實,這個晝面弄很久才弄出來,似乎跟 “Use Base Internationalization” 有關,勾掉之後就只剩English, 然後再增加中文就變正常了,新的 Base Internationalization 暫時懶的去研究是什麼新功能。請叫我囫圇吞棗大師~,讀書和做研究都不求甚解。

 

 

String file, 的英文檔:

"About" = "About";

對應到中文的檔案時:

"About" = "關於";

 

在程式碼裡使用 NSLocalizedString(<#key#>, <#comment#>) 來讀取多國化字串。

 

相關文章:

iOS本地化 NSLocalizedString的使用
http://www.jianshu.com/p/3d77c2e76684

NSLocalizedString
https://developer.apple.com/reference/foundation/nslocalizedstring

 

Localizing Your App
https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *