]> git.lyx.org Git - lyx.git/commitdiff
New info-inset type l7n
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 13 Aug 2018 15:18:44 +0000 (17:18 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 13 Aug 2018 15:18:44 +0000 (17:18 +0200)
This returns a localized version of a string (in the GUI language)
if available, removing trailing colons and accelerator marks.

This can be used to refer to dialog items in the docs in a portable way.

development/FORMAT
lib/lyx2lyx/lyx_2_4.py
src/LyXAction.cpp
src/frontends/qt4/GuiInfo.cpp
src/insets/InsetInfo.cpp
src/insets/InsetInfo.h
src/version.h

index 4bf2519331406425b8561d9f278645fcfe366874..2ae38024b7f1c8d91fd65b7dbb0c502b70b2aa21 100644 (file)
@@ -7,6 +7,11 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2018-08-13  Jürgen Spitzmüller <spitz@lyx.org>
+       * format incremented to 562: New info-inset type l7n. This returns a localized version
+          of a string (in the GUI language) if available, removing trailing colons and
+          accelerator marks.
+
 2018-08-10  Kornel Benko <kornel@lyx.org>
        * format incremented to 561: Added DejaVu fonts
 
index 1574fb5d3cbb3e6e72216ef5912070f5ed85af1e..2d6caabaa46597d476ba36996abd3cee826d3b76 100644 (file)
@@ -1129,6 +1129,32 @@ def revert_namenoextinfo(document):
         i = i + 1
 
 
+def revert_l7ninfo(document):
+    " Revert l7n Info inset to text. "
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset Info", i)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i + 1)
+        if j == -1:
+            document.warning("Malformed LyX document: Could not find end of Info inset.")
+            i = i + 1
+            continue
+        tp = find_token(document.body, 'type', i, j)
+        tpv = get_quoted_value(document.body, "type", tp)
+        if tpv != "l7n":
+            i = i + 1
+            continue
+        arg = find_token(document.body, 'arg', i, j)
+        argv = get_quoted_value(document.body, "arg", arg)
+        # remove trailing colons, menu accelerator (|...) and qt accelerator (&), while keeping literal " & " 
+        argv = argv.rstrip(':').split('|')[0].replace(" & ", "</amp;>").replace("&", "").replace("</amp;>", " & ")
+        document.body[i : j+1] = argv
+        i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -1151,10 +1177,12 @@ convert = [
            [558, [removeFrontMatterStyles]],
            [559, []],
            [560, []],
-           [561, [convert_dejavu]]
+           [561, [convert_dejavu]],
+           [562, []]
           ]
 
 revert =  [
+           [561, [revert_l7ninfo]],
            [560, [revert_dejavu]],
            [559, [revert_timeinfo, revert_namenoextinfo]],
            [558, [revert_dateinfo]],
index d73b2a9b590eb3c57cba84678c78c2c473a3e521..4f424883f7a7e207932cbbe015bd0f05f842654e 100644 (file)
@@ -1930,7 +1930,8 @@ void LyXAction::init()
                the work area.\n
                2. select the text and run info-insert lfun.
  * \li Syntax: info-insert <TYPE> <ARG>
- * \li Params: <TYPE>: shortcut[s]|lyxrc|lyxinfo|package|textclass|menu|icon|buffer \n
+ * \li Params: <TYPE>: date|moddate|fixdate|time|modtime|fixtime|shortcut|shortcuts|lyxrc|
+ *                     lyxinfo|package|textclass|menu|l7n|icon|buffer|vcs \n
                <ARG>: argument for a given type. Look into InsetInfo.h for detailed
                       description. \n
                       date: current date (formatted and localized)\n
@@ -1945,6 +1946,7 @@ void LyXAction::init()
                       package: name of latex package (e.g. listings) \n
                       textclass: name of textclass (e.g. article) \n
                       menu: name of lfun used in menu  \n
+                      l7n: localizable string.\n
                       icon: icon of lfun used in toolbar or direct icon name\n
                       buffer: "name"|"name-noext"|"path"|"class"
                       vcs: "tree-revision"|"revision"|"author"|"date"|"time"
index a499461282f193415d48c9bc0c8ffeb998577cce..9fec2187753853a163584899c2cf3a9f3f7f3a17 100644 (file)
@@ -58,6 +58,7 @@ char const * info_types[] =
   "shortcut",
   "shortcuts",
   "menu",
+  "l7n",
   "icon",
   "lyxrc",
   "lyxinfo",
@@ -79,6 +80,7 @@ char const * info_types_gui[] =
   N_("Last Assigned Keyboard Shortcut"),// shortcut
   N_("All Keyboard Shortcuts"),// shortcuts
   N_("LyX Menu Location"),// menu
+  N_("Localized GUI String"),// l7n
   N_("LyX Toolbar Icon"),// icon
   N_("LyX Preferences Entry"),// lyxrc
   N_("LyX Application Information"),// lyxinfo
@@ -100,6 +102,7 @@ char const * info_name_gui[] =
   N_("LyX Function"),// shortcut
   N_("LyX Function"),// shortcuts
   N_("LyX Function"),// menu
+  N_("English String"),// l7n
   N_("LyX Function"),// icon
   N_("Preferences Key"),// lyxrc
   N_("Not Applicable"),// lyxinfo
@@ -196,6 +199,8 @@ char const * info_tooltip[] =
      "The output lists all possible keyboard shortcuts for this function"),// shortcuts
   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
      "The output is the path to the function in the menu (using the current localization)."),// menu
+  N_("Enter a localizable English string from the LyX User Interface, including accelerator markup ('&' or '|') and trailing colons. "
+     "The output is the localized string (using the current localization); trailing colons and accelerator markup are stripped."),// l7n
   N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
      "The output is the toolbar icon for this function (using the active icon theme)."),// icon
   N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "
index da78a110755b1925910ab200c89f20b1f1caf275..4d3901596679706d410ff855d4d6c29f0b162453 100644 (file)
@@ -75,6 +75,7 @@ NameTranslator const initTranslator()
        translator.addPair(InsetInfoParams::PACKAGE_INFO, "package");
        translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "textclass");
        translator.addPair(InsetInfoParams::MENU_INFO, "menu");
+       translator.addPair(InsetInfoParams::L7N_INFO, "l7n");
        translator.addPair(InsetInfoParams::ICON_INFO, "icon");
        translator.addPair(InsetInfoParams::BUFFER_INFO, "buffer");
        translator.addPair(InsetInfoParams::LYX_INFO, "lyxinfo");
@@ -109,6 +110,7 @@ DefaultValueTranslator const initDVTranslator()
        translator.addPair(InsetInfoParams::PACKAGE_INFO, "graphics");
        translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "article");
        translator.addPair(InsetInfoParams::MENU_INFO, "info-insert");
+       translator.addPair(InsetInfoParams::L7N_INFO, "");
        translator.addPair(InsetInfoParams::ICON_INFO, "info-insert");
        translator.addPair(InsetInfoParams::BUFFER_INFO, "name-noext");
        translator.addPair(InsetInfoParams::LYX_INFO, "version");
@@ -231,6 +233,10 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
                break;
        }
 
+       case L7N_INFO:
+               result.push_back(make_pair("custom", _("Custom")));
+               break;
+
        case LYXRC_INFO: {
                result.push_back(make_pair("custom", _("Custom")));
                set<string> rcs = lyxrc.getRCs();
@@ -381,6 +387,10 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const
                result = bformat(_("The menu location for the function '%1$s'"),
                                from_utf8(params_.name));
                break;
+       case InsetInfoParams::L7N_INFO: 
+               result = bformat(_("The localization for the string '%1$s'"),
+                               from_utf8(params_.name));
+               break;
        case InsetInfoParams::ICON_INFO:
                result = bformat(_("The toolbar icon for the function '%1$s'"),
                                from_utf8(params_.name));
@@ -494,6 +504,9 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
                return func.action() != LFUN_UNKNOWN_ACTION;
        }
 
+       case InsetInfoParams::L7N_INFO:
+               return !name.empty();
+
        case InsetInfoParams::ICON_INFO: {
                FuncCode const action = lyxaction.lookupFunc(name).action();
                if (action == LFUN_UNKNOWN_ACTION) {
@@ -950,6 +963,24 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
                }
                break;
        }
+       case InsetInfoParams::L7N_INFO: {
+               docstring locstring = _(params_.name);
+               // Remove trailing colons
+               locstring = rtrim(locstring, ":");
+               // Remove menu accelerators
+               if (contains(locstring, from_ascii("|"))) {
+                       docstring nlocstring;
+                       rsplit(locstring, nlocstring, '|');
+                       locstring = nlocstring;
+               }
+               // Remove Qt accelerators, but keep literal ampersands
+               locstring = subst(locstring, from_ascii(" & "), from_ascii("</amp;>"));
+               locstring = subst(locstring, from_ascii("&"), docstring());
+               locstring = subst(locstring, from_ascii("</amp;>"), from_ascii(" & "));
+               setText(locstring, guilang);
+               params_.force_ltr = !guilang->rightToLeft() && !params_.lang->rightToLeft();
+               break;
+       }
        case InsetInfoParams::ICON_INFO: {
                // only need to do this once.
                if (initialized_)
index 27aba3fced2b92e527899b7717a878ec66262ee6..ada1f4cfaeca439f994afc56b7b008f7f74d811b 100644 (file)
@@ -85,6 +85,11 @@ menu: argument is the name of the LFUN such as "paste". The syntax is the same
     triggers this LFUN. For example, "File > Paste", where '>' is actually
     \lyxarrow (an InsetSpecialChar).
 
+l7n: argument is an English string that is marked for localization. The output
+    is the localization of that string in the current GUI language (if available).
+    Trailing colons are stripped, accelerators removed.
+    This is used to refer to GUI items in the docs.
+
 icon: argument is the name of the LFUN such as "paste". The syntax is the same
     as what is used in the bind and ui files. The output is the icon use in
     the toolbar for this LFUN. Alternatively, argument can be the icon path
@@ -130,6 +135,7 @@ public:
                MENU_INFO,       // Which menu item is used for certain function
                ICON_INFO,       // which toolbar icon is used for certain function
                LYX_INFO,        // LyX version information
+               L7N_INFO,        // Localized string
                UNKNOWN_INFO,    // Invalid type
        };
        ///
index f583da6d4e4e561235781c770348be7c46f51de9..b6e6d398e586ed365bbf7e0c21b4ff159c97cf59 100644 (file)
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 561 // kornel: Added dejavu fonts
-#define LYX_FORMAT_TEX2LYX 561
+#define LYX_FORMAT_LYX 562 // spitz: l7n info inset
+#define LYX_FORMAT_TEX2LYX 562
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER