*** fix bug 2488 (make dynamic formats in menus translatable) ***

* po/lyx_pot.py:
	- new method formats_l10n that parses configure.py for file formats and shortcuts
* po/Makefile.in.in:
* development/scons/SConstruct:
	- call formats_l10n on po update

* src/frontends/qt4/Menus.cpp:
	- handle translated formats

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24833 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-05-19 09:33:53 +00:00
parent 2134c42dd5
commit 21bd7671ec
4 changed files with 57 additions and 17 deletions

View File

@ -1762,7 +1762,7 @@ if 'update_po' in BUILD_TARGETS:
['$TOP_SRCDIR/src/tex2lyx/%s' % x for x in src_tex2lyx_header_files + src_tex2lyx_files ]
)
Alias('update_po', POTFILES_in)
# build language_l10n.pot, ui_l10n.pot, layouts_l10n.pot, qt4_l10n.pot, external_l10n
# build language_l10n.pot, ui_l10n.pot, layouts_l10n.pot, qt4_l10n.pot, external_l10n, formats_l10n
# and combine them to lyx.po
env['LYX_POT'] = 'python $TOP_SRCDIR/po/lyx_pot.py'
lyx_po = env.Command('$BUILDDIR/po/lyx.po',
@ -1780,6 +1780,8 @@ if 'update_po' in BUILD_TARGETS:
'$LYX_POT -b $TOP_SRCDIR -t ui -o $TARGET $SOURCES'),
env.Command('$BUILDDIR/po/external_l10n.pot', '$TOP_SRCDIR/lib/external_templates',
'$LYX_POT -b $TOP_SRCDIR -t external -o $TARGET $SOURCES'),
env.Command('$BUILDDIR/po/formats_l10n.pot', '$TOP_SRCDIR/lib/configure.py',
'$LYX_POT -b $TOP_SRCDIR -t formats -o $TARGET $SOURCES'),
], utils.env_cat),
['$MSGUNIQ -o $TARGET $SOURCE',
'''$XGETTEXT --default-domain=${TARGET.base} \

View File

@ -393,7 +393,7 @@ ${srcdir}/POTFILES.in: $(POTFILE_IN_DEPS)
sort | uniq ) > $@-t \
&& mv $@-t $@
l10n_pots: qt4_l10n.pot layouts_l10n.pot languages_l10n.pot ui_l10n.pot external_l10n.pot
l10n_pots: qt4_l10n.pot layouts_l10n.pot languages_l10n.pot ui_l10n.pot external_l10n.pot formats_l10n.pot
cat $^ | \
msguniq -o $(DOMAIN).po && rm -f $^
@ -420,6 +420,9 @@ i18n.inc: $(POFILES) postats.py
external_l10n.pot: $(top_srcdir)/lib/external_templates
python $(srcdir)/lyx_pot.py -b $(top_srcdir) -o $@ -t external ${top_srcdir}/lib/external_templates
formats_l10n.pot: $(top_srcdir)/lib/configure.py
python $(srcdir)/lyx_pot.py -b $(top_srcdir) -o $@ -t formats ${top_srcdir}/lib/configure.py
force:
# Tell versions [3.59,3.63) of GNU make not to export all variables.

View File

@ -245,6 +245,36 @@ def external_l10n(input_files, output, base):
output.close()
def formats_l10n(input_files, output, base):
'''Generate pot file from configure.py'''
output = open(output, 'w')
GuiName = re.compile(r'.*\Format\s+\S+\s+\S+\s+"([^"]*)"\s+(\S*)\s+.*')
GuiName2 = re.compile(r'.*\Format\s+\S+\s+\S+\s+([^"]\S+)\s+(\S*)\s+.*')
input = open(input_files[0])
for lineno, line in enumerate(input.readlines()):
label = ""
labelsc = ""
if GuiName.match(line):
label = GuiName.match(line).group(1)
shortcut = GuiName.match(line).group(2).replace('"', '')
elif GuiName2.match(line):
label = GuiName2.match(line).group(1)
shortcut = GuiName2.match(line).group(2).replace('"', '')
else:
continue
label = label.replace('\\', '\\\\').replace('"', '')
if shortcut != "":
labelsc = label + "|" + shortcut
if label != "":
print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
(relativePath(input_files[0], base), lineno+1, label)
if labelsc != "":
print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
(relativePath(input_files[0], base), lineno+1, labelsc)
input.close()
output.close()
Usage = '''
lyx_pot.py [-b|--base top_src_dir] [-o|--output output_file] [-h|--help] -t|--type input_type input_files
@ -259,6 +289,7 @@ where
qt4: qt4 ui files
languages: file lib/languages
external: external templates file
formats: formats predefined in lib/configure.py
'''
if __name__ == '__main__':
@ -278,7 +309,7 @@ if __name__ == '__main__':
base = value
elif opt in ['-t', '--type']:
input_type = value
if input_type not in ['ui', 'layouts', 'modules', 'qt4', 'languages', 'external'] or output is None:
if input_type not in ['ui', 'layouts', 'modules', 'qt4', 'languages', 'external', 'formats'] or output is None:
print 'Wrong input type or output filename.'
sys.exit(1)
if input_type == 'ui':
@ -289,6 +320,8 @@ if __name__ == '__main__':
qt4_l10n(args, output, base)
elif input_type == 'external':
external_l10n(args, output, base)
elif input_type == 'formats':
formats_l10n(args, output, base)
else:
languages_l10n(args, output, base)

View File

@ -755,17 +755,24 @@ void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
for (; fit != end ; ++fit) {
if ((*fit)->dummy())
continue;
QString label = toqstr((*fit)->prettyname());
QString const shortcut = toqstr((*fit)->shortcut());
docstring lab = from_utf8((*fit)->prettyname());
docstring scut = from_utf8((*fit)->shortcut());
docstring const tmplab = lab;
if (!scut.empty())
lab += char_type('|') + scut;
docstring lab_i18n = translateIfPossible(lab);
bool const untranslated = (lab == lab_i18n);
QString const shortcut = toqstr(split(lab_i18n, lab, '|'));
QString label = toqstr(lab);
if (untranslated)
// this might happen if the shortcut
// has been redefined
label = toqstr(translateIfPossible(tmplab));
switch (kind) {
case MenuItem::ImportFormats:
// FIXME: This is a hack, we should rather solve
// FIXME: bug 2488 instead.
if ((*fit)->name() == "text")
label = qt_("Plain Text");
else if ((*fit)->name() == "textparagraph")
label = qt_("Plain Text, Join Lines");
label += "...";
break;
case MenuItem::ViewFormats:
@ -778,12 +785,7 @@ void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
LASSERT(false, /**/);
break;
}
// FIXME: if we had proper support for translating the
// format names defined in configure.py, there would
// not be a need to check whether the shortcut is
// correct. If we add it uncondiitonally, it would
// create useless warnings on bad shortcuts
if (!shortcut.isEmpty() && label.contains(shortcut))
if (!shortcut.isEmpty())
label += '|' + shortcut;
if (buf)