unsigned char *get_text_translation(unsigned char *text, struct terminal *term) { unsigned char **current_tra; struct conv_table *conv_table; unsigned char *trn; int ch = term ? term->spec->charset : 0; if (is_direct_text(text)) return text; if ((current_tra = translation_array[current_language][ch])) { unsigned char *tt; if ((trn = current_tra[text - dummyarray])) return trn; tr: if (!(tt = translations[current_language].t[text - dummyarray].name)) { trn = stracpy(translation_english[text - dummyarray].name); } else { conv_table = get_translation_table(current_lang_charset, ch); trn = convert_string(conv_table, tt, strlen(tt)); } current_tra[text - dummyarray] = trn; } else { if (current_lang_charset && ch != current_lang_charset) { current_tra = translation_array[current_language][ch] = mem_alloc(sizeof (unsigned char **) * T__N_TEXTS); memset(current_tra, 0, sizeof (unsigned char **) * T__N_TEXTS); goto tr; } if (!(trn = translations[current_language].t[text - dummyarray].name)) { trn = translations[current_language].t[text - dummyarray].name = translation_english[text - dummyarray].name; /* modifying translation structure */ } } return trn; }
/*This is used to display the items in the menu*/ static unsigned char *block_type_item(struct terminal *term, void *data, int x) { unsigned char *txt, *txt1; struct conv_table *table; struct block* item=(struct block*)data; if ((struct list*)item==(&blocks)) return stracpy(_(TEXT_(T_BLOCK_LIST),term)); txt=stracpy(item->url); /*I have no idea what this does, but it os copied from working code in types.c*/ table=get_translation_table(blocks_ld.codepage,term->spec->charset); txt1=convert_string(table,txt,(int)strlen(cast_const_char txt),NULL); mem_free(txt); return txt1; }
/** Convert a STRING XTextProperty to a string in the specified codepage. * * @return the string that the caller must free with mem_free(), * or NULL on error. */ static unsigned char * xprop_to_string(Display *display, const XTextProperty *text_prop, int to_cp) { int from_cp; char **list = NULL; int count = 0; struct conv_table *convert_table; unsigned char *ret = NULL; /* <X11/Xlib.h> defines X_HAVE_UTF8_STRING if * Xutf8TextPropertyToTextList is available. * * The X...TextPropertyToTextList functions return a negative * error code, or Success=0, or the number of unconvertible * characters. Use the result even if some characters were * unconvertible, because convert_string() can be lossy too, * and it seems better to restore an approximation of the * original title than to restore a default title that may be * entirely different. */ #if defined(CONFIG_UTF8) && defined(X_HAVE_UTF8_STRING) from_cp = get_cp_index((const unsigned char *)"UTF-8"); if (Xutf8TextPropertyToTextList(display, text_prop, &list, &count) < 0) return NULL; #else /* !defined(X_HAVE_UTF8_STRING) || !defined(CONFIG_UTF8) */ from_cp = get_cp_index((const unsigned char *)"System"); if (XmbTextPropertyToTextList(display, text_prop, &list, &count) < 0) return NULL; #endif /* !defined(X_HAVE_UTF8_STRING) || !defined(CONFIG_UTF8) */ convert_table = get_translation_table(from_cp, to_cp); if (count >= 1 && convert_table) ret = convert_string(convert_table, (unsigned char *)list[0], strlen((const char *)list[0]), to_cp, CSM_NONE, NULL, NULL, NULL); XFreeStringList(list); return ret; }
/* Puts url into the block list */ static void block_edit_done(void *data) { /*Copied from types.c*/ struct dialog *d=(struct dialog*)data; struct block *item=(struct block *)d->udata; struct assoc_ok_struct* s=(struct assoc_ok_struct*)d->udata2; unsigned char *txt; struct conv_table *table; unsigned char *url; /*See block_edit_item*/ url=(unsigned char *)&d->items[4]; table=get_translation_table(s->dlg->win->term->spec->charset,blocks_ld.codepage); txt=convert_string(table,url,(int)strlen(cast_const_char url),NULL); mem_free(item->url); item->url=txt; s->fn(s->dlg,s->data,item,&blocks_ld); d->udata=NULL; /* for abort function */ }
unsigned char *get_text_translation(unsigned char *text, struct terminal *term) { unsigned char **current_tra; struct conv_table *conv_table; unsigned char *trn; int charset; if (!term) charset = 0; else if (term->spec) charset = term->spec->charset; else charset = utf8_table; if (is_direct_text(text)) return text; if ((current_tra = translation_array[current_language][charset])) { unsigned char *tt; if ((trn = current_tra[text - dummyarray])) return trn; tr: if (!(tt = cast_uchar translations[current_language].t[text - dummyarray].name)) { trn = cast_uchar translation_english[text - dummyarray].name; } else { struct document_options l_opt; memset(&l_opt, 0, sizeof(l_opt)); l_opt.plain = 0; l_opt.cp = charset; conv_table = get_translation_table(current_lang_charset, charset); trn = convert_string(conv_table, tt, (int)strlen(cast_const_char tt), &l_opt); if (!strcmp(cast_const_char trn, cast_const_char tt)) { mem_free(trn); trn = tt; } } current_tra[text - dummyarray] = trn; } else { if (current_lang_charset && charset != current_lang_charset) { current_tra = translation_array[current_language][charset] = mem_alloc(sizeof (unsigned char **) * T__N_TEXTS); memset(current_tra, 0, sizeof (unsigned char **) * T__N_TEXTS); goto tr; } if (!(trn = cast_uchar translations[current_language].t[text - dummyarray].name)) { trn = cast_uchar(translations[current_language].t[text - dummyarray].name = translation_english[text - dummyarray].name); /* modifying translation structure */ } } return trn; }