iPhone中字串的國際化

2022-08-29 01:15:09 字數 1116 閱讀 9754

一、獲取系統所支援的國際化資訊

nsuserdefaults 

*defaults 

=[nsuserdefaults standarduserdefaults]; 

nsarray 

*languages 

=[defaults objectforkey:@""

]; nslog(

@"%@

", languages);

二、對字串進行國際化

1.  應用nslocalizedstring巨集

//括號裡第乙個引數是要顯示的內容,第二個是對第乙個引數的注釋

nsstring 

*teststr =

(@"this is a test nsstring

",@"

這是測試字串");

2. 為每個支援的語言建立目錄

在專案路徑下,為所要支援的語言建立目錄。比如要支援英語和中文,在專案下建立en.lproj和zh.lproj目錄。

3. 使用terminal的genstrings命令進行生成資源檔案。

例如,專案的目錄為:/user/documents/project/test01

命令如下:genstrings -o en.lproj  ./classes/*.m

genstrings -o zh.lproj  ./classes/*.m

4. 修改對應的strings檔案

開啟專案,會發現resource目錄下多了個localizable.strings, 點選展開,會看到名稱為en,zh的檔案,雙擊後可以發現如下格式的字串:

/*這是測試字串 

*/@"

this is a test nsstring"=

@"這是測試字串

"只要根據不同的地區修改右側的字串即可。

zh.strings下,為:@"

this is a test nsstring"=

@"這是測試字串

"en.strings下,為:@"

this is a test nsstring"=

@"this is a test nsstring

"最後一步,儲存更改,編譯並執行程式,就能看到結果了!

android字串國際化

1 在values資料夾下建立不同國家對應的資料夾,然後在這些資料夾下面定義不同國家的字串檔案,檔名隨意,但是conectado屬性名要一致。就是connected名字要一致conectado這個名字是不同國家的語言。android多國語言資料夾檔案彙總如下 中文 中國 values zh rcn ...

Vue中的國際化

單純記錄使用過程中遇到的問題,基礎的用法看官網的就行了官網位址 1.script標籤裡面使用國際化,例如在methods裡面使用 methods 在html標籤屬性中使用,例如在placeholder中使用 type lock lock password text placeholder t log...

spring中配置國際化

先寫好幾個.properties的資源檔案放在classpath下,當然可以放在src下面 我寫了兩個 format.properties 內容 testmsg hello world exception.properties run runtimeexception null nullpointe...