⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localizationutils.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * Copyright (C) 2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#include "stdafx.h"
#include "localizationUtils.h"
#include <CString>
#include "spds/constants.h"

#include "pim/ClientSettings.h"

#ifdef WIN32_PLATFORM_WFSP
#include "funresourcesp.h"
#endif
#ifdef WIN32_PLATFORM_PSPC
#include "funresourceppc.h"
#endif



//
// Init static pointer.
//
localizationUtils* localizationUtils::pinstance = NULL;

/*
* Method to get the sole instance
* automatically we set up the instance and
* creates the resource for the localization dll
* in every class that uses this singleton we need to import
* funresourceppc.h for PPC and
* funresourcesp.h for SP
* present in the FunLanguage-en projectI
* to have the correct list of the define for the string table
*/
localizationUtils* localizationUtils::getInstance() {
    if (pinstance == NULL) {
        pinstance = new localizationUtils();
    }
    return pinstance;
}


localizationUtils::localizationUtils(){
    initLangCodes();
    setLocaleResource();
}

/*
   Setting up the resource for the localization dll
   first of all we look up if there is a custom localization dll
   it should be called language.dll under the Funambol directory
   then we look for the user default language. We get the primary
   language of the country and we look if under the funambol directory
   there's the corrispondent dll
   the default language dll is language-en.dll for english
*/
void localizationUtils::setLocaleResource(){

    wchar_t* path = toWideChar(getRegConfig()->getAppPath().c_str());
    
    CString libpath(path);
    
    if (path) { delete [] path; }

    CString libnamecustom(TEXT("\\language.dll"));
    CString libname(TEXT("\\language-"));
 
    localeResource = LoadLibrary(libpath + libnamecustom);

    if (localeResource == NULL){
        LANGID lId = GetUserDefaultLangID();
        
        lId &= 0x1F;

        if (lId && langCodes[lId]) {
            localeResource = LoadLibrary( libpath + TEXT("\\") + libname + langCodes[lId] + TEXT(".dll") );
        } else {
            localeResource = LoadLibrary( libpath + TEXT("\\") + libname+ TEXT("en") + TEXT(".dll") );
        }
    
        if (localeResource == NULL){
            localeResource = LoadLibrary( libpath + TEXT("\\") + libname + TEXT("en") + TEXT(".dll") );
        }
    }
}

