location folder: 名字以.lproj結尾。
如果找不到對應語言的.lproj folder,才會採用預設的resource folder。
.lproj 命名規則:
ex:
fr_FR.lproj
fr: 指定language ,代表French language
FR: 指定region, 代表France
所以語言都有至少一個three-digit code
只有某些語言具有two-digit code
locale = language + region
常見的localizable 資源:
字串,圖片,nib檔,App display name
在.lproj directory裡,有個Localizable.strings檔案,裡頭存放對應到此locale的顯示字串。
檔案內容範例如下:
/* show first name */
"first name" = "first name";
等於符號的左邊為key,右邊為對應此locale顯示的文字。
程式碼:
建立Localizable.strings檔案:
利用genstrings指令
ex:
genstrings Test/.m
尋找Test目錄下的.m檔所有用到NSLocalizedString的地方,生出Localizable.strings檔案
將Localizable.strings加入project裡,記得將其encoding設為UTF-16
點選Localizable.strings檔案後,從其設定裡新增Localization
於Localizable.strings(Chinese)即可設定中文顯示字串
常用Localizable.strings語言:
1. zh-Hant
locale = language + region
常見的localizable 資源:
字串,圖片,nib檔,App display name
在.lproj directory裡,有個Localizable.strings檔案,裡頭存放對應到此locale的顯示字串。
檔案內容範例如下:
/* show first name */
"first name" = "first name";
等於符號的左邊為key,右邊為對應此locale顯示的文字。
程式碼:
NSString *str = NSLocalizedString(@"first name", @"show first name");
顯示key為first name所對應到的字串
建立Localizable.strings檔案:
利用genstrings指令
ex:
genstrings Test/.m
尋找Test目錄下的.m檔所有用到NSLocalizedString的地方,生出Localizable.strings檔案
將Localizable.strings加入project裡,記得將其encoding設為UTF-16
點選Localizable.strings檔案後,從其設定裡新增Localization
於Localizable.strings(Chinese)即可設定中文顯示字串
常用Localizable.strings語言:
1. zh-Hant
沒有留言:
張貼留言