Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 21:06
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
(Solved) Gettext and C
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 14 Aug 2014, 15:22    Post subject:  (Solved) Gettext and C  

Hi.

I have a little knowledge of C and almost each little tool I've created using C, was based on a C example I've got from 01micko.

By now I need always to build two versions, one for DE and one for EN.

So I need to learn how to use gettext in C.

Can anybody show me a quick example of how to use gettext in C, or at least point me to some C source codes wherein gettext is used, so that I can examine the code?

Thanks,

RSH

_________________
LazY Puppy
RSH's DNA
SARA B.

Last edited by RSH on Thu 14 Aug 2014, 21:49; edited 1 time in total
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7797
Location: qld

PostPosted: Thu 14 Aug 2014, 19:47    Post subject:  

Hi RSH

Take a look at network_tray and some of the others that Barry originally wrote. rodin.s gettext'd them, I think with help of L18L. Don't pay too much attention to the actual C code, it needs work, but you can see the _(bla) format where the underscore flags the string to be translated. There is also relevant stuff in the 'compile' script(s).

http://distro.ibiblio.org/puppylinux/sources/ .. which is quite incomplete but there is network_tray under /n/ and a few others.

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 14 Aug 2014, 20:48    Post subject:  

Hi 01micko.

Thanks for the reply.

I have examined network_tray and included the necessary parts into my C code file. Gettext is installed and works - checked this by running Screeny, which appears in DE.

Though my C Application won't show in DE:
Code:
//#############################################################################
// System Tray Refresh Desktop Function
// 2014-08-14 RSH for LazY Puppy
//#############################################################################

// Include Files
#include <string.h>
#include <libintl.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <glib/gstdio.h>
#include <dirent.h>
#include <errno.h>
#define _(STRING)    gettext(STRING)

// Icons
GdkPixbuf *a_pixbuf;
GtkStatusIcon *tray_icon;

// Error Check on File Open
GError *gerror = NULL;

//#############################################################################
// Click Functions called from Menu
//#############################################################################

// Run /usr/local/bin/refresh_desktop
void  view_popup_menu_run_refreshdesktop (GtkWidget *menuitem, gpointer user_data)
{
    system("/usr/local/bin/refresh_desktop &");
}

//#############################################################################
// System Tray Icon
//#############################################################################

// Create Tray Icon
static GtkStatusIcon *create_tray_icon()
{
   tray_icon = gtk_status_icon_new();
   g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(view_popup_menu_run_refreshdesktop), NULL);
       g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(view_popup_menu_run_refreshdesktop), NULL);
   a_pixbuf=gdk_pixbuf_new_from_file("/usr/share/pixmaps/restore.png",&gerror);
   gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
   gtk_status_icon_set_tooltip(tray_icon, _("Refresh the Desktop"));
   gtk_status_icon_set_visible(tray_icon, TRUE);
   return tray_icon;
}

//#############################################################################
// Main Program Functions
//#############################################################################

// Main Program
int main(int argc, char **argv)
{
   gtk_init(&argc, &argv);

   setlocale( LC_ALL, "" );
   bindtextdomain( "refresh_my_desktop", "/usr/share/locale" );
   textdomain( "refresh_my_desktop" );

   tray_icon = create_tray_icon();
   gtk_main();
   return 0;
}

//#############################################################################
// End of System Tray Refresh Desktop Function
//#############################################################################


Here is how I did compile:
Code:
lxterminal -e gcc -o refresh_my_desktop refresh_my_desktop.c `pkg-config --libs --cflags gtk+-2.0`
xgettext --keyword="_" refresh_my_desktop.c -o refresh_my_desktop.pot


Content of the created .pot (.mo) file:
Code:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-08-15 02:39+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: refresh_my_desktop.c:55
msgid "Refresh the Desktop"
msgstr "Arbeitsfläche aktualisieren"


Note: msgstr "Arbeitsfläche aktualisieren" was edited after .pot creation, then made a .mo file from this and copied into /usr/share/locale/de/LC_MESSAGES.

Though the tool-tip still shows EN message, Refresh the Desktop.

What am I doing wrong here??? Crying or Very sad

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7797
Location: qld

PostPosted: Thu 14 Aug 2014, 21:31    Post subject:  

RSH wrote:
What am I doing wrong here??? Crying or Very sad


I dunno, but it works fine here.
Make sure
    you have de.po created from the .pot
    that UTF-8 is set for charset=
    compile with msgfmt de.po -o refresh_my_desktop.mo


(I just changed icon for my convenience)
rsh_app.png
 Description   
 Filesize   22.79 KB
 Viewed   79 Time(s)

rsh_app.png


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 14 Aug 2014, 21:47    Post subject:  

Quote:
Make sure

you have de.po created from the .pot
that UTF-8 is set for charset=
compile with msgfmt de.po -o refresh_my_desktop.mo

UTF-8 was the missing point.

Works now over here as well. Very Happy

So I'm prepared now...

Thank you very much! Cool

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0609s ][ Queries: 12 (0.0037s) ][ GZIP on ]