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.

This can be used to refer to dialog items in the docs in a portable way.
This commit is contained in:
Juergen Spitzmueller 2018-08-13 17:18:44 +02:00
parent ad3d711b0e
commit e9b187af08
7 changed files with 81 additions and 4 deletions

View 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> 2018-08-10 Kornel Benko <kornel@lyx.org>
* format incremented to 561: Added DejaVu fonts * format incremented to 561: Added DejaVu fonts

View File

@ -1129,6 +1129,32 @@ def revert_namenoextinfo(document):
i = i + 1 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 # Conversion hub
# #
@ -1151,10 +1177,12 @@ convert = [
[558, [removeFrontMatterStyles]], [558, [removeFrontMatterStyles]],
[559, []], [559, []],
[560, []], [560, []],
[561, [convert_dejavu]] [561, [convert_dejavu]],
[562, []]
] ]
revert = [ revert = [
[561, [revert_l7ninfo]],
[560, [revert_dejavu]], [560, [revert_dejavu]],
[559, [revert_timeinfo, revert_namenoextinfo]], [559, [revert_timeinfo, revert_namenoextinfo]],
[558, [revert_dateinfo]], [558, [revert_dateinfo]],

View File

@ -1930,7 +1930,8 @@ void LyXAction::init()
the work area.\n the work area.\n
2. select the text and run info-insert lfun. 2. select the text and run info-insert lfun.
* \li Syntax: info-insert <TYPE> <ARG> * \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 <ARG>: argument for a given type. Look into InsetInfo.h for detailed
description. \n description. \n
date: current date (formatted and localized)\n date: current date (formatted and localized)\n
@ -1945,6 +1946,7 @@ void LyXAction::init()
package: name of latex package (e.g. listings) \n package: name of latex package (e.g. listings) \n
textclass: name of textclass (e.g. article) \n textclass: name of textclass (e.g. article) \n
menu: name of lfun used in menu \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 icon: icon of lfun used in toolbar or direct icon name\n
buffer: "name"|"name-noext"|"path"|"class" buffer: "name"|"name-noext"|"path"|"class"
vcs: "tree-revision"|"revision"|"author"|"date"|"time" vcs: "tree-revision"|"revision"|"author"|"date"|"time"

View File

@ -58,6 +58,7 @@ char const * info_types[] =
"shortcut", "shortcut",
"shortcuts", "shortcuts",
"menu", "menu",
"l7n",
"icon", "icon",
"lyxrc", "lyxrc",
"lyxinfo", "lyxinfo",
@ -79,6 +80,7 @@ char const * info_types_gui[] =
N_("Last Assigned Keyboard Shortcut"),// shortcut N_("Last Assigned Keyboard Shortcut"),// shortcut
N_("All Keyboard Shortcuts"),// shortcuts N_("All Keyboard Shortcuts"),// shortcuts
N_("LyX Menu Location"),// menu N_("LyX Menu Location"),// menu
N_("Localized GUI String"),// l7n
N_("LyX Toolbar Icon"),// icon N_("LyX Toolbar Icon"),// icon
N_("LyX Preferences Entry"),// lyxrc N_("LyX Preferences Entry"),// lyxrc
N_("LyX Application Information"),// lyxinfo N_("LyX Application Information"),// lyxinfo
@ -100,6 +102,7 @@ char const * info_name_gui[] =
N_("LyX Function"),// shortcut N_("LyX Function"),// shortcut
N_("LyX Function"),// shortcuts N_("LyX Function"),// shortcuts
N_("LyX Function"),// menu N_("LyX Function"),// menu
N_("English String"),// l7n
N_("LyX Function"),// icon N_("LyX Function"),// icon
N_("Preferences Key"),// lyxrc N_("Preferences Key"),// lyxrc
N_("Not Applicable"),// lyxinfo N_("Not Applicable"),// lyxinfo
@ -196,6 +199,8 @@ char const * info_tooltip[] =
"The output lists all possible keyboard shortcuts for this function"),// shortcuts "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. " 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 "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. " 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 "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. " N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "

View File

@ -75,6 +75,7 @@ NameTranslator const initTranslator()
translator.addPair(InsetInfoParams::PACKAGE_INFO, "package"); translator.addPair(InsetInfoParams::PACKAGE_INFO, "package");
translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "textclass"); translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "textclass");
translator.addPair(InsetInfoParams::MENU_INFO, "menu"); translator.addPair(InsetInfoParams::MENU_INFO, "menu");
translator.addPair(InsetInfoParams::L7N_INFO, "l7n");
translator.addPair(InsetInfoParams::ICON_INFO, "icon"); translator.addPair(InsetInfoParams::ICON_INFO, "icon");
translator.addPair(InsetInfoParams::BUFFER_INFO, "buffer"); translator.addPair(InsetInfoParams::BUFFER_INFO, "buffer");
translator.addPair(InsetInfoParams::LYX_INFO, "lyxinfo"); translator.addPair(InsetInfoParams::LYX_INFO, "lyxinfo");
@ -109,6 +110,7 @@ DefaultValueTranslator const initDVTranslator()
translator.addPair(InsetInfoParams::PACKAGE_INFO, "graphics"); translator.addPair(InsetInfoParams::PACKAGE_INFO, "graphics");
translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "article"); translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "article");
translator.addPair(InsetInfoParams::MENU_INFO, "info-insert"); translator.addPair(InsetInfoParams::MENU_INFO, "info-insert");
translator.addPair(InsetInfoParams::L7N_INFO, "");
translator.addPair(InsetInfoParams::ICON_INFO, "info-insert"); translator.addPair(InsetInfoParams::ICON_INFO, "info-insert");
translator.addPair(InsetInfoParams::BUFFER_INFO, "name-noext"); translator.addPair(InsetInfoParams::BUFFER_INFO, "name-noext");
translator.addPair(InsetInfoParams::LYX_INFO, "version"); translator.addPair(InsetInfoParams::LYX_INFO, "version");
@ -231,6 +233,10 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
break; break;
} }
case L7N_INFO:
result.push_back(make_pair("custom", _("Custom")));
break;
case LYXRC_INFO: { case LYXRC_INFO: {
result.push_back(make_pair("custom", _("Custom"))); result.push_back(make_pair("custom", _("Custom")));
set<string> rcs = lyxrc.getRCs(); 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'"), result = bformat(_("The menu location for the function '%1$s'"),
from_utf8(params_.name)); from_utf8(params_.name));
break; break;
case InsetInfoParams::L7N_INFO:
result = bformat(_("The localization for the string '%1$s'"),
from_utf8(params_.name));
break;
case InsetInfoParams::ICON_INFO: case InsetInfoParams::ICON_INFO:
result = bformat(_("The toolbar icon for the function '%1$s'"), result = bformat(_("The toolbar icon for the function '%1$s'"),
from_utf8(params_.name)); from_utf8(params_.name));
@ -494,6 +504,9 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
return func.action() != LFUN_UNKNOWN_ACTION; return func.action() != LFUN_UNKNOWN_ACTION;
} }
case InsetInfoParams::L7N_INFO:
return !name.empty();
case InsetInfoParams::ICON_INFO: { case InsetInfoParams::ICON_INFO: {
FuncCode const action = lyxaction.lookupFunc(name).action(); FuncCode const action = lyxaction.lookupFunc(name).action();
if (action == LFUN_UNKNOWN_ACTION) { if (action == LFUN_UNKNOWN_ACTION) {
@ -950,6 +963,24 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
} }
break; 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: { case InsetInfoParams::ICON_INFO: {
// only need to do this once. // only need to do this once.
if (initialized_) if (initialized_)

View 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 triggers this LFUN. For example, "File > Paste", where '>' is actually
\lyxarrow (an InsetSpecialChar). \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 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 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 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 MENU_INFO, // Which menu item is used for certain function
ICON_INFO, // which toolbar icon is used for certain function ICON_INFO, // which toolbar icon is used for certain function
LYX_INFO, // LyX version information LYX_INFO, // LyX version information
L7N_INFO, // Localized string
UNKNOWN_INFO, // Invalid type UNKNOWN_INFO, // Invalid type
}; };
/// ///

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
#define LYX_FORMAT_LYX 561 // kornel: Added dejavu fonts #define LYX_FORMAT_LYX 562 // spitz: l7n info inset
#define LYX_FORMAT_TEX2LYX 561 #define LYX_FORMAT_TEX2LYX 562
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER #ifndef _MSC_VER