Am Mittwoch, 13. Oktober 2004 10:01 schrieb Jean-Marc Lasgouttes: > >>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes: > > OK, here are some comments. Better late than never ;)
Thanks. Unfortunately I am late with the reply, too ;-) > Georg> Questions: 1. Do we ever use any other gettext than GNU > Georg> gettext? > > I do not know. A case of interest is probably the gettext used on *bsd. Ok, then we are on the safe side with messages-2.diff. > Georg> 2. Is HAVE_LC_MESSAGES ever undefined? > > Don't know. Ok, it does not matter for the second version. > What happens is that we may need two languages at the same time: one > for the interface and one for the document strings (this is new to > 1.4.0cvs). Therefore, the locale has to be reset. I suspect however > that we could do these changes less often. I disabled the complete localization in messages.C by doing return m; at the very beginning of Messages::Pimpl::get(). Several runs of time ./lyx-notrans -x 'command-sequence file-open UserGuide.lyx ; lyx-quit ;' show on average 50 ms less than a normal build, so I guess we don't need to worry about this point. > I propose a different solution, which is a mix of what you did and > what I proposed earlier. > > 1/ use a clear notation for translators hints that does not risk to be > used in normal code, like [[double brackets]] or /*C-style comments*/ I don't like this very much, because we limit the domain of translatable strings, but I think I would prefer the double bracket version if we are going to do it like this. > 2/ Once a string has been translated, remove translators hints (using > a regexp) if they are still present. > > It seems to me that this avoids nicely the use of a en.po. Why do you want to avoid it? The amount of code is almost the same as for your proposal. IMHO using en.po is a nice solution (I may say that, it is Angus' idea, not mine :-) ) > Would that work? Yes. See attached diff (undefine USE_EN_PO, parts of my previous patch are needed, too). The regex is preliminary, bacause like this I did not need to change the dialogs again. The same coarse timing method as above shows no difference above noise between a normal build, the method with en.po and your proposal. Georg
--- lyx-1.4-clean/src/messages.C 2004-06-09 18:53:41.000000000 +0200 +++ lyx-1.4-cvs/src/messages.C 2004-10-15 21:43:16.000000000 +0200 @@ -13,6 +13,11 @@ #include "support/filetools.h" #include "support/path_defines.h" +#undef USE_EN_PO +#ifndef USE_EN_PO +#include <boost/regex.hpp> +#endif + using lyx::support::GetEnvPath; using lyx::support::lyx_localedir; @@ -98,11 +103,37 @@ bindtextdomain(PACKAGE, lyx_localedir().c_str()); textdomain(PACKAGE); const char* msg = gettext(m.c_str()); + // Some english words have different translations, depending + // on context. These cases are handled with an english + // translation: The original string is augmented by context + // information (e.g. + // "To:[translation hint: as in 'From page x to page y']" and + // "To:[translation hint: as in 'From format x to format y']", + // and the english translation of both strings is "To:". + // This means that we need the english translation as + // fallback, if no translation for the current language is + // available, otherwise the user sees bogus messages. + string translated(msg); + if (n && translated == m) { +#ifdef USE_EN_PO + n = setlocale(LC_ALL, "en_US"); + bindtextdomain(PACKAGE, lyx_localedir().c_str()); + textdomain(PACKAGE); + msg = gettext(m.c_str()); + translated = msg; +#else + static boost::regex const reg("^([^\\[]*)\\[translation hint:[^\\]]*\\](.*)$"); + boost::smatch sub; + if (regex_match(translated, sub, reg)) { + translated = sub.str(1) + sub.str(2); + } +#endif + } setlocale(LC_ALL, old); free(old); // If we are unable to honour the request we just // return what we got in. - return (!n ? m : string(msg)); + return (!n ? m : translated); } private: ///