/* 
   Setting up the map for have union between the
   primary language and the char code of the language
*/
void localizationUtils::initLangCodes(){

    langCodes[LANG_AFRIKAANS] = TEXT("af");
    langCodes[LANG_ALBANIAN] = TEXT("sq");
    langCodes[LANG_ARABIC] = TEXT("ar");
    langCodes[LANG_ARMENIAN] = TEXT("hy");
    langCodes[LANG_ASSAMESE] = TEXT("as");
    langCodes[LANG_AZERI] = TEXT("az");
    langCodes[LANG_BASQUE] = TEXT("eu");
    langCodes[LANG_BELARUSIAN] = TEXT("be");
    langCodes[LANG_BENGALI] = TEXT("bn");
    langCodes[LANG_BULGARIAN] = TEXT("bg");
    langCodes[LANG_CATALAN] = TEXT("ca");
    langCodes[LANG_CHINESE] = TEXT("zh");
    langCodes[LANG_CROATIAN] = TEXT("hr");
    langCodes[LANG_CZECH] = TEXT("cs");
    langCodes[LANG_DANISH] = TEXT("da");
    langCodes[LANG_DIVEHI] = TEXT("dv");
    langCodes[LANG_DUTCH] = TEXT("nl");
    langCodes[LANG_ENGLISH] = TEXT("en");
    langCodes[LANG_ESTONIAN] = TEXT("et");
    langCodes[LANG_FAEROESE] = TEXT("fo");
    langCodes[LANG_FARSI] = TEXT("--");
    langCodes[LANG_FINNISH] = TEXT("fi");
    langCodes[LANG_FRENCH] = TEXT("fr");
    langCodes[LANG_GEORGIAN] = TEXT("ka");
    langCodes[LANG_GERMAN] = TEXT("de");
    langCodes[LANG_GREEK] = TEXT("el");
    langCodes[LANG_GUJARATI] = TEXT("gu");
    langCodes[LANG_HEBREW] = TEXT("he");
    langCodes[LANG_HINDI] = TEXT("hi");
    langCodes[LANG_HUNGARIAN] = TEXT("hu");
    langCodes[LANG_ICELANDIC] = TEXT("is");
    langCodes[LANG_INDONESIAN] = TEXT("id");
    langCodes[LANG_ITALIAN] = TEXT("it");
    langCodes[LANG_JAPANESE] = TEXT("ja");
    langCodes[LANG_KANNADA] = TEXT("kn");
    langCodes[LANG_KASHMIRI] = TEXT("--");
    langCodes[LANG_KAZAK] = TEXT("kk");
    langCodes[LANG_KONKANI] = TEXT("kok");
    langCodes[LANG_KOREAN] = TEXT("ko");
    langCodes[LANG_LATVIAN] = TEXT("lv");
    langCodes[LANG_LITHUANIAN] = TEXT("lt");
    langCodes[LANG_MACEDONIAN] = TEXT("mk");
    langCodes[LANG_MALAY] = TEXT("ms");
    langCodes[LANG_MALAYALAM] = TEXT("ml");
    langCodes[LANG_MANIPURI] = TEXT("--");
    langCodes[LANG_MARATHI] = TEXT("mr");
    langCodes[LANG_MONGOLIAN] = TEXT("mn");
    langCodes[LANG_NEPALI] = TEXT("ne");
    langCodes[LANG_NORWEGIAN] = TEXT("no");
    langCodes[LANG_ORIYA] = TEXT("or");
    langCodes[LANG_POLISH] = TEXT("pl");
    langCodes[LANG_PORTUGUESE] = TEXT("pt");
    langCodes[LANG_PUNJABI] = TEXT("pa");
    langCodes[LANG_ROMANIAN] = TEXT("ro");
    langCodes[LANG_RUSSIAN] = TEXT("ru");
    langCodes[LANG_SANSKRIT] = TEXT("sa");
    langCodes[LANG_SERBIAN] = TEXT("sr");
    langCodes[LANG_SINDHI] = TEXT("--");
    langCodes[LANG_SLOVAK] = TEXT("sk");
    langCodes[LANG_SLOVENIAN] = TEXT("sl");
    langCodes[LANG_SPANISH] = TEXT("es");
    langCodes[LANG_SWAHILI] = TEXT("sw");
    langCodes[LANG_SWEDISH] = TEXT("sv");
    langCodes[LANG_SYRIAC] = TEXT("syr");
    langCodes[LANG_TAMIL] = TEXT("ta");
    langCodes[LANG_TATAR] = TEXT("tt");
    langCodes[LANG_TELUGU] = TEXT("te");
    langCodes[LANG_THAI] = TEXT("th");
    langCodes[LANG_TURKISH] = TEXT("tr");
    langCodes[LANG_UKRAINIAN] = TEXT("uk");
    langCodes[LANG_URDU] = TEXT("ur");
    langCodes[LANG_UZBEK] = TEXT("uz");
    langCodes[LANG_VIETNAMESE] = TEXT("vi");
}

/**
 * Get the localized string from a IDS.
 * 
 * @param ids the string id in the string table
 * @return a const pointer to the string.
 *
 * NOTE: the value returned is stored by the class and is overridded at
 *       each call of this function. The caller must copy the string value
 *       if needed.
 */
const wchar_t* localizationUtils::getLocalizationString(UINT ids){
    
    const int VAL_LEN = 1024;

    //CString s1;
    if (localeResource == NULL){
         setLocaleResource();
    }
    wchar_t tmp[VAL_LEN];
    LoadString(localeResource, ids, tmp, VAL_LEN);
    
    internalBuffer = tmp;
    return internalBuffer.c_str();
}


/* 
   returns the resource of the language dll for the UI
*/
HINSTANCE localizationUtils::getLocaleResource(){

    return localeResource;
}


localizationUtils* getLocalizationUtils(){
    return localizationUtils::getInstance();
}

/*
  used to create a message box with a custom message
  passed by value.
void showMessage(UINT VALUE){
    CString s1,s2;
    s1.LoadString(getLocalizationUtils()->getLocaleResource(),VALUE);
    s2.LoadString(getLocalizationUtils()->getLocaleResource(),IDS_FUNAMBOL_ALERT);
    MessageBox (NULL, s1, s2, MB_SETFOREGROUND | MB_ICONWARNING |MB_OK);
}
  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -