Re: [poedit-users] getting started

"Werner F. Bruhin" <[email protected]>
Newsgroups gmane.editors.poedit.user
Message-ID <[email protected]>
Hi Christian,

I am no good in C++ but as I use wxPython (a Python wrapper of wxWidget) 
I might have some pointers for you.

Christian Buhtz wrote:

>Now I got this directory structure with files
>
>../OctopusBackup (that is the working dir!)
>../OctopusBackup/locales/de/ob.mo
>../OctopusBackup/locales/de/ob.po
>../OctopusBackup/locales/fr/ob.mo
>../OctopusBackup/locales/fr/ob.po
>  
>
You are aware that you only need to distribute the .mo?  You might also 
want to change "locales" to "locale" which seems to be the standard 
used, but then this is nitpicking :-) .

>
>That is my code with wxWidgest.
><code>
>bool OBApp::OnInit()
>{
>    static const wxLanguage langIds[] =
>    {
>        wxLANGUAGE_DEFAULT,
>        wxLANGUAGE_FRENCH,
>        wxLANGUAGE_GERMAN,
>        wxLANGUAGE_ENGLISH
>    };
>
>    locale_.AddCatalogLookupPathPrefix(_T("locales"));
>    locale_.AddCatalog(_T("ob"));
>    locale_.Init(langIds[1]);
>  
>
Do you really want to translate "locales" and "ob"?  Shouldn't does be 
just strings - I guess they are after the translation has gone through, 
but not sure if this should work.  But looking at my code I guess it 
could be the "./" which is missing in yours.

With wxPython I do:
# Define the "_" method, pointing it to wxPython's GetTranslation method
__builtins__._ = wx.GetTranslation
# Define the location of the Machine Object language files
wx.Locale_AddCatalogLookupPathPrefix('./locale')

class BoaApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()

        self.locale = wx.Locale(wx.LANGUAGE_GERMAN,
                        wx.LOCALE_LOAD_DEFAULT | wx.LOCALE_CONV_ENCODING)
        self.locale.AddCatalog('yourapp')

To switch language:
    def SetLang(self, lang):
        if lang in ['de']:
            if hasattr(self, 'locale'):
                del self.locale
            self.locale = wx.Locale(wx.LANGUAGE_GERMAN,
                        wx.LOCALE_LOAD_DEFAULT | wx.LOCALE_CONV_ENCODING)
            self.locale.AddCatalog('yourapp')
            self.aConfig.Write(key='Language', value='de')
        else:
            if hasattr(self, 'locale'):
                del self.locale
            self.locale = wx.Locale(wx.LANGUAGE_ENGLISH,
                        wx.LOCALE_LOAD_DEFAULT | wx.LOCALE_CONV_ENCODING)
            self.locale.AddCatalog('yourapp')
            self.aConfig.Write(key='Language', value='en')

Note that the above only changes texts from "yourapp", any texts coming 
from wxPython require an application restart.

If it would be useful I can send you a small wxPython app which demos 
the i18n.

Hope this helps
Werner

>    pMainFrame_ = new OBMainFrame( _(_T("Hello World")), wxPoint(50,50),
>wxSize(450,340), this );
>
>    pMainFrame_->AddMessage("OB started...");
>    pMainFrame_->AddMessage(core_.GetCurrentDateString());
>
>    return TRUE;
>}
></code>
>
>I do not know why it does not work. It should do I think. :)
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by xPML, a groundbreaking scripting language
>that extends applications into web and mobile media. Attend the live webcast
>and join the prime developer group breaking into this new coding territory!
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
>_______________________________________________
>Poedit-users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/poedit-users
>
>
>  
>




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.