Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - GUI translation
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

GUI translation

 Post Reply Post Reply
Author
Message
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Topic: GUI translation
    Posted: 15 January 2018 at 1:26am
Hello,

During working on localization issues in Codejock library I fonund that to apply translation for Ribbon Backstage Page we need create it with calling CreateIndirect(). With RibbonSample this looks like:
CMainFrame::CreateBackstage()
{
.....
    if (!m_pagePrint.GetSafeHwnd())
    {
        m_pagePrint.CreateIndirect(XTPResourceManager()->LoadDialogTemplate(CXTPRibbonBackstagePagePrint::IDD), this);
I have added such example in RibbonSample.
For using localized resources DLL you can use next code:
struct {
    WORD wLanguage;
    LPCTSTR lpszEncoding;
    LPCTSTR lpszCaption;
    LPCTSTR lpszDLLName;
}
encoding[] = 
{
    {MAKELANGID(LANG_ARABIC,    SUBLANG_ARABIC_SAUDI_ARABIA),  _T("windows-1256"), _T("Arabic (Saudi Arabia)"), _T("ResourceArSa")},
    {MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT),              _T("windows-1251"), _T("Bulgarian"),             _T("ResourceBg")},
    {MAKELANGID(LANG_CZECH,     SUBLANG_DEFAULT),              _T("windows-1250"), _T("Czech"),                 _T("ResourceCs")},
    {MAKELANGID(LANG_DANISH,    SUBLANG_DEFAULT),              _T("windows-1252"), _T("Danish"),                _T("ResourceDa")},
    {MAKELANGID(LANG_GERMAN,    SUBLANG_GERMAN),               _T("windows-1252"), _T("German (Germany)"),      _T("ResourceDe")},
    {MAKELANGID(LANG_GREEK,     SUBLANG_DEFAULT),              _T("windows-1253"), _T("Greek"),                 _T("ResourceEl")},    // 5
    {MAKELANGID(LANG_ENGLISH,   SUBLANG_ENGLISH_US),           _T("windows-1252"), _T("English (United States)"),_T("ResourceEn")},
    {MAKELANGID(LANG_SPANISH,   SUBLANG_SPANISH_MODERN),       _T("windows-1252"), _T("Spanish (Spain - Modern Sort)"),_T("ResourceEs")},
    {MAKELANGID(LANG_ESTONIAN,  SUBLANG_DEFAULT),              _T("windows-1257"), _T("Estonian"),              _T("ResourceEt")},
    {MAKELANGID(LANG_FINNISH,   SUBLANG_DEFAULT),              _T("windows-1252"), _T("Finnish"),               _T("ResourceFi")},
    {MAKELANGID(LANG_FRENCH,    SUBLANG_FRENCH),               _T("windows-1252"), _T("French (France)"),       _T("ResourceFr")},    //10
    {MAKELANGID(LANG_HEBREW,    SUBLANG_DEFAULT),              _T("windows-1255"), _T("Hebrew"),                _T("ResourceHe")},
    {MAKELANGID(LANG_CROATIAN,  SUBLANG_DEFAULT),              _T("windows-1250"), _T("Croatian"),              _T("ResourceHr")},
    {MAKELANGID(LANG_HUNGARIAN, SUBLANG_DEFAULT),              _T("windows-1250"), _T("Hungarian"),             _T("ResourceHu")},
    {MAKELANGID(LANG_ITALIAN,   SUBLANG_ITALIAN),              _T("windows-1252"), _T("Italian (Italy)"),       _T("ResourceIt")},
    {MAKELANGID(LANG_JAPANESE,  SUBLANG_DEFAULT),              _T("shift-jis"),    _T("Japanese"),              _T("ResourceJa")},    //15
    {MAKELANGID(LANG_KOREAN,    SUBLANG_DEFAULT),              _T("ks_c_5601"),    _T("Korean"),                _T("ResourceKo")},
    {MAKELANGID(LANG_LITHUANIAN,SUBLANG_LITHUANIAN),           _T("windows-1257"), _T("Lithuanian"),            _T("ResourceLt")},
    {MAKELANGID(LANG_LATVIAN,   SUBLANG_DEFAULT),              _T("windows-1257"), _T("Latvian"),               _T("ResourceLv")},
    {MAKELANGID(LANG_DUTCH,     SUBLANG_DUTCH),                _T("windows-1252"), _T("Dutch"),                 _T("ResourceNl")},
    {MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL),     _T("windows-1252"), _T("Norwegian (Bokmal)"),    _T("ResourceNo")},    //20
    {MAKELANGID(LANG_POLISH,    SUBLANG_DEFAULT),              _T("windows-1250"), _T("Polish"),                _T("ResourcePl")},
    {MAKELANGID(LANG_PORTUGUESE,SUBLANG_PORTUGUESE),           _T("windows-1252"), _T("Portuguese (Portugal)"), _T("ResourcePt")},
    {MAKELANGID(LANG_PORTUGUESE,SUBLANG_PORTUGUESE_BRAZILIAN), _T("windows-1252"), _T("Portuguese (Brazil)"),   _T("ResourcePtBr")},
    {MAKELANGID(LANG_ROMANIAN,  SUBLANG_DEFAULT),              _T("windows-1250"), _T("Romanian"),              _T("ResourceRo")},
    {MAKELANGID(LANG_RUSSIAN,   SUBLANG_DEFAULT),              _T("windows-1251"), _T("Russian"),               _T("ResourceRu")},    //25
    {MAKELANGID(LANG_SLOVAK,    SUBLANG_DEFAULT),              _T("windows-1250"), _T("Slovak"),                _T("ResourceSk")},
    {MAKELANGID(LANG_SLOVENIAN, SUBLANG_DEFAULT),              _T("windows-1250"), _T("Slovenian"),             _T("ResourceSl")},
    {MAKELANGID(LANG_SERBIAN,   SUBLANG_SERBIAN_LATIN),        _T("windows-1250"), _T("Serbian"),               _T("ResourceSr")},
    {MAKELANGID(LANG_SWEDISH,   SUBLANG_DEFAULT),              _T("windows-1252"), _T("Swedish"),               _T("ResourceSv")},
    {MAKELANGID(LANG_THAI,      SUBLANG_DEFAULT),              _T("windows-874"),  _T("Thai"),                  _T("ResourceTh")},    //30
    {MAKELANGID(LANG_TURKISH,   SUBLANG_DEFAULT),              _T("windows-1254"), _T("Turkish"),               _T("ResourceTr")},
    {MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT),              _T("windows-1251"), _T("Ukrainian "),            _T("ResourceUk")},
    {MAKELANGID(LANG_CHINESE,   SUBLANG_CHINESE_SIMPLIFIED),   _T("gb2312"),       _T("Chinese (PRC)"),         _T("ResourceZhCn")},
    {MAKELANGID(LANG_CHINESE,   SUBLANG_CHINESE_TRADITIONAL),  _T("big5"),         _T("Chinese (Taiwan)"),      _T("ResourceZhTw")}
};

