[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[help-texinfo] Re: Setting human languag for makeinfo
From: |
Torsten Bronger |
Subject: |
[help-texinfo] Re: Setting human languag for makeinfo |
Date: |
Sun, 10 Apr 2005 14:46:23 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
Hallöchen!
address@hidden (Karl Berry) writes:
> [...]
>
> My thought was to translate the per-documentlanguage strings with
> a different function, say
>
> doclang_("See")
>
> And the doclang_ function would temporarily change the language to
> whatever was given in @documentlanguage, look up the string using
> the standard gettext functions, and change it back.
That was exactly my first thought.
The problem is that the argument to setlocale() is the same as for
LANG (I had made some tests that showed this), and we now know how
unreliable it seems to be. Well, it's misusing setlocale() after
all.
Anyway, I attached a second proposal.
http://lists.gnu.org/archive/html/bug-gnu-utils/2004-09/msg00057.html
suggests that the expansion with the country code should work.
Indeed, it does so on my system. However, other sources said that
setlocale() is always fragile.
Tschö,
Torsten.
===================================================================
RCS file: /cvsroot/texinfo/texinfo/makeinfo/lang.c,v
retrieving revision 1.14
diff -c -r1.14 lang.c
*** lang.c 22 Nov 2004 23:57:33 -0000 1.14
--- lang.c 10 Apr 2005 12:38:26 -0000
***************
*** 27,38 ****
--- 27,43 ----
#include "makeinfo.h"
#include "xml.h"
+ #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
+
/* Current document encoding. */
encoding_code_type document_encoding_code = no_encoding;
/* Current language code; default is English. */
language_code_type language_code = en;
+ /* Current locale code (language + country code). */
+ char *locale_code = NULL;
+
/* By default, unsupported encoding is an empty string. */
char *unknown_encoding = NULL;
***************
*** 559,564 ****
--- 564,671 ----
void
cm_documentlanguage (void)
{
+ /* Taken from gettext's msginit.c. Added en_US. */
+ static const char *locales_with_principal_territory[] = {
+ /* Language Main territory */
+ "af_ZA", /* Afrikaans South Africa */
+ "am_ET", /* Amharic Ethiopia */
+ "as_IN", /* Assamese India */
+ "az_AZ", /* Azerbaijani Azerbaijan */
+ "be_BY", /* Belarusian Belarus */
+ "bg_BG", /* Bulgarian Bulgaria */
+ "bn_IN", /* Bengali India */
+ "bo_CN", /* Tibetan China */
+ "br_FR", /* Breton France */
+ "bs_BA", /* Bosnian Bosnia */
+ "ca_ES", /* Catalan Spain */
+ "ce_RU", /* Chechen Russia */
+ "co_FR", /* Corsican France */
+ "cs_CZ", /* Czech Czech Republic */
+ "cy_GB", /* Welsh Britain */
+ "da_DK", /* Danish Denmark */
+ "de_DE", /* German Germany */
+ "dz_BT", /* Dzongkha Bhutan */
+ "el_GR", /* Greek Greece */
+ "en_US", /* English USA */
+ "es_ES", /* Spanish Spain */
+ "et_EE", /* Estonian Estonia */
+ "fa_IR", /* Persian Iran */
+ "fi_FI", /* Finnish Finland */
+ "fj_FJ", /* Fijian Fiji */
+ "fo_FO", /* Faroese Faeroe Islands */
+ "fr_FR", /* French France */
+ "ga_IE", /* Irish Ireland */
+ "gd_GB", /* Scots Britain */
+ "gu_IN", /* Gujarati India */
+ "he_IL", /* Hebrew Israel */
+ "hi_IN", /* Hindi India */
+ "hr_HR", /* Croatian Croatia */
+ "hu_HU", /* Hungarian Hungary */
+ "hy_AM", /* Armenian Armenia */
+ "id_ID", /* Indonesian Indonesia */
+ "is_IS", /* Icelandic Iceland */
+ "it_IT", /* Italian Italy */
+ "ja_JP", /* Japanese Japan */
+ "jv_ID", /* Javanese Indonesia */
+ "ka_GE", /* Georgian Georgia */
+ "kk_KZ", /* Kazakh Kazakhstan */
+ "kl_GL", /* Kalaallisut Greenland */
+ "km_KH", /* Khmer Cambodia */
+ "kn_IN", /* Kannada India */
+ "ko_KR", /* Korean Korea (South) */
+ "kok_IN", /* Konkani India */
+ "lo_LA", /* Laotian Laos */
+ "lt_LT", /* Lithuanian Lithuania */
+ "lv_LV", /* Latvian Latvia */
+ "mg_MG", /* Malagasy Madagascar */
+ "mk_MK", /* Macedonian Macedonia */
+ "ml_IN", /* Malayalam India */
+ "mn_MN", /* Mongolian Mongolia */
+ "mr_IN", /* Marathi India */
+ "ms_MY", /* Malay Malaysia */
+ "mt_MT", /* Maltese Malta */
+ "my_MM", /* Burmese Myanmar */
+ "mni_IN", /* Manipuri India */
+ "na_NR", /* Nauru Nauru */
+ "nb_NO", /* Norwegian Bokmal Norway */
+ "ne_NP", /* Nepali Nepal */
+ "nl_NL", /* Dutch Netherlands */
+ "nn_NO", /* Norwegian Nynorsk Norway */
+ "no_NO", /* Norwegian Norway */
+ "oc_FR", /* Occitan France */
+ "or_IN", /* Oriya India */
+ "pa_IN", /* Punjabi India */
+ "pl_PL", /* Polish Poland */
+ "ps_AF", /* Pashto Afghanistan */
+ "pt_PT", /* Portuguese Portugal */
+ "rm_CH", /* Rhaeto-Roman Switzerland */
+ "rn_BI", /* Kirundi Burundi */
+ "ro_RO", /* Romanian Romania */
+ "ru_RU", /* Russian Russia */
+ "sa_IN", /* Sanskrit India */
+ "sc_IT", /* Sardinian Italy */
+ "sg_CF", /* Sango Central African Rep. */
+ "si_LK", /* Sinhalese Sri Lanka */
+ "sk_SK", /* Slovak Slovakia */
+ "sl_SI", /* Slovenian Slovenia */
+ "so_SO", /* Somali Somalia */
+ "sq_AL", /* Albanian Albania */
+ "sr_YU", /* Serbian Yugoslavia */
+ "sv_SE", /* Swedish Sweden */
+ "te_IN", /* Telugu India */
+ "tg_TJ", /* Tajik Tajikistan */
+ "th_TH", /* Thai Thailand */
+ "tk_TM", /* Turkmen Turkmenistan */
+ "tl_PH", /* Tagalog Philippines */
+ "to_TO", /* Tonga Tonga */
+ "tr_TR", /* Turkish Turkey */
+ "uk_UA", /* Ukrainian Ukraine */
+ "ur_PK", /* Urdu Pakistan */
+ "uz_UZ", /* Uzbek Uzbekistan */
+ "vi_VN", /* Vietnamese Vietnam */
+ "wa_BE", /* Walloon Belgium */
+ "wen_DE" /* Sorbian Germany */
+ };
language_code_type c;
char *lang_arg;
***************
*** 571,577 ****
if (strcmp (lang_arg, language_table[c].abbrev) == 0)
{ /* Set current language code. */
language_code = c;
! break;
}
}
--- 678,700 ----
if (strcmp (lang_arg, language_table[c].abbrev) == 0)
{ /* Set current language code. */
language_code = c;
! int i;
! for (i = 0; i < SIZEOF (locales_with_principal_territory); i++)
! {
! int j = 0;
! while (locales_with_principal_territory[i][j] != '_'
! && locales_with_principal_territory[i][j] == lang_arg[j])
! j++;
! if (locales_with_principal_territory[i][j] == '_')
! {
! if (locale_code != NULL) free (locale_code);
! locale_code = strdup (locales_with_principal_territory[i]);
! break;
! }
! }
! if (i == SIZEOF (locales_with_principal_territory))
! warning (_("country code for language %s not found"), lang_arg);
! break;
}
}
***************
*** 588,593 ****
--- 711,730 ----
free (lang_arg);
}
+ /* Used like gettext(), but it returns a translation not according to the
+ active locale, but according to "language_code". */
+
+ char *
+ doclang_ (const char *msgid)
+ {
+ char *result;
+ /* Setting the default locale */
+ if (locale_code == NULL) locale_code = strdup ("");
+ setlocale (LC_MESSAGES, locale_code);
+ result = _(msgid);
+ setlocale (LC_MESSAGES, "");
+ return result;
+ }
/* Search through the encoding table for the given character, returning
cvs diff: I know nothing about lang.c.~1.14.~
Index: lang.h
===================================================================
RCS file: /cvsroot/texinfo/texinfo/makeinfo/lang.h,v
retrieving revision 1.6
diff -c -r1.6 lang.h
*** lang.h 11 Apr 2004 17:56:47 -0000 1.6
--- lang.h 10 Apr 2005 12:38:27 -0000
***************
*** 145,148 ****
--- 145,150 ----
extern char *current_document_encoding (void);
+ extern char *doclang_ (const char *);
+
#endif /* not LANG_H */
- [help-texinfo] Setting human languag for makeinfo, Torsten Bronger, 2005/04/02
- Re: [help-texinfo] Setting human languag for makeinfo, Karl Berry, 2005/04/04
- [help-texinfo] Re: Setting human languag for makeinfo, Torsten Bronger, 2005/04/08
- Re: [help-texinfo] Re: Setting human languag for makeinfo, Karl Berry, 2005/04/08
- [help-texinfo] Re: Setting human languag for makeinfo, Torsten Bronger, 2005/04/09
- Re: [help-texinfo] Re: Setting human languag for makeinfo, Karl Berry, 2005/04/09
- [help-texinfo] Re: Setting human languag for makeinfo, Torsten Bronger, 2005/04/09
- Re: [help-texinfo] Re: Setting human languag for makeinfo, Karl Berry, 2005/04/09
- [help-texinfo] Re: Setting human languag for makeinfo,
Torsten Bronger <=
- Re: [help-texinfo] Re: Setting human languag for makeinfo, Karl Berry, 2005/04/10