bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loading getext catalogs from mutliple domains?


From: Stephen Kelly
Subject: Loading getext catalogs from mutliple domains?
Date: Wed, 14 Jul 2010 18:14:07 +0200
User-agent: KNode/4.3.2

Hi,

Not certain I am using the right terminology here. 

I am looking for a way to specify multiple locations where translations 
should be loaded from, for example, /usr/share/locale and 
/usr/share/apps/kmail/themes/mytheme/ or 
~/.kde/share/apps/kmail/themes/mytheme

The reason is I have a string templating system which allows 3rd parties to 
create themes. My system is written in Qt and based on the Django template 
system[1]. One theme might contain something like

<html>
<table>
<tr><td>{{ _("Subject") }}</td><td>{{ message.subject }}</td></tr>
<tr><td>{% i18nc "The date an email arrived" "Date" %}</td><td>{{ 
message.date }}</td></tr>
</table>

etc. Things like plurals and context disambiguation messages work already. 
However, a 3rd party theme might contain translatable strings like "Spam 
level" in another line. The example is slightly contrived because that 
string would already be in the app. It is conceivable though that a 3rd 
party would want to introduce strings not already present in the 
application.

I thought that one way to do that would be to look for messages from the 
theme such as in 
~/.kde/share/apps/kmail/themes/mytheme/de_DE/LC_MESSAGES/mytheme.mo. The 
third party would be responsible for providing the .mo files obviously.

The way I tried to do that was with multiple calls to bindtextdomain, but 
that does not work in my test application.

I use the locale en_IN because the spanish one did not work for some reason. 
I don't know why. If I comment the bindtextdomain2 and textdomain2 calls, 
the app is translated, but strace tells me there is no attempt to open .mo 
files from 2 locations. Even if I change the text to "hello wd" so that the 
string is not found in the first .mo file it does not look in the second 
location. Is what I want to do possible?

All the best,

Steve.

cat >hellogt.cxx <<EOF
// hellogt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
#include <cstdlib>
int main (){
    char* cwd = getenv("PWD");
    std::cout << "getenv(PWD): " << (cwd?cwd:"NULL") << std::endl;
    char* l = getenv("LANG");
    std::cout << "getenv(LANG): " << (l?l:"NULL") << std::endl;
    char* s = setlocale(LC_ALL, "");
    std::cout << "setlocale(): " << (s?s:"NULL") << std::endl;
    std::cout << "bindtextdomain(): " << bindtextdomain("hellogt", cwd) << 
std::endl;
    char *otherdir = getenv("HOME");
    std::cout << "otherdir: " << otherdir << std::endl;
    std::cout << "bindtextdomain2(): " << bindtextdomain("hellogt2", 
otherdir) << std::endl;
    std::cout << "textdomain(): " << textdomain( "hellogt") << std::endl;
    std::cout << "textdomain2(): " << textdomain( "hellogt2") << std::endl;
    std::cout << gettext("hello, world!") << std::endl;
}
EOF
g++ -ohellogt hellogt.cxx
xgettext -d hellogt -o hellogt.pot hellogt.cxx
msginit --no-translator -l en_IN -o hellogt_spanish.po -i hellogt.pot
sed --in-place hellogt_spanish.po --expression='/#: /,$ s/""/"hola mundo"/'
sed --in-place hellogt_spanish.po --expression='s/PACKAGE VERSION/hellogt 
1.0/'
mkdir -p ./en_IN/LC_MESSAGES
msgfmt -c -v -o ./en_IN/LC_MESSAGES/hellogt.mo hellogt_spanish.po
ls -l $PWD/en_IN/LC_MESSAGES/hellogt.mo
LANG=en_IN ./hellogt
LANG=en_IN strace -e trace=open ./hellogt


[1] http://www.grantlee.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]