#include <locale.h>

BOOL CRibbonSampleApp::InitInstance()
{

//hardcoded language choosing
    const int kk = 34;     //any
    //const int kk = 4;    //german
    //const int kk = 5;    //greek
    LCID Locale = encoding[kk].wLanguage;
    LPCTSTR szLocale = encoding[kk].lpszCaption;
    LPCTSTR    szFileName = encoding[kk].lpszDLLName;

// get application path    
    CString strPath;
    VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, strPath.GetBufferSetLength(_MAX_PATH), _MAX_PATH));
    strPath.ReleaseBuffer();
            
    int nIndex  = strPath.ReverseFind(_T('\\'));
    if (nIndex > 0) strPath = strPath.Left(nIndex + 1); else strPath.Empty();
            
    strPath = strPath + _T("Translations\\ToolkitPro.") + szFileName + _T(".dll");

//set resource file for strings
    XTPResourceManager()->SetResourceManager(new CXTPResourceManager());
    XTPResourceManager()->SetResourceFile(strPath);
        
    ::SetThreadLocale(MAKELCID(Locale, SORT_DEFAULT)); 
    ::_tsetlocale(LC_ALL, szLocale); 

//test loading resources
    //CString strTitle;
    //XTPResourceManager()->LoadString(&strTitle, XTP_ID_RIBBONCONTROLQUICKACCESS);

Translations are saved in folder 'res\Resource_**.rc' for some controls, for example Calendar
c:\Program Files (x86)\Codejock Software\MFC\Xtreme ToolkitPro v18.0.1\Source\Calendar\res\Resource_zh_TW.rc
These .rc files should be opened with codepage as specified at the begining of every file
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

then it can be compiled to separate DLL for every language by building project
c:\Program Files (x86)\Codejock Software\MFC\Xtreme ToolkitPro v18.2.0\Workspace\Resource\Resource.dsw

If you know any issues with translations please write here or on support.codejock.com

Regards,
 Oleksandr Lebed
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.