From e416d1aea7ace1e97f9cf7a3185686cce88b30bf Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 19 Oct 2004 09:11:02 +0000 Subject: [PATCH] enable translation of ambigous messages git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9097 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/doc/ChangeLog | 5 ++ lib/doc/Customization.lyx | 74 ++++++++++++++++++- po/ChangeLog | 4 + po/de.po | 13 ++-- src/ChangeLog | 4 + src/frontends/qt2/ChangeLog | 7 +- src/frontends/qt2/ui/QPrefConvertersModule.ui | 2 +- src/frontends/qt2/ui/QPrintDialogBase.ui | 2 +- src/frontends/xforms/ChangeLog | 5 ++ .../xforms/forms/form_preferences.fd | 2 +- src/frontends/xforms/forms/form_print.fd | 2 +- src/messages.C | 21 +++++- src/messages.h | 4 +- 13 files changed, 129 insertions(+), 16 deletions(-) diff --git a/lib/doc/ChangeLog b/lib/doc/ChangeLog index ad51994822..6b5fc0ebd3 100644 --- a/lib/doc/ChangeLog +++ b/lib/doc/ChangeLog @@ -1,3 +1,8 @@ +2004-10-18 Georg Baum + + * Customization.lyx: add description of translation of ambigous + messages + 2004-10-17 José Matos * Depend.pl: removed. diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index cdd03dcfd2..d7654eb181 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -2814,6 +2814,78 @@ README LYX-SOURCE-DIR/po/ \family default directory for more instructions. +\layout Subsubsection + +Ambigous messages +\layout Standard + +Sometimes it turns out that one english message needs to be translated into + different messages in the target language. + One example is the message +\family typewriter +To +\family default + which has the german translation +\family typewriter +\lang german +Nach +\family default +\lang english + or +\family typewriter +\lang german +Bis +\family default +\lang english +. + +\family typewriter +gettext +\family default + does not handle such ambigous translations. + Therefore you have to add some context information to the message: Instead + of +\family typewriter +To +\family default + it becomes +\family typewriter +To[[as in 'From format x to format y']] +\family default + and +\family typewriter +To[[as in 'From page x to page y']]. + +\family default + Now the two occurences of +\family typewriter +To +\family default + are different for +\family typewriter +gettext +\family default + and can be translated correctly to +\family typewriter +\lang german +Nach +\family default +\lang english + and +\family typewriter +\lang german +Bis +\family default +\lang english +, respectively. +\layout Standard + +Of course the context information needs to be stripped off the original + message when no translation is used. + Therefore you have to put it in double square brackets at the end of the + message (see the example above). + The translation mechanism of LyX ensures that everything in double square + brackets at the end of messages is removed before displaying the message. \layout Subsection Translating the documentation. @@ -2839,7 +2911,7 @@ As of February 2003, almost all of the docs have been translated into German \emph on Tutorial \emph default - has been translated into at least 12 ther languages, with other translations + has been translated into at least 12 other languages, with other translations in progress. The library of translated documents is growing rapidly. \end_inset diff --git a/po/ChangeLog b/po/ChangeLog index e5115411e6..7c8e6e303b 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,7 @@ +2004-10-18 Georg Baum + + * de.po: update strings with context information + 2004-10-05 Jean-Marc Lasgouttes * ru.po: fix crash when autosaving reported by Nikita V. diff --git a/po/de.po b/po/de.po index 74f12265cd..6cecfd9eeb 100644 --- a/po/de.po +++ b/po/de.po @@ -1538,8 +1538,7 @@ msgid "From:|#F" msgstr "Von:|#V" #: src/frontends/xforms/forms/form_preferences.fd:1960 -#: src/frontends/xforms/forms/form_print.fd:188 -msgid "To:|#T" +msgid "To:|#T[[as in 'From format x to format y']]" msgstr "Nach:|#N" #: src/frontends/xforms/forms/form_preferences.fd:1978 @@ -1726,6 +1725,10 @@ msgstr "Kopien" msgid "Sorted|#S" msgstr "Sortiert|#S" +#: src/frontends/xforms/forms/form_print.fd:188 +msgid "To:|#T[[as in 'From page x to page y']]" +msgstr "Bis:|#B" + #: src/frontends/xforms/forms/form_print.fd:224 msgid "Reverse order|#R" msgstr "Umgekehrte Reihenfolge|#R" @@ -3998,7 +4001,7 @@ msgid "C&onverter:" msgstr "&Konverter:" #: src/frontends/qt2/ui/QPrefConvertersModule.ui:220 -msgid "&To:" +msgid "&To:[[as in 'From format x to format y']]" msgstr "&Nach:" #: src/frontends/qt2/ui/QPrefConvertersModule.ui:235 @@ -4516,8 +4519,8 @@ msgid "Page number to print from" msgstr "Drucke ab Seite Nr." #: src/frontends/qt2/ui/QPrintDialogBase.ui:112 -msgid "&to" -msgstr "&bis" +msgid "&To:[[as in 'From page x to page y']]" +msgstr "&Bis:" #: src/frontends/qt2/ui/QPrintDialogBase.ui:131 msgid "Page number to print to" diff --git a/src/ChangeLog b/src/ChangeLog index 2b2d73b568..1291f118ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-10-18 Georg Baum + + * messages.C (Pimpl): strip off translation context information + 2004-10-14 Jean-Marc Lasgouttes * BufferView_pimpl.C (setBuffer): when closing a buffer, make sure diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d5df44ca23..e3a7d595fd 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2004-10-18 Georg Baum + + * ui/QPrefConvertersModule.ui: Add translation context to "To:" + * ui/QPrintDialogBase.ui: ditto + 2004-10-11 Andreas Vox * qfont_loader.C (initFontPath, addToFontPath): two new static @@ -5,7 +10,7 @@ (available): remove special MacOSX code; use addToFontPath * lyx_gui.C (parse_init): add call to qfont_loader::initFontPath() - + 2004-10-01 Jean-Marc Lasgouttes * QLPopupMenu.C (populate): move the code below to here, so that diff --git a/src/frontends/qt2/ui/QPrefConvertersModule.ui b/src/frontends/qt2/ui/QPrefConvertersModule.ui index 42b05e0809..68113bb41a 100644 --- a/src/frontends/qt2/ui/QPrefConvertersModule.ui +++ b/src/frontends/qt2/ui/QPrefConvertersModule.ui @@ -217,7 +217,7 @@ text - &To: + &To:[[as in 'From format x to format y']] buddy diff --git a/src/frontends/qt2/ui/QPrintDialogBase.ui b/src/frontends/qt2/ui/QPrintDialogBase.ui index 314492285c..91d9f0711b 100644 --- a/src/frontends/qt2/ui/QPrintDialogBase.ui +++ b/src/frontends/qt2/ui/QPrintDialogBase.ui @@ -109,7 +109,7 @@ text - &to + &To:[[as in 'From page x to page y']] buddy diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 4f307eebdf..afe504e25f 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2004-10-18 Georg Baum + + * forms/form_preferences.fd: Add translation context to "To:" + * forms/form_print.fd: ditto + 2004-10-05 Angus Leeming * FormPreferences.C: add code to input/output the indexing command. diff --git a/src/frontends/xforms/forms/form_preferences.fd b/src/frontends/xforms/forms/form_preferences.fd index 94855b4da0..e76675ae86 100644 --- a/src/frontends/xforms/forms/form_preferences.fd +++ b/src/frontends/xforms/forms/form_preferences.fd @@ -1957,7 +1957,7 @@ alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE size: FL_DEFAULT_SIZE lcol: FL_BLACK -label: To:|#T +label: To:|#T[[as in 'From format x to format y']] shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity diff --git a/src/frontends/xforms/forms/form_print.fd b/src/frontends/xforms/forms/form_print.fd index dc61ab0912..ca36b14612 100644 --- a/src/frontends/xforms/forms/form_print.fd +++ b/src/frontends/xforms/forms/form_print.fd @@ -185,7 +185,7 @@ alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: To:|#T +label: To:|#T[[as in 'From page x to page y']] shortcut: resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity diff --git a/src/messages.C b/src/messages.C index d1aa3f5221..1877ae2f0b 100644 --- a/src/messages.C +++ b/src/messages.C @@ -13,6 +13,8 @@ #include "support/filetools.h" #include "support/path_defines.h" +#include + using lyx::support::GetEnvPath; using lyx::support::lyx_localedir; @@ -98,11 +100,24 @@ public: bindtextdomain(PACKAGE, lyx_localedir().c_str()); textdomain(PACKAGE); const char* msg = gettext(m.c_str()); - setlocale(LC_ALL, old); - free(old); + // Some english words have different translations, depending + // on context. In these cases the original string is + // augmented by context information (e.g. + // "To:[[as in 'From page x to page y']]" and + // "To:[[as in 'From format x to format y']]". + // This means that we need to filter out everything in + // double square brackets at the end of the string, + // otherwise the user sees bogus messages. // If we are unable to honour the request we just // return what we got in. - return (!n ? m : string(msg)); + string translated(n ? msg : m); + static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$"); + boost::smatch sub; + if (regex_match(translated, sub, reg)) + translated = sub.str(1); + setlocale(LC_ALL, old); + free(old); + return translated; } private: /// diff --git a/src/messages.h b/src/messages.h index c4b2fa25ec..f8ba53dbf0 100644 --- a/src/messages.h +++ b/src/messages.h @@ -17,9 +17,9 @@ /// class Messages { public: - /// + /// messages in the language defined by the environment Messages(); - /// + /// messages in the language \p l Messages(std::string const & l); /// ~Messages(); -- 2.39.5