1. 程式人生 > >app應用內中英文切換

app應用內中英文切換

      工程-PROJECT-info->Localizations,點“+”,選擇(Chinese(Simplified))新增簡體中文,英文Xcode自帶有(English),所以不需要再次新增。(點選新增彈出語言選單,即可選擇你所需要的語言)


2.現在可以新增多語言檔案了。

   注意:需要手動切換語言,而不是根據系統語言變換,所以命名不能與系統語言檔案同名,即Localizable.strings;

自己隨意命名,字尾是.strings,一定要記得Targets要勾選專案

3.配置English.strings本地化,現在支援中文和英文。

  (1)選中English.strings檔案,檢視右邊欄中的資訊;(2)點選Localization中的按鈕,彈出框中顯示出前面新增的語言;(3)選擇中文和英文,base選項可有可無,


勾選之後,English.strings中多出了兩個檔案

完成之後便是完成了專案內多語言環境的配置,下面看一下這兩個檔案中應該怎樣寫

4.檔案中新增需要的字串

中文:

"AirLeak" = "漏氣";

"AppUseDes" = "APP使用說明";

"AutoBind" = "自動繫結";

"AutoBindNewDevice" = "自動繫結";

"BackToDefaultSet" = "恢復預設設定";

"BatteryAlertDown" = "電量警報下限";

"BindNewDevice" = "繫結新裝置";

"BleOpen" = "藍芽開啟";

"Cancel" = "取消";

"DeviceHasBeenBD"

= "裝置已經被繫結";

"DeviceInstallDes" = "裝置安裝說明";

"Ensure" = "確定";

"FindNewDevice" = "發現新版本";

"HighTempreture" = "溫度過高";

"Help" = "幫助";

"HighPressure" = "氣壓過高";

"Home" = "首頁";

"InputRightCode" = "請輸入正確的編號";

"InputWheelCode" = "請輸入輪胎編碼\n(0-9a-fA-F組成)";

"LowBattery" = "電量低";

"LowPressure" = "氣壓低";

"ManualBindNewDevice"

= "手動繫結";

"ManualBind" = "手動繫結";

"PleaseBindDevice" = "請繫結裝置";

"PleaseOpenBle" = "請開啟藍芽";

"PressureAlertDown" = "壓力警告下限";

"PressureAlertUpper" = "壓力警告上限";

"PressureUnint" = "壓力單位";

"Searching" = "搜尋中";

"SharkAlert" = "震動報警";

"SystemSet" = "系統設定";

"TempretureAlertUpper" = "溫度警告上限";

"TempretureUnint" = "溫度單位";

"LeftUpWheel" = "左前輪胎";

"RightUpWheel" = "右前輪胎";

"LeftDownWheel" = "左後輪胎";

"RightDownWheel" = "右後輪胎";

"RotationType" = "調胎";

"ScanAndScan" = "掃一掃";//掃一掃

"AlbumLab" = "相簿";

"ChooseQRCodePic" = "請選擇二維碼圖片";

"ChooseSure" = "確認";

"ScanCodeSuccess" = "掃碼繫結成功";//掃碼繫結成功

"ScanRepeat" = "請重新掃描";//請重新掃描

"ScanBind" = "掃碼繫結";//掃碼繫結

英文:

"AirLeak" = "Air leak";

"AppUseDes" = "app use manual";

"AutoBind" = "Auto bind";

"AutoBindNewDevice" = "Auto bind";

"BackToDefaultSet" = "Restore default setting";

"BatteryAlertDown" = "Minimum alert battery";

"BindNewDevice" = "Bind new sensor";

"BleOpen" = "Ble enabled";

"Cancel" = "Cancel";

"DeviceHasBeenBD" = "Device has been bound";

"DeviceInstallDes" = "device install instructions";

"Ensure" = "Ok";

"FindNewDevice" = "New version";

"HighTempreture" = "High temperature";

"Help" = "Help";

"HighPressure" = "High pressure";

"Home" = "Home";

"InputRightCode" = "Input correct code";

"InputWheelCode" = "Input wheel code";

"LowBattery" = "Low battery ";

"LowPressure" = "Low pressure";

"ManualBindNewDevice" = "Manual bind";

"ManualBind" = "manual bind";

"PleaseBindDevice" = "Please bind sensor";

"PleaseOpenBle" = "Enable ble";

"PressureAlertDown" = "Minimum alert pressure";

"PressureAlertUpper" = "Maximum alert pressure";

"PressureUnint" = "Pressure unit ";

"Searching" = "Searching";

"SharkAlert" = "Vibration alert";

"SystemSet" = "System setting";

"TempretureAlertUpper" = "Maximum alert temperature";

"TempretureUnint" = "Temperature unit";

"LeftUpWheel" = "Left up wheal";

"RightUpWheel" = "Right up wheal";

"LeftDownWheel" = "Left down Wheal";

"RightDownWheel" = "Right down wheal";

"RotationType" = "Tyre rotation";

"ScanAndScan" = "Scan";//掃一掃

"AlbumLab" = "Album";

"ChooseQRCodePic" = "Please choose a pic of QRCode";

"ChooseSure" = "sure";

"ScanCodeSuccess" = "Scan success";//掃碼繫結成功

"ScanRepeat" = "Scan repeat";//請重新掃描

"ScanBind" = "Scan bind";//掃碼繫結


5.配置環境已經完成,現在看看程式碼怎麼寫????

(1)新建立工具類,繼承自NSObject(在這裡我命名為ChangeLanguage)

(2)ChangeLanguage.h

+(NSBundle *)bundle;//獲取當前資原始檔

+(void)initUserLanguage;//初始化語言檔案

+(NSString *)userLanguage;//獲取應用當前語言

+(void)setUserlanguage:(NSString *)language;//設定當前語言

ChangeLanguage.m