本地化(Language localisation)

來源:互聯網
上載者:User

                           本地化(Language localisation)

1、簡介

        為Symbian應用程式添加本地化資源(localisation aware resources)。

2、設計和實現

       與本地化有關的實體:

  • 項目定義檔案
  • 定義支援的語言
  • 獨立的資源檔
  • 與特定語言相關的資源檔

2.1 項目定義檔案

        使用本地化資源的應用程式必須在項目定義檔案中定義支援的語言。這些語言的相關的資源檔將在編譯過程中建立。

        通過在.mmp檔案中添加 LANG   語句。如果要支援英語和漢語,則添加:
LANG 01 31。   01 代表英語,31代表簡體中文

2.2 定義支援的檔案

       Symbian OS為特定裝置支援的語言定義了一個標識符。例如在支援中文的裝置上這個標識符就是 LANGUAGE_31.

      可以通過Language.loc決定裝載哪種語言的資源檔。Language.loc的內容如下:
        #ifdef LANGUAGE_01
        #include "Language.l01"
        #endif

        #ifdef LANGUAGE_31
        #include "Language.l31"
        #endif

其中Language.l01和Language.l31分別是英語和漢語的資源檔

2.3 獨立的資源檔

        在rss檔案中定義符號標識資源。例如:

MENU_ITEM {command = EAknSoftkeyExit;   txt = LANG_MENU_EXIT;}而不是一般的

MENU_ITEM {command = EAknSoftkeyExit;   txt = "Exit";}

2.4 特定語言的資源檔

        應用程式需要為它支援的每一種語言提供特定的資源檔。每一個這種資源檔中定義了rss檔案中標識資源的符號在特定語言中的內容。例如在Language.l31中定義的中文資源檔內容如下:

CHARACTER_SET UTF8
//  APPLICATION INFORMATION
#define ELanguage               ELangPrcChinese      // Caption language

//  LOCALISATION STRINGS

/*
-----------------------------------------------------------------------------

    Menu texts

-----------------------------------------------------------------------------
*/

#define LANG_MENU_COMMAND1 "顯示"
#define LANG_MENU_EXIT  "退出"

/*
-----------------------------------------------------------------------------

    MessageBox text

-----------------------------------------------------------------------------
*/

#define LANG_I_COMMAND1 "中文"

      注意要將此檔案第一行為CHARACTER_SET UTF8,要將該檔案儲存為UTF-8格式,如果編譯是出現錯誤"undefined character..."是只要將該檔案第一行修改為CHARACTER_SET UTF8就可以了。這是因為ANSI檔案轉為UTF-8檔案,檔案頭會多出了3個位元組

Note: If you’re using MS Visual Studio, you’ll find out that introduces a problem here, since it only supports ANSI. You can easily edit the file in Notepad, which, (in Win2K & XP) lets you save the file as UTF-8. Unfortunately, notepad has the side effect of prefixing the file with the three bytes 0xEF, 0xBB, 0xBF, which make the file unreadable by the compiler. You can fix this by opening the file in Visual studio and deleting these characters.

2.5 使用資源

     CONE"s AllocReadResourceLC(...) 或者StringLoader::LoadLC(...)

3.Summary

  • 概括了本地化資源相關的實體。
  • 示範了如何為Symbian應用程式添加本地化資源(localisation aware resources)。
  • 提供了兩個提取資源的API

modify:

4。安裝

      在.pkg檔案中添加語言指示。例如為本例添加:

      &EN, ZH

       接著在.pkg檔案中找到下面的代碼

       "SymbianUIQ_70Epoc32datazsystemappsMyAppMyApp.rsc"-       "!:systemappsMyAppMyApp.rsc"

        修改為:

        {"SymbianUIQ_70Epoc32datazsystemappsMyAppMyApp.rsc",
          "SymbianUIQ_70Epoc32datazsystemappsMyAppMyApp.r31"}
        -"!:systemappsMyAppMyApp.rsc"

       如果一切順利,安裝時你可以選擇安裝某種語言,且只有這種語言的資源才被安裝。

Enjoy!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.