localizationutils.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 268 行
CPP
268 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
#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;
}
/**
* Returns true if the singleton is instantiated.
*/
bool localizationUtils::isInstantiated() {
return (pinstance ? true : false);
}
localizationUtils::localizationUtils(){
initLangCodes();
setLocaleResource();
}
/**
* Destructor: releases the localization dll
*/
localizationUtils::~localizationUtils() {
if (localeResource) {
FreeLibrary(localeResource);
localeResource = NULL;
}
}
/*
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 = PRIMARYLANGID(GetUserDefaultUILanguage());
CString lang("en");
if (lId && langCodes[lId]) {
lang = langCodes[lId];
}
localeResource = LoadLibrary( libpath + TEXT("\\") + libname + lang + 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 + =
减小字号Ctrl + -
显示快捷键?