gitktrans-i18n.c

Go to the documentation of this file.
00001 
00012 #define GITK_LIB_C
00013 #define GITK_TRANS_I18N_C
00014 
00015 #include "gitkincludes.h"
00016 
00017 
00019 #define giml_ctrl_text N_("Okay");
00020 #undef giml_ctrl_text
00021 #define giml_ctrl_text N_("Cancel");
00022 #undef giml_ctrl_text
00023 #define giml_ctrl_text N_("Apply");
00024 #undef giml_ctrl_text
00025 #define giml_ctrl_text N_("Help");
00026 #undef giml_ctrl_text
00027 
00028 
00036 static void gitk_dialog_trans_i18n_walker(xmlNodePtr cur) {
00037   xmlNodePtr i18n,parent,next;
00038   xmlChar *pre_i18n,*post_i18n,*str,*domain;
00039 
00040   while(cur!=NULL) {
00041     next=cur->next;
00042     if(xmlNodeIsText(cur)) {
00043       //-- get i18n (parent of this)
00044       i18n=cur->parent;
00045       //-- read contents, if it is child of i18n
00046       if(!strncmp(i18n->name,"text",4) && i18n->ns && !strncmp(i18n->ns->href,I18N_NS_URL,strlen(I18N_NS_URL))) {
00047         //-- get parent of i18n
00048         parent=i18n->parent;
00049         if((pre_i18n=xmlNodeGetContent(cur))) {
00050           //gitk_log1("from '%s'",pre_i18n);
00051           if((domain=xmlGetProp(i18n,"domain"))) {
00052             //gitk_log1("  domain=\"%s\"",domain);
00053             str=dgettext(domain,pre_i18n);
00054             xmlFree(domain);
00055           }
00056           else {
00057             str=dgettext(client_package_name,pre_i18n);
00058             //gitk_log3("  domain=\"%s\" \"%s\"->\"%s\"",client_package_name,pre_i18n,str);
00059           }
00060           //if(str==pre_i18n) str=dgettext(renderer_package_name,pre_i18n);
00061           //if(str==pre_i18n) str=dgettext(PACKAGE,pre_i18n);
00062           post_i18n=strdup(str);
00063           //gitk_log1("to '%s'",post_i18n);
00064           free(pre_i18n);
00065           xmlUnlinkNode(cur);xmlFreeNode(cur);
00066           xmlUnlinkNode(i18n);xmlFreeNode(i18n);
00067           if(post_i18n) {
00068             xmlNodePtr new_node,new_snode;
00069             if((new_snode=xmlNewText(post_i18n))) {
00070               if(!(new_node=xmlAddChild(parent,new_snode))) { gitk_log("add failed"); }
00071             }
00072             else { gitk_log("create failed"); }
00073             free(post_i18n);
00074           }
00075           cur=NULL;
00076         }
00077       }
00078     }
00079     //else { gitk_log1("cur->name '%s'",cur->name); }
00080     //-- recurse into node childen
00081     if(cur) {
00082       if(cur->children!=NULL) gitk_dialog_trans_i18n_walker(cur->children);
00083       cur=next;
00084     }
00085   }
00086 }
00087 
00088 
00094 xmlDocPtr gitk_dialog_trans_i18n(xmlDocPtr const src) {
00095   xmlDocPtr res=NULL;
00096   
00097   g_assert(src);
00098   //gitk_log1("before running i18n via '%s'",client_package_name);
00099   //gitk_dialog_trans_i18n_walker(xmlDocGetRootElement(src));
00100   //return(src);
00101   
00102   if(!(res=xsltApplyStylesheet(xsl_i18n,src,NULL))) {
00103     gitk_err("failed to apply stylesheet (i18n.xsl)");
00104   }
00105   // DEBUG
00106   //gitk_dialog_trans_i18n_walker(xmlDocGetRootElement(res));
00107   // DEBUG
00108   return(res);
00109 }
00110 
00111 
00112 void *xsltExtInit_i18n(xsltTransformContextPtr ctxt, const xmlChar *URI) {
00113   gitk_log_intro();
00114   //gitk_log1(">>>>>>>>>> URI=\"%s\"",URI);
00115   if(xsltRegisterExtFunction(ctxt,"gettext",URI,xmlXPathEvalFunc_i18n_gettext)) {
00116     gitk_err("failed to register extension function (i18n)");
00117   }
00118   gitk_log_outro();
00119   return(NULL);
00120 }
00121 
00122 void xsltExtShutdown_i18n(xsltTransformContextPtr ctxt, const xmlChar *URI, void *data) {
00123 }
00124 
00125 void xmlXPathEvalFunc_i18n_gettext(xmlXPathParserContextPtr ctxt, int nargs) {
00126   guint i,j,itemct;
00127   xmlChar *elem;
00128   xmlChar *pre_i18n,*post_i18n,*str,*domain;
00129   xmlXPathObjectPtr xpoptr;
00130   xmlNodeSetPtr items;
00131   xmlNodePtr i18n,parent,child;
00132   
00133   //gitk_log_intro();
00134   
00135   //gitk_log1(">>>>>>>>>> nargs=%d",nargs);
00136   for(i=0;i<nargs;i++) {
00137     xpoptr=valuePop(ctxt);
00138     items=(xmlNodeSetPtr)xpoptr->nodesetval;
00139     itemct=xmlXPathNodeSetGetLength(items);
00140     //gitk_log1(">>>>>>>>>>>> items=%d",itemct);
00141     for(j=0;j<itemct;j++) {
00142       i18n=xmlXPathNodeSetItem(items,j);
00143       //-- dump node name
00144       //gitk_log1("%s",i18n->name);
00145       if(!strncmp(i18n->name,"text",4) && i18n->ns && !strncmp(i18n->ns->href,I18N_NS_URL,strlen(I18N_NS_URL))) {
00146         //-- get parent of i18n
00147         parent=i18n->parent;
00148         child=i18n->children;
00149         if((pre_i18n=xmlNodeGetContent(child))) {
00150           //gitk_log1("from '%s'",pre_i18n);
00151           if((domain=xmlGetProp(i18n,"domain"))) {
00152             //gitk_log1("  domain=\"%s\"",domain);
00153             str=dgettext(domain,pre_i18n);
00154             xmlFree(domain);
00155           }
00156           else {
00157             str=dgettext(client_package_name,pre_i18n);
00158             //gitk_log3("  domain=\"%s\" \"%s\"->\"%s\"",client_package_name,pre_i18n,str);
00159           }
00160           //if(str==pre_i18n) str=dgettext(renderer_package_name,pre_i18n);
00161           //if(str==pre_i18n) str=dgettext(PACKAGE,pre_i18n);
00162           post_i18n=strdup(str);
00163           //gitk_log1("to '%s'",post_i18n);
00164           free(pre_i18n);
00165           xmlUnlinkNode(child);xmlFreeNode(child);
00166           xmlUnlinkNode(i18n);xmlFreeNode(i18n);
00167           if(post_i18n) {
00168             xmlNodePtr new_node,new_snode;
00169             if((new_snode=xmlNewText(post_i18n))) {
00170               if(!(new_node=xmlAddChild(parent,new_snode))) { gitk_log("add failed"); }
00171             }
00172             else { gitk_log("create failed"); }
00173             free(post_i18n);
00174           }
00175         }
00176       }
00177     }
00178     valuePush(ctxt,xpoptr);
00179   }
00180   
00181   //gitk_log_outro();
00182 }

Generated on Thu Oct 28 10:59:15 2004 for gitk by doxygen 1.3.6