File indexing completed on 2023-05-30 10:41:17
0001 #!/usr/bin/python 0002 # 0003 # GCompris - wordlist-json-2html.py 0004 # 0005 # SPDX-FileCopyrightText: 2018 Johnny Jazeix <jazeix@gmail.com> 0006 # 0007 # SPDX-License-Identifier: GPL-3.0-or-later 0008 0009 import json 0010 0011 wordsFile="../src/activities/lang/resource/words.json" 0012 0013 with open(wordsFile) as data_file: 0014 try: 0015 data = json.load(data_file) 0016 print("Processing OK " + wordsFile) 0017 except ValueError as e: 0018 print(dir(e)) 0019 print("Processing KO " + wordsFile) 0020 print("Parser error: {0}".format(e.message)) 0021 0022 header="""<html dir=\"ltr\" lang=\"fr\"> 0023 <head> 0024 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> 0025 </head> 0026 <body> 0027 <a name=\"words_by_section\" href=\"words_by_section.html\"/>Same list of words by section</a> 0028 <p></p> 0029 <a name=\"empty json\" href=\"words.json\"/>Empty json data file ready to be translated</a> 0030 <hr> 0031 """ 0032 0033 footer= """ 0034 </body> 0035 </html>""" 0036 0037 orderedData = {} 0038 0039 with open("words_by_section.html", "w") as section_file: 0040 section_file.write("""<html dir=\"ltr\" lang=\"fr\"> 0041 0042 <head> 0043 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> 0044 </head> 0045 <body> 0046 0047 """) 0048 for chapter in data: 0049 for lesson in chapter["content"]: 0050 lessonName = lesson["name"]; 0051 if lessonName == "otherLesson": 0052 lessonName = "other" 0053 section_file.write(" <h1>" + lessonName + "</h1>\n") 0054 for content in lesson["content"]: 0055 # store the info for words.html 0056 orderedData[content["description"]] = { 0057 "image": content["image"], 0058 "section": lessonName 0059 }; 0060 # write in the file 0061 section_file.write(""" <a name=\""""+content["description"]+"""\" href=\"lang/""" + content["image"] + """\"><img src=\"lang/"""+content["image"] + """\"/></a> 0062 <p>"""+content["description"]+"""</p> 0063 <hr/> 0064 """) 0065 section_file.write(footer) 0066 0067 with open("words.html", "w") as words_file: 0068 words_file.write(header) 0069 for key in sorted(orderedData): 0070 words_file.write(" <a name=\""+key+"\" href=\"lang/"+orderedData[key]["image"]+"\"><img src=\"lang/"+orderedData[key]["image"]+"\"/></a><p>"+key+" ("+orderedData[key]["section"]+")</p><hr/>\n") 0071 words_file.write(footer)