Hi, everyone.

I'm trying to use gettext in complicate application. It consists of C++ code wrapped in python interface via sip. Is it possible to bind textdomain once in python code, and don't use this function in C++ code?
Now I have to use this function twice like is shown below.

python main:

import gettext
gettext.bindtextdomain(DOMAIN, LOCALEDIR)

and wrapped C++ code:

#include <libintl.h>
bindtextdomain (DOMAIN, LOCALEDIR);
textdomain (DOMAIN);

Excuse me for my english.

I found answer without assistance.
It's not possible now, because of python module gettext using it's own gettext tools.
But in the past python gettext was based on C-gettext library.

problem is simply resolved by using Pyrex
In the module below I use C and Python bindtextdomain\textdomain at the same time. Therefore it's possible to call functions from this module once in my source code.

To compile this module in shared library see this .

#!/usr/bin/env python

# import stanard python gettext
import gettext

# extern C gettext functions
cdef extern from "libintl.h":
    char * bindtextdomain(char * DOMAIN, char * LOCALEDIR)
    char * textdomain(char * DOMAIN)

def bindtextdomain(DOMAIN, LOCALEDIR):
    bindtextdomain(DOMAIN, LOCALEDIR)   #C function call
    return gettext.bindtextdomain(DOMAIN, LOCALEDIR)  #Python function call

def textdomain(DOMAIN):
    return gettext.textdomain(DOMAIN)

def _(msg):
    if isinstance(msg,unicode):
        return (gettext.gettext(msg)).encode("utf-8")
        return (gettext.gettext(unicode(msg,"utf-8"))).encode("utf-8")

Sorry, previous piece of code was incorrect, because of name conflicts.
The right code looks like:

#!/usr/bin/env python

# import stanard python gettext
from gettext import bindtextdomain as Python_bindtextdomain
from gettext import textdomain as Python_textdomain
from gettext import gettext

# extern C gettext functions
cdef extern from "libintl.h":
    char * C_bindtextdomain "bindtextdomain" (char * DOMAIN, char * LOCALEDIR)
    char * C_textdomain "textdomain" (char * DOMAIN)

def bindtextdomain(DOMAIN, LOCALEDIR):
    C_bindtextdomain(DOMAIN, LOCALEDIR)
    return Python_bindtextdomain(DOMAIN, LOCALEDIR)

def textdomain(DOMAIN):
    return Python_textdomain(DOMAIN)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.