diff --git a/development/FORMAT b/development/FORMAT index 4bf2519331..2ae38024b7 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,11 @@ changes happened in particular if possible. A good example would be ----------------------- +2018-08-13 Jürgen Spitzmüller + * 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 * format incremented to 561: Added DejaVu fonts diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 1574fb5d3c..2d6caabaa4 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -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(" & ", "").replace("&", "").replace("", " & ") + 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]], diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index d73b2a9b59..4f424883f7 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1930,7 +1930,8 @@ void LyXAction::init() the work area.\n 2. select the text and run info-insert lfun. * \li Syntax: info-insert - * \li Params: : shortcut[s]|lyxrc|lyxinfo|package|textclass|menu|icon|buffer \n + * \li Params: : date|moddate|fixdate|time|modtime|fixtime|shortcut|shortcuts|lyxrc| + * lyxinfo|package|textclass|menu|l7n|icon|buffer|vcs \n : 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" diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index a499461282..9fec218775 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -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. " diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index da78a11075..4d39015966 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -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> 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 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("")); + locstring = subst(locstring, from_ascii("&"), docstring()); + locstring = subst(locstring, from_ascii(""), 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_) diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 27aba3fced..ada1f4cfae 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -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 }; /// diff --git a/src/version.h b/src/version.h index f583da6d4e..b6e6d398e5 100644 --- a/src/version.h +++ b/src/version.h @@ -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