X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fdoc%2Fdoc_toc.py;h=5ecca5ed0851e5f074de3df56bec7cabf235ba51;hb=8be71ab8e20c7299c9ff4e986184d7d32abeb2a3;hp=7277d698370b1553bff803c2a0d33de30d7fac2b;hpb=fa133e49b9a1adab68b6335dc919d916f3e8e821;p=lyx.git diff --git a/lib/doc/doc_toc.py b/lib/doc/doc_toc.py index 7277d69837..5ecca5ed08 100755 --- a/lib/doc/doc_toc.py +++ b/lib/doc/doc_toc.py @@ -1,7 +1,7 @@ #! /usr/bin/env python -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # This file is part of the LyX Documentation -# Copyright (C) 2004 José Matos +# Copyright (C) 2004 José Matos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,32 +17,45 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# This script creates a "master table of contents" for a set of LyX docs. +# This script is called by the script depend.py to create a "master table of contents" +# for a set of LyX docs. # It does so by going through the files and printing out all of the # chapter, section, and sub(sub)section headings out. (It numbers the # sections sequentially; hopefully noone's using Section* in the docs.) +# It is called using this syntax: +# depend.py doc_toc.py SetOfDocuments +# where SetOfDocuments is a set of documents import sys import os -sys.path.insert(0,"../lyx2lyx") +if __name__ == "__main__": + srcdir = os.path.dirname(sys.argv[0]) + if srcdir == '': + srcdir = '.' + sys.path.insert(0, srcdir + "/../lyx2lyx") + +# when doc_toc is imported by scons, sys.path is set over there import parser_tools import LyX import depend # Specific language information -# info["isoname"] = (language, language_quotes, enconding, TOC_translated) -info = { 'da' : ('danish', 'german', 'latin1', "Indholdsfortegnelse over LyX's dokumentation"), - 'de' : ('german', 'german', 'latin1', "Inhaltsverzeichnis LyX Dokumentation"), - 'fr' : ('french', 'french', 'latin1', "Plan de la documentation"), - 'ru' : ('russian', 'english', 'koi8-r', "LyX Documentation Table of Contents"), - 'sl' : ('slovene', 'german', 'latin2', "Kazalo dokumentacije LyXa"), - 'en' : ('english', 'english', 'latin1', "LyX Documentation Table of Contents")} +# info["isoname"] = (language, language_quotes, TOC_translated) +info = { 'cs' : ('czech', 'german', u"Obsah dokumentace LyXu"), + 'da' : ('danish', 'german', u"Indholdsfortegnelse over LyX's dokumentation"), + 'de' : ('german', 'german', u"Inhaltsverzeichnis LyX Dokumentation"), + 'es' : ('spanish', 'spanish', u"Índice general LyX documentation"), + 'fr' : ('french', 'french', u"Plan de la documentation LyX"), + 'ja' : ('japanese', 'japanese', u"LyX取扱説明書目次"), + 'ru' : ('russian', 'english', u"LyX Documentation Table of Contents"), + 'sl' : ('slovene', 'german', u"Kazalo dokumentacije LyXa"), + 'en' : ('english', 'english', u"LyX Documentation Table of Contents")} def usage(pname): - print """Usage: %s [lang] + print """Usage: %s lang output - lang is the language to build the TOC file, if not present use english. + lang is the language to build the TOC file, """ % pname @@ -60,7 +73,7 @@ def build_from_toc(par_list): if len(par_list) == 1: return par_list - + for i in range(1, len(par_list)): if par_list[i].name == 'Title': return [par] + \ @@ -80,7 +93,7 @@ def nest_struct(name, par_list): if len(par_list) == 1: return par_list - + for i in range(1, len(par_list)): if par_list[i].name == name: par.child = build_from_toc(par_list[1:i]) @@ -89,37 +102,53 @@ def nest_struct(name, par_list): return [ par ] -def main(argv): - if len(argv) > 2: - usage() - sys.exit(1) - - # choose language and prefix for files - if len(argv) == 1: - lang = "en" - pref = "" - else: - lang = argv[1] - pref = lang + '_' - # fallback - if lang not in info: - lang = 'en' - +def build_toc(output, documents, lang=None): # Determine existing translated documents for that language. toc_general = [] - for file in depend.documents(pref): + for file in documents: file = LyX.File(input= file) file.convert() toc_general.extend(file.get_toc()) - - file = LyX.NewFile(output= pref + 'TOC.lyx') + + # if lang is not given, guess from document names. (Used in scons build) + if lang is None: + lang = 'en' + for file in documents: + dir = file.split(os.sep)[-2] + if dir in info.keys(): + lang = dir + file = LyX.NewFile(output = output) data = info[lang] - file.set_header(language = data[0], language_quotes = data[1], inputencoding = data[2]) - body = [ LyX.Paragraph('Title', [data[3]])] + file.set_header(language = data[0], language_quotes = data[1], inputencoding = "auto") + file.language = data[0] + file.encoding = "utf-8" + body = [ LyX.Paragraph('Title', [data[2]])] body.extend(build_from_toc(toc_general)) file.set_body(body) file.write() + +def main(argv): + if len(argv) != 3: + usage(argv[0]) + sys.exit(1) + + lang = argv[1] + if not os.path.isdir(os.path.join(argv[2], lang)): + # need to create lang dir if build dir != src dir + os.mkdir(os.path.join(argv[2], lang)) + + # choose language files + if lang == 'en': + output = os.path.join(argv[2], 'TOC.lyx') + else: + output = os.path.join(argv[2], lang, 'TOC.lyx') + # fallback + if lang not in info: + lang = 'en' + + build_toc(output, depend.documents(srcdir, lang), lang) + if __name__ == "__main__": main(sys.argv)