TranslationModules - Let CEGUI translate your strings

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

Hanmac
Just popping in
Just popping in
Posts: 7
Joined: Thu Jul 07, 2011 19:45

TranslationModules - Let CEGUI translate your strings

Postby Hanmac » Wed Aug 31, 2011 10:39

hay i had the idea to add translation modules into cegui for translating the strings in the Windows and Widgets

Example usage without TranslationModule:
if you want to make your menu multi language, you must change the setted text every time you change the language
this could be very annoying

Example usage with TranslationModule:
you change the language and the Windows look after translations for the new language in the TranslationModule which is setted to the system,
so you must not change the Text values of the windows.

Code examples:
  • gettext - which reads the po files, for setting the language, uselocale is used for tread-safe

    Code: Select all

    TranslationSystem* trans = new GettextTranslationSystem;
    trans->setProperty("Domain","cegui");
    trans->setProperty("DomainDirectory",".");
    std::cout << trans->translate("hello how are you?","de"); //"Wie geht es dir?"

  • TMX xml-files - an file that holds multible translations you can see the spec there

    Code: Select all

    TranslationSystem* trans = new TmxTranslationSystem;
    static_cast<TmxTranslationSystem*>(trans)->handleFile("translations.tmx");
    std::cout << trans->translate("hello how are you?","de"); //"Wie geht es dir?"
  • when using with system you could do that (after you use setTranslationSystem)

    Code: Select all

    std::cout << System::getSingleton().getTranslationSystem().translate("hello how are you?","de"); //"Wie geht es dir?"

latest branch on bitbucket

Code: Select all

/***********************************************************************
   filename:    CEGUITranslationModule.h
   created:   8/6/2011
   author:      Hans 'Hanmac' Mackowiak
   
   purpose:   Defines abstract base class for translation modules
*************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
 *
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 ***************************************************************************/
#ifndef _CEGUITranslationModule_h_
#define _CEGUITranslationModule_h_

#include "CEGUIBase.h"
#include "CEGUIPropertyHelper.h"
#include "CEGUIString.h"
#include <map>

// Start of CEGUI namespace section
namespace CEGUI
{
/*!
\brief
    Abstract class that defines the required interface for all resource provider sub-classes.

*/
class CEGUIEXPORT TranslationModule :
    public AllocatedObject<TranslationModule>
{
public:
    /*************************************************************************
        Construction and Destruction
    *************************************************************************/
    /*!
    \brief
        Constructor for the TranslationModule class
    */
    TranslationModule() { }

    /*!
    \brief
        Destructor for the TranslationModule class
    */
    virtual ~TranslationModule(void) { }

    typedef std::map<String,String> Param;
    virtual const String translate(const String &key,const String &lang,Param param = Param()) = 0;
    template<typename T>
    const String translate(const String &key,const String &lang,const String &paramkey,const T paramvalue)
    {
        Param param;
        param.insert(std::make_pair(paramkey,PropertyHelper<T>::toString(paramvalue)));
        return translate(key,lang,param);
    }
    template<typename T1,typename T2>
    const String translate(const String &key,const String &lang,const String &paramkey1,const T1 paramvalue1,const String &paramkey2,const T2 paramvalue2)
    {
        Param param;
        param.insert(std::make_pair(paramkey1,PropertyHelper<T1>::toString(paramvalue1)));
        param.insert(std::make_pair(paramkey2,PropertyHelper<T2>::toString(paramvalue2)));
        return translate(key,lang,param);
    }
    template<typename T1,typename T2,typename T3>
    const String translate(const String &key,const String &lang,const String &paramkey1,const T1 paramvalue1,const String &paramkey2,const T2 paramvalue2,const String &paramkey3,const T3 paramvalue3)
    {
        Param param;
        param.insert(std::make_pair(paramkey1,PropertyHelper<T1>::toString(paramvalue1)));
        param.insert(std::make_pair(paramkey2,PropertyHelper<T2>::toString(paramvalue2)));
        param.insert(std::make_pair(paramkey3,PropertyHelper<T3>::toString(paramvalue3)));
        return translate(key,lang,param);
    }
    virtual bool isTranslatable(const String &key,const String &lang) const = 0;

protected:

};

} // End of  CEGUI namespace section

#endif   // end of guard _CEGUITranslationModule_h_

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: TranslationModules - Let CEGUI translate your strings

Postby Kulik » Tue Sep 06, 2011 18:23

Could you please add how this is to be used with layouts and properties? How will the syntax look like in .layout files and .looknfeel files, possibly others (this might also apply to .animation files and maybe others as well).

Hanmac
Just popping in
Just popping in
Posts: 7
Joined: Thu Jul 07, 2011 19:45

Re: TranslationModules - Let CEGUI translate your strings

Postby Hanmac » Wed Sep 07, 2011 04:51

i planed that you does noz need to change it in the layout files because it use the string, and try to translate them

or add it to layout-Property like:

Code: Select all

<Property name="Text" value="English Text" xml:lang="en"/>
<Property name="Text" value="German Text" xml:lang="de"/>


but this function is not implmented


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests