]> git.lyx.org Git - features.git/commitdiff
Translations for listings insets
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 10 Apr 2012 18:21:01 +0000 (20:21 +0200)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 10 Apr 2012 18:21:01 +0000 (20:21 +0200)
The listings inset and include inset of type listings use two english terms
that are not localized yet: "Listing" for the caption and "Listings" for the
list of listings (not supported natively by LyX yet). The existing layout
translation mechanism has been extended to translate these terms as well:

1) Support [[stuff]] context in lib/layouttranslations
2) Support BabelPreamble and LangPreamble in InsetLayout
3) Use a InsetLayout for InsetInclude of type listings
4) Define BabelPreamble and LangPreamble in the layouts for InsetInclude
   and InsetListings

18 files changed:
lib/doc/Customization.lyx
lib/examples/localization_test.lyx
lib/layouts/stdinsets.inc
lib/layouttranslations
lib/scripts/layout2layout.py
po/lyx_pot.py
src/LaTeXFeatures.cpp
src/Language.cpp
src/Layout.cpp
src/Layout.h
src/TextClass.cpp
src/frontends/qt4/GuiDocument.cpp
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
src/support/Messages.cpp
src/support/Messages.h

index c3024dfe0901bb68362ff95caf5ee191135605e0..f97cd15e4f2b3da879b81c09d1811223f94d0f7b 100644 (file)
@@ -14254,6 +14254,31 @@ InsetLayout
  definition can contain the following entries:
 \end_layout
 
+\begin_layout Description
+\change_inserted -195340706 1333913893
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+BabelPreamble
+\end_layout
+
+\end_inset
+
+ Preamble for changing languages. See section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:I18n"
+
+\end_inset
+
+.
+\end_layout
+
 \begin_layout Description
 \begin_inset Flex Code
 status collapsed
@@ -14904,6 +14929,34 @@ Branch
 \end_inset
 
 ) modify this label on the fly.
+
+\end_layout
+
+\begin_layout Description
+\change_inserted -195340706 1333913893
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+LangPreamble
+\end_layout
+
+\end_inset
+
+ Language dependent preamble.  See section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:I18n"
+
+\end_inset
+
+.
+
 \end_layout
 
 \begin_layout Description
index 691bc2eea88e09e015693d7d8b3207444cb35190..51d09a468a082363943d80ccf66ad61660dbbf38 100644 (file)
@@ -382,6 +382,44 @@ fggf
 \end_inset
 
 
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "float,language={C++}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\begin_inset Caption
+
+\begin_layout Plain Layout
+
+ccc
+\end_layout
+
+\end_inset
+
+while(true);
+\end_layout
+
+\end_inset
+
+
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+lstlistoflistings
+\end_layout
+
+\end_inset
+
+
 \end_layout
 
 \end_body
index 28a08ab99619cd53e89cfeb31cbc79f517976de4..faa6d1c9d027015ded823cc4aa304b921688eba1 100644 (file)
@@ -4,7 +4,7 @@
 #
 # Detailed format description is available in the customization manual
 
-Format 36
+Format 38
 
 Provides stdinsets 1
 
@@ -170,8 +170,28 @@ InsetLayout Phantom
        ForcePlain            true
 End
 
+InsetLayout IncludeListings
+       # We need the [[List of Listings]] context, since "Listings" is also
+       # the name of the inset and translated differently.
+       # "Listings[[List of Listings]]" is the name of the "List of listings"
+       # ("Listings" is the predefined english name) in listings.sty, so it
+       # must be used here as well.
+       BabelPreamble
+               \addto\captions$$lang{\renewcommand{\lstlistingname}{_(Listing)}}
+               \addto\captions$$lang{\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}}
+       EndBabelPreamble
+       # The commands do not need to be defined in LangPreamble, since
+       # listings.sty does that already. However they need to be redefined
+       # in order to be used for non-english single-language documents.
+       LangPreamble
+               \renewcommand{\lstlistingname}{_(Listing)}
+               \renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}
+       EndLangPreamble
+End
+
 InsetLayout Listings
-       LabelString           Listings
+       CopyStyle IncludeListings
+       LabelString           Listings[[inset]]
        LatexType             none
        Decoration            minimalistic
        Font
index 2c9f81c9904bd553c4e06e15d345353ae7affcf4..aead249ec6292a85a9895efab3cb44441a081b68 100644 (file)
@@ -30,6 +30,8 @@ Translation ar
        "List of Graphs" "قائمة الرسوم البيانية"
        "List of Schemes" "قائمة التصميمات"
        "List of Tableaux" "قائمة الجداول"
+       "Listing" "عمل قوائم"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "تدوين"
        "Note" "ملاحظة"
        "Problem" "مشكلة"
@@ -106,6 +108,8 @@ Translation ca
        "List of Graphs" "List of Graphs"
        "List of Schemes" "List of Schemes"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "Llistat"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notació"
        "Note" "Nota"
        "Problem" "Problema"
@@ -145,6 +149,8 @@ Translation cs
        "List of Graphs" "Seznam grafů"
        "List of Schemes" "Seznam schémat"
        "List of Tableaux" "Seznam tabel"
+       "Listing" "Výpis"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Značení"
        "Note" "Poznámka"
        "Problem" "Úloha"
@@ -184,6 +190,8 @@ Translation da
        "List of Graphs" "Grafliste"
        "List of Schemes" "Schemaliste"
        "List of Tableaux" "Tableauliste"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Notat"
        "Problem" "Problem"
@@ -223,6 +231,8 @@ Translation de
        "List of Graphs" "Liste der Graphen"
        "List of Schemes" "Liste der Schemata"
        "List of Tableaux" "Tableaux-Verzeichnis"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Notiz"
        "Problem" "Problem"
@@ -266,6 +276,8 @@ Translation el
        "List of Graphs" "Λίστα Γραφημάτων"
        "List of Schemes" "Λίστα Σχεδίων"
        "List of Tableaux" "Λίστα Ταμπλό"
+       "Listing" "Καταλογοποίηση"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Σημειογραφία"
        "Note" "Σημείωση"
        "Problem" "Πρόβλημα"
@@ -305,6 +317,8 @@ Translation en
        "List of Graphs" "List of Graphs"
        "List of Schemes" "List of Schemes"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Note"
        "Problem" "Problem"
@@ -344,6 +358,8 @@ Translation es
        "List of Graphs" "Índice de gráficos"
        "List of Schemes" "Índice de esquemas"
        "List of Tableaux" "Índice de Tableaux"
+       "Listing" "Listado"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notación"
        "Note" "Nota"
        "Problem" "Problema"
@@ -383,6 +399,8 @@ Translation eu
        "List of Graphs" "Grafikoen zerrenda"
        "List of Schemes" "Eskemen zerrenda"
        "List of Tableaux" "Taulen zerrenda"
+       "Listing" "Zerrenda"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notazioa"
        "Note" "Ohar"
        "Problem" "Buruketa"
@@ -422,6 +440,8 @@ Translation fi
        "List of Graphs" "Kuvaajien luettelo"
        "List of Schemes" "Kuvausten lettelo"
        "List of Tableaux" "Taulujen luettelo"
+       "Listing" "Listaus"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Merkintätapa"
        "Note" "Muistiinpano"
        "Problem" "Ongelma"
@@ -461,6 +481,8 @@ Translation fr
        "List of Graphs" "Liste des graphiques"
        "List of Schemes" "Liste des schémas"
        "List of Tableaux" "Liste des tableaux (TO)"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Note"
        "Problem" "Problème"
@@ -500,6 +522,8 @@ Translation gl
        "List of Graphs" "List of Graphs"
        "List of Schemes" "List of Schemes"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "Lista"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notación"
        "Note" "Nota"
        "Problem" "Problema"
@@ -539,6 +563,8 @@ Translation he
        "List of Graphs" "רשימת גרפים"
        "List of Schemes" "רשימת סכמות"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "רישום קוד"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "צורת רישום"
        "Note" "הערה"
        "Problem" "בעיה"
@@ -578,6 +604,8 @@ Translation hu
        "List of Graphs" "Grafikonok listája"
        "List of Schemes" "Sémák listája"
        "List of Tableaux" "Csoportképek listája"
+       "Listing" "Lista"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Jelölés"
        "Note" "Megjegyzés"
        "Problem" "Probléma"
@@ -617,6 +645,8 @@ Translation ia
        "List of Graphs" "Lista de graphicos"
        "List of Schemes" "Lista de schemas"
        "List of Tableaux" "Lista de tableau"
+       "Listing" "Listar"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Nota"
        "Problem" "Problema"
@@ -656,6 +686,8 @@ Translation id
        "List of Graphs" "Daftar Grafik"
        "List of Schemes" "Daftar Skema"
        "List of Tableaux" "Daftar Tableaux"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notasi"
        "Note" "Nota"
        "Problem" "Masalah"
@@ -695,6 +727,8 @@ Translation it
        "List of Graphs" "Elenco dei grafici"
        "List of Schemes" "Elenco degli schemi"
        "List of Tableaux" "Elenco dei tableau"
+       "Listing" "Listato"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notazione"
        "Note" "Nota"
        "Problem" "Problema"
@@ -734,6 +768,8 @@ Translation ja
        "List of Graphs" "グラフ一覧"
        "List of Schemes" "スキーム一覧"
        "List of Tableaux" "絵画一覧"
+       "Listing" "リスト"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "記法"
        "Note" "注釈"
        "Problem" "問題"
@@ -810,6 +846,8 @@ Translation nb
        "List of Graphs" "Grafer"
        "List of Schemes" "Struktruformler"
        "List of Tableaux" "Tablåer"
+       "Listing" "«Listing»"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notasjon"
        "Note" "Merknad"
        "Problem" "Problem"
@@ -849,6 +887,8 @@ Translation nl
        "List of Graphs" "Grafiekenlijst"
        "List of Schemes" "Schema-lijst"
        "List of Tableaux" "Lijst van Tableaus"
+       "Listing" "Opsomming"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notatie"
        "Note" "Noot"
        "Problem" "Opgave"
@@ -888,6 +928,8 @@ Translation nn
        "List of Graphs" "Liste over grafar"
        "List of Schemes" "Liste over skjema"
        "List of Tableaux" "Liste over tablå"
+       "Listing" "Kodeliste"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notasjon"
        "Note" "Notis"
        "Problem" "Problem"
@@ -927,6 +969,8 @@ Translation pl
        "List of Graphs" "Lista grafów"
        "List of Schemes" "Lista schematów"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notacja"
        "Note" "Notka"
        "Problem" "Problem"
@@ -966,6 +1010,8 @@ Translation pt
        "List of Graphs" "Lista de Gráficos"
        "List of Schemes" "Lista de Esquemas"
        "List of Tableaux" "Lista de Quadros"
+       "Listing" "Listagem"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notação"
        "Note" "Nota"
        "Problem" "Problema"
@@ -1010,6 +1056,8 @@ Translation ro
        "List of Graphs" "Listă de Grafice"
        "List of Schemes" "Listă de Scheme"
        "List of Tableaux" "Listă de Tabele"
+       "Listing" "Listare"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notație"
        "Note" "Notă"
        "Problem" "Problemă"
@@ -1049,6 +1097,8 @@ Translation ru
        "List of Graphs" "Список графиков"
        "List of Schemes" "Список схем"
        "List of Tableaux" "Список таблиц"
+       "Listing" "Листинг"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Нотация"
        "Note" "Заметка"
        "Problem" "Проблема"
@@ -1088,6 +1138,8 @@ Translation sk
        "List of Graphs" "Zoznam grafík"
        "List of Schemes" "Zoznam náčrtkov"
        "List of Tableaux" "Zoznam tablov"
+       "Listing" "Výpis"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notácia"
        "Note" "Poznámka"
        "Problem" "Problém"
@@ -1164,6 +1216,8 @@ Translation sr
        "List of Graphs" "Spisak Grafikona"
        "List of Schemes" "Spisak Šema"
        "List of Tableaux" "Spisak Tabela "
+       "Listing" "Listing"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Zabeleška"
        "Note" "Napomena"
        "Problem" "Problem"
@@ -1203,6 +1257,8 @@ Translation sv
        "List of Graphs" "Lista över grafer"
        "List of Schemes" "Lista över scheman"
        "List of Tableaux" "Lista över tablåer"
+       "Listing" "Listning"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notation"
        "Note" "Not"
        "Problem" "Problem"
@@ -1242,6 +1298,8 @@ Translation tr
        "List of Graphs" "List of Graphs"
        "List of Schemes" "Plan Listesi"
        "List of Tableaux" "Tablo Listesi"
+       "Listing" "Liste"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Notasyon"
        "Note" "Not"
        "Problem" "Problem"
@@ -1281,6 +1339,8 @@ Translation uk
        "List of Graphs" "Список графіків"
        "List of Schemes" "Список схем"
        "List of Tableaux" "Список табло"
+       "Listing" "Текст програми"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "Позначення"
        "Note" "Примітка"
        "Problem" "Проблема"
@@ -1320,6 +1380,8 @@ Translation zh_CN
        "List of Graphs" "图形列表"
        "List of Schemes" "方案列表"
        "List of Tableaux" "场景列表"
+       "Listing" "列表"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "记号"
        "Note" "备忘"
        "Problem" "问题"
@@ -1359,6 +1421,8 @@ Translation zh_TW
        "List of Graphs" "List of Graphs"
        "List of Schemes" "List of Schemes"
        "List of Tableaux" "List of Tableaux"
+       "Listing" "列表"
+       "Listings[[List of Listings]]" "Listings"
        "Notation" "記法"
        "Note" "註記"
        "Problem" "問題"
index 9de6c8372f2aef1402567580fd0bf70c00db390f..6eebac565b81942bc83887099c77fb6cf745c1ab 100644 (file)
@@ -129,6 +129,9 @@ import os, re, string, sys
 # Implement the citation engine machinery in layouts.
 # Change CiteFormat to CiteFormat (default|authoryear|numerical).
 
+# Incremented to format 38, 08 April 2012 by gb
+# Introduce LangPreamble and BabelPreamble for InsetLayout.
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -136,7 +139,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 37
+currentFormat = 38
 
 
 def usage(prog_name):
@@ -322,6 +325,10 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 37:
+          i += 1
+          continue
+
         if format == 36:
             match = re_CiteFormat.match(lines[i]);
             if match and match.group(4) == "":
index 235f304fc8b2a34b907e33660b8d9725d2635acb..25cb1fd649ba84461aac679cb6a249092954305c 100755 (executable)
@@ -336,6 +336,8 @@ def layouts_l10n(input_files, output, base, layouttranslations):
             keys.append(key)
         keys.sort()
 
+        ContextRe = re.compile(r'(.*)(\[\[.*\]\])')
+
         print >> out, '''# This file has been automatically generated by po/lyx_pot.py.
 # PLEASE MODIFY ONLY THE LAGUAGES HAVING NO .po FILE! If you want to regenerate
 # this file from the translations, run `make ../lib/layouttranslations' in po.
@@ -372,8 +374,13 @@ def layouts_l10n(input_files, output, base, layouttranslations):
                 # also print untranslated entries to help translators
                 elif not lang in oldlanguages:
                     key = key.replace('\\', '\\\\').replace('"', '\\"')
+                    res = ContextRe.search(key)
+                    if res != None:
+                        val = res.group(1)
+                    else:
+                        val = key
                     print >> out, '\t"%s" "%s"' % \
-                             (key.encode('utf-8'), key.encode('utf-8'))
+                             (key.encode('utf-8'), val.encode('utf-8'))
             print >> out, 'End'
 
     out.close()
index f1d315cae84e3341ebea09efdff2715cce1b9aeb..d5a0b6f6b90043b7015f37d64dad51804ea5071b 100644 (file)
@@ -38,6 +38,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/regex.h"
 
 #include <algorithm>
 
@@ -1181,6 +1182,49 @@ docstring const getFloatI18nPreamble(docstring const & type,
           << "{\\renewcommand{\\" << type << "name}{" << translated << "}}\n";
        return os.str();
 }
+
+
+docstring const i18npreamble(docstring const & templ, Language const * lang,
+               Encoding const & enc, bool const polyglossia)
+{
+       if (templ.empty())
+               return templ;
+
+       string preamble = polyglossia ?
+               subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
+               subst(to_utf8(templ), "$$lang", lang->babel());
+
+       string const langenc = lang->encoding()->iconvName();
+       string const texenc = lang->encoding()->latexName();
+       string const bufenc = enc.iconvName();
+       // First and second character of plane 15 (Private Use Area)
+       string const s1 = "\xf3\xb0\x80\x80"; // U+F0000
+       string const s2 = "\xf3\xb0\x80\x81"; // U+F0001
+       // FIXME UNICODE
+       // lyx::regex is not unicode-safe.
+       // Should use QRegExp or (boost::u32regex, but that requires ICU)
+       static regex const reg("_\\(([^\\)]+)\\)");
+       smatch sub;
+       while (regex_search(preamble, sub, reg)) {
+               string const key = sub.str(1);
+               docstring const name = lang->translateLayout(key);
+               // Check whether name can be encoded in the buffer encoding
+               bool encodable = true;
+               for (size_t i = 0; i < name.size(); ++i) {
+                       if (!enc.encodable(name[i])) {
+                               encodable = false;
+                               break;
+                       }
+               }
+               string const translated = encodable ? to_utf8(name)
+                       : "\\inputencoding{" + texenc + "}"
+                       + s1 + langenc + s2 + to_utf8(name)
+                       + s1 + bufenc + s2;
+               preamble = subst(preamble, sub.str(), translated);
+       }
+       return from_utf8(preamble);
+}
+
 }
 
 
@@ -1197,17 +1241,20 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
        list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit) {
                // language dependent commands (once per document)
-               snippets.insert(tclass[*cit].langpreamble(buffer().language(),
+               snippets.insert(i18npreamble(tclass[*cit].langpreamble(),
+                                               buffer().language(),
                                                buffer().params().encoding(),
                                                use_polyglossia));
                // commands for language changing (for multilanguage documents)
                if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
-                       snippets.insert(tclass[*cit].babelpreamble(
+                       snippets.insert(i18npreamble(
+                                               tclass[*cit].babelpreamble(),
                                                buffer().language(),
                                                buffer().params().encoding(),
                                                use_polyglossia));
                        for (lang_it lit = lbeg; lit != lend; ++lit)
-                               snippets.insert(tclass[*cit].babelpreamble(
+                               snippets.insert(i18npreamble(
+                                               tclass[*cit].babelpreamble(),
                                                *lit,
                                                buffer().params().encoding(),
                                                use_polyglossia));
@@ -1251,6 +1298,34 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
                }
        }
 
+       cit = usedInsetLayouts_.begin();
+       end = usedInsetLayouts_.end();
+       TextClass::InsetLayouts const & ils = tclass.insetLayouts();
+       for (; cit != end; ++cit) {
+               TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
+               if (it == ils.end())
+                       continue;
+               // language dependent commands (once per document)
+               snippets.insert(i18npreamble(it->second.langpreamble(),
+                                               buffer().language(),
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
+               // commands for language changing (for multilanguage documents)
+               if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
+                       snippets.insert(i18npreamble(
+                                               it->second.babelpreamble(),
+                                               buffer().language(),
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
+                       for (lang_it lit = lbeg; lit != lend; ++lit)
+                               snippets.insert(i18npreamble(
+                                               it->second.babelpreamble(),
+                                               *lit,
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
+               }
+       }
+
        odocstringstream tcpreamble;
        set<docstring>::const_iterator const send = snippets.end();
        set<docstring>::const_iterator it = snippets.begin();
index a7845f51d32a4f42f4242bf370d11be546cad839..cbe425d3b9dcc6a3a092e03a5ef4c74652282c2b 100644 (file)
@@ -53,7 +53,9 @@ docstring const Language::translateLayout(string const & m) const
        if (it != layoutTranslations_.end())
                return it->second;
 
-       return from_ascii(m);
+       docstring t = from_ascii(m);
+       cleanTranslation(t);
+       return t;
 }
 
 
index bd4c08bee42fa9884d9f08f0f6a472e22d5e59d7..ec6e2dc5a5dfe760f5c931acea611e93f1635ddf 100644 (file)
@@ -24,7 +24,6 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/Messages.h"
-#include "support/regex.h"
 #include "support/textutils.h"
 
 
@@ -859,72 +858,6 @@ void Layout::readSpacing(Lexer & lex)
 }
 
 
-namespace {
-
-docstring const i18npreamble(Language const * lang, Encoding const & enc,
-                            docstring const & templ, bool const polyglossia)
-{
-       if (templ.empty())
-               return templ;
-
-       string preamble = polyglossia ?
-               subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
-               subst(to_utf8(templ), "$$lang", lang->babel());
-
-#ifdef TEX2LYX
-       // tex2lyx does not have getMessages()
-       LASSERT(false, /**/);
-       (void)enc;
-#else
-       string const langenc = lang->encoding()->iconvName();
-       string const texenc = lang->encoding()->latexName();
-       string const bufenc = enc.iconvName();
-       // First and second character of plane 15 (Private Use Area)
-       string const s1 = "\xf3\xb0\x80\x80"; // U+F0000
-       string const s2 = "\xf3\xb0\x80\x81"; // U+F0001
-       // FIXME UNICODE
-       // lyx::regex is not unicode-safe.
-       // Should use QRegExp or (boost::u32regex, but that requires ICU)
-       static regex const reg("_\\(([^\\)]+)\\)");
-       smatch sub;
-       while (regex_search(preamble, sub, reg)) {
-               string const key = sub.str(1);
-               docstring const name = lang->translateLayout(key);
-               // Check whether name can be encoded in the buffer encoding
-               bool encodable = true;
-               for (size_t i = 0; i < name.size(); ++i) {
-                       if (!enc.encodable(name[i])) {
-                               encodable = false;
-                               break;
-                       }
-               }
-               string const translated = encodable ? to_utf8(name)
-                       : "\\inputencoding{" + texenc + "}"
-                               + s1 + langenc + s2 + to_utf8(name)
-                               + s1 + bufenc + s2;
-               preamble = subst(preamble, sub.str(), translated);
-       }
-#endif
-       return from_utf8(preamble);
-}
-
-}
-
-
-docstring const Layout::langpreamble(Language const * lang,
-                       Encoding const & enc, bool const polyglossia) const
-{
-       return i18npreamble(lang, enc, langpreamble_, polyglossia);
-}
-
-
-docstring const Layout::babelpreamble(Language const * lang,
-                       Encoding const & enc, bool const polyglossia) const
-{
-       return i18npreamble(lang, enc, babelpreamble_, polyglossia);
-}
-
-
 string const & Layout::htmltag() const 
 { 
        if (htmltag_.empty())
index 1db9a23a386896ac0248fb08df98c33a34506154..08c049d8d6ac054140e2005cf49a867091a59696 100644 (file)
@@ -14,7 +14,6 @@
 #ifndef LAYOUT_H
 #define LAYOUT_H
 
-#include "Encoding.h"
 #include "FontInfo.h"
 #include "LayoutEnums.h"
 #include "Spacing.h"
@@ -25,7 +24,6 @@
 
 namespace lyx {
 
-class Language;
 class Lexer;
 class TextClass;
 
@@ -96,10 +94,10 @@ public:
        docstring const & preamble() const { return preamble_; }
        /// Get language dependent macro definitions needed for this layout
        /// for language \p lang
-       docstring const langpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
+       docstring const langpreamble() const { return langpreamble_; }
        /// Get language and babel dependent macro definitions needed for
        /// this layout for language \p lang
-       docstring const babelpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
+       docstring const babelpreamble() const { return babelpreamble_; }
        ///
        std::set<std::string> const & requires() const { return requires_; }
        ///
index 2d49a4d5f1901c063595bae23973d2ff0f678049..82740cba429dcd5bd371ed443ce45198892b2614 100644 (file)
@@ -57,10 +57,10 @@ namespace lyx {
 // could. See LayoutFileList::addEmptyClass() and, especially, the
 // definition of the layoutpost string.
 // You should also run (or ask someone who has bash to run) the
-// development/updatelayouts.sh script, to update the format of
+// development/tools/updatelayouts.sh script, to update the format of
 // all of our layout files.
 //
-int const LAYOUT_FORMAT = 37; //jrioux : move citation engine stuff into layouts
+int const LAYOUT_FORMAT = 38; //gb : LangPreamble and BabelPreamble for InsetLayout
 
 namespace {
 
index 565da96f2fc76b3dd0aaa5e07394a44c76aa894c..9f3f7ea0dcaadab54b96a0c0d8af8517c9965487 100644 (file)
@@ -1424,7 +1424,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
        docPS->addPanel(mathsModule, qt_("Math Options"));
        docPS->addPanel(floatModule, qt_("Float Placement"));
-       docPS->addPanel(listingsModule, qt_("Listings"));
+       docPS->addPanel(listingsModule, qt_("Listings[[inset]]"));
        docPS->addPanel(bulletsModule, qt_("Bullets"));
        docPS->addPanel(branchesModule, qt_("Branches"));
        docPS->addPanel(outputModule, qt_("Output"));
index e7f9da374754862e4fdaee973b0b4ec7365c7229..c4a437bc195a5a6c6e681d7d493a16597bb21722 100644 (file)
@@ -905,6 +905,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
 
        features.includeFile(include_label, writefile);
 
+       features.useInsetLayout(getLayout());
        if (isVerbatim(params()))
                features.require("verbatim");
        else if (isListings(params()))
@@ -997,6 +998,13 @@ Inset::DisplayType InsetInclude::display() const
 }
 
 
+docstring InsetInclude::layoutName() const
+{
+       if (isListings(params()))
+               return from_ascii("IncludeListings");
+       return InsetCommand::layoutName();
+}
+
 
 //
 // preview stuff
index e3269badc0b502c54494284a4c5d6f68c4f63735..2583f41406fb0cdf22e1db6e1290a5986652ef39 100644 (file)
@@ -79,6 +79,8 @@ public:
        DisplayType display() const;
        ///
        InsetCode lyxCode() const { return INCLUDE_CODE; }
+       ///
+       docstring layoutName() const;
        /** Fills \c key
         *  \param keys the list of bibkeys in the child buffer.
         *  \param it not used here
index dee7e29f7a6083ff0fa4caa306c5a018b85b3353..01642d863c57b6bf517d504eca61fa4cc2ae3346 100644 (file)
@@ -75,6 +75,7 @@ InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
 bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
 {
        enum {
+               IL_BABELPREAMBLE,
                IL_BGCOLOR,
                IL_CONTENTASLABEL,
                IL_COPYSTYLE,
@@ -98,6 +99,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                IL_INTOC,
                IL_LABELFONT,
                IL_LABELSTRING,
+               IL_LANGPREAMBLE,
                IL_LATEXNAME,
                IL_LATEXPARAM,
                IL_LATEXTYPE,
@@ -117,6 +119,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
 
 
        LexerKeyword elementTags[] = {
+               { "babelpreamble", IL_BABELPREAMBLE },
                { "bgcolor", IL_BGCOLOR },
                { "contentaslabel", IL_CONTENTASLABEL },
                { "copystyle", IL_COPYSTYLE }, 
@@ -142,6 +145,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                { "keepempty", IL_KEEPEMPTY },
                { "labelfont", IL_LABELFONT },
                { "labelstring", IL_LABELSTRING },
+               { "langpreamble", IL_LANGPREAMBLE },
                { "latexname", IL_LATEXNAME },
                { "latexparam", IL_LATEXPARAM },
                { "latextype", IL_LATEXTYPE },
@@ -311,6 +315,12 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                case IL_PREAMBLE:
                        preamble_ = from_utf8(lex.getLongString("EndPreamble"));
                        break;
+               case IL_BABELPREAMBLE:
+                       babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
+                       break;
+               case IL_LANGPREAMBLE:
+                       langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
+                       break;
                case IL_REFPREFIX:
                        lex >> refprefix_;
                        break;
index 5b88cb89836187b7552f0ea5d965ff77bf1672bb..4619abcb0a363fe520009af7d7cae1ce7677649b 100644 (file)
@@ -82,6 +82,11 @@ public:
        ColorCode bgcolor() const { return bgcolor_; }
        ///
        docstring preamble() const { return preamble_; }
+       /// Get language dependent macro definitions needed for this inset
+       docstring const langpreamble() const { return langpreamble_; }
+       /// Get language and babel dependent macro definitions needed for
+       /// this inset
+       docstring const babelpreamble() const { return babelpreamble_; }
        ///
        docstring counter() const { return counter_; }
        ///
@@ -183,6 +188,10 @@ private:
        docstring counter_;
        ///
        docstring preamble_;
+       /// Language dependent macro definitions needed for this inset
+       docstring langpreamble_;
+       /// Language and babel dependent macro definitions needed for this inset
+       docstring babelpreamble_;
        ///
        docstring refprefix_;
        ///
index 81b4eaee67873d929cf35838afc5619f68fadc75..8d85460ea6dba9e1930b181f9bd73b64f1ab9be1 100644 (file)
@@ -29,8 +29,6 @@ namespace lyx {
 // Instanciate static member.
 string Messages::main_lang_;
 
-namespace {
-
 void cleanTranslation(docstring & trans) 
 {
        /*
@@ -51,7 +49,6 @@ void cleanTranslation(docstring & trans)
        }
 }
 
-} // anonymous
 } // lyx
 
 
index 3b3dce8304be7d29a84dc1382e75bd2feea53489..9ef8dc3ae9a0703516346eab43249bef6489dd56 100644 (file)
@@ -57,6 +57,9 @@ extern Messages const & getMessages(std::string const & language);
 /// Implementation is in LyX.cpp.
 extern Messages const & getGuiMessages();
 
+/// Remove the context suffix from \p trans
+extern void cleanTranslation(docstring & trans);
+
 } // namespace lyx
 
 #endif