GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 01, 2014 12:41 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Menus with context-based translations possible?
PostPosted: Sun Mar 18, 2012 3:11 pm 
Offline
Familiar Face

Joined: Sun May 24, 2009 9:03 pm
Posts: 13
I have a problem with a menu where I would like to use context-based translations -
I have the menu defined as an array of GtkActionEntries in the style of:

Code:
static GtkActionEntry sMenuActions[] =
{
   { "FileMenuAction", NULL, N_("_File") },
   { "EditMenuAction", NULL, N_("_Edit") },
   { "ViewMenuAction", NULL, N_("_View") },
   { "HelpMenuAction", NULL, N_("_Help") },
   
   { "OpenProjectAction", GTK_STOCK_OPEN, NC_("File|","_Open project"), "<control>O", N_("Open Project"), G_CALLBACK(openproject_menu_cb) },
   { "SaveProjectAction", GTK_STOCK_SAVE, NC_("File|","_Save project"), "<control>S", N_("Save Project"), G_CALLBACK(saveproject_menu_cb) },
   {


and add the menu to the window using code like this:

Code:
   
gtk_action_group_set_translation_domain(sActionGroup,PACKAGE);
gtk_action_group_add_actions(sActionGroup, sMenuActions, sNumMenuActions, NULL);
gtk_ui_manager_insert_action_group(sGtkUIManager, sActionGroup, 0);
if (gtk_ui_manager_add_ui_from_string(sGtkUIManager, sMenuDefXML, strlen(sMenuDefXML), &tempErr) == 0) {


But I don't get the context-based strings working - Is it even possible?
The non-context based strings (using N_) work just fine, but it seems like the NC_-ones doesn't.

I have noted that gtk_action_group_set_translation_domain () mentions that it uses g_dgettext() for translating, which only handles non-context-based strings - Is it possible to use both styles of translatable strings in a menu?


Top
 Profile  
 
 Post subject: Re: Menus with context-based translations possible?
PostPosted: Sun Mar 18, 2012 9:08 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
How come you are using the N based macros? Allright I don't know anything about GtkActions so you're probably using it and the N qualifier for good reasons.
As a stab you might be able to get around your issue using gtk_action_group_set_translate_func(). It may allow you to use the context specific function g_dpgettext2 rather than defaulting to g_dgettext. There was something in the documentation about | as a context seperator being depreciated too.


Top
 Profile  
 
 Post subject: Re: Menus with context-based translations possible?
PostPosted: Sun Mar 18, 2012 9:59 pm 
Offline
Familiar Face

Joined: Sun May 24, 2009 9:03 pm
Posts: 13
Paul Childs wrote:
How come you are using the N based macros? Allright I don't know anything about GtkActions so you're probably using it and the N qualifier for good reasons.

Yeah, if I use _("") in the menu definitions, I get

src/gui.c:117: error: initializer element is not constant
src/gui.c:117: error: (near initialization for ‘sMenuActions[0].label’)

, and the documentation for the N_ function is:

Gtk Documentation wrote:
Only marks a string for translation. This is useful in situations where the translated strings can't be directly used, e.g. in string array initializers. To get the translated string, call gettext() at runtime.

http://developer.gnome.org/glib/stable/ ... ml#N-:CAPS

Paul Childs wrote:
As a stab you might be able to get around your issue using gtk_action_group_set_translate_func(). It may allow you to use the context specific function g_dpgettext2 rather than defaulting to g_dgettext. There was something in the documentation about | as a context seperator being depreciated too.

I have given this a shot, but I don't have any luck with it... If someone has some links to examples or other code, it would be very much appreciated.


Top
 Profile  
 
 Post subject: Re: Menus with context-based translations possible?
PostPosted: Tue Mar 20, 2012 10:39 am 
Offline
Familiar Face

Joined: Sun May 24, 2009 9:03 pm
Posts: 13
Alright, I have managed to find a solution, but it isn't really optimal - I use NC_("","") in the GtkActionEntry array to mark the messages as translatable with context, but then I have the strings listed in another array again, to have them as input to g_dpgettext2 ...

It works, but unfortunately it means listing the strings twice...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group