1
0
Fork 0

Catalog I18N support

Read I18N satrings form aircraft data and add to the catalog
This commit is contained in:
Automatic Release Builder 2020-06-21 19:25:18 +01:00
parent 3a36bdd474
commit cef19a8b13
4 changed files with 75 additions and 2 deletions

View file

@ -7,6 +7,17 @@
<primary-set type="bool">true</primary-set>
<localized>
<de>
<long-description>Describe the F16-A in German</long-description>
</de>
<fr>
<long-description>Describe the F16-A in French</long-description>
</fr>
</localized>
<rating>
<FDM type="int">3</FDM>
<systems type="int">1</systems>

View file

@ -6,6 +6,16 @@
<long-description>The F16-B is an upgraded version of the F16A.</long-description>
<variant-of>f16a</variant-of>
<localized>
<de>
<long-description>Describe the F16-B in German</long-description>
</de>
<fr>
<long-description>Describe the F16-B in French</long-description>
</fr>
</localized>
<authors n="0">
<author n="0">
<name>James T Kirk</name>

View file

@ -40,6 +40,9 @@ class UpdateCatalogTests(unittest.TestCase):
self.assertEqual(authors.getValue('author[0]/email'), 'ww@wright.com')
self.assertEqual(authors.getValue('author[1]/name'), 'Orville Wright')
locDe = info['localized']['de']
self.assertEqual(locDe["long-description"], "Describe the F16-A in German")
def test_scan_dir(self):
(pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/f16", ["testData/OtherDir"])
@ -60,6 +63,9 @@ class UpdateCatalogTests(unittest.TestCase):
self.assertEqual(f16b['variant-of'], 'f16a')
self.assertEqual(f16b['primary-set'], False)
locFr = f16b['localized']['fr']
self.assertEqual(locFr["long-description"], "Describe the F16-B in French")
authorsArray = f16b['authors']
self.assertNotIn('author', f16b)
@ -135,8 +141,9 @@ class UpdateCatalogTests(unittest.TestCase):
self.assertEqual(parsedPkgNode.getValue('rating/cockpit'), 2)
self.assertEqual(parsedPkgNode.getValue('rating/model'), 5)
self.assertEqual(parsedPkgNode.getValue('localized/de/long-description'), "Describe the F16-A in German")
# author data verification
# author data verification
self.assertFalse(parsedPkgNode.hasChild('author'));
parsedAuthors = parsedPkgNode.getChild("authors").getChildren('author')
@ -172,6 +179,9 @@ class UpdateCatalogTests(unittest.TestCase):
self.assertEqual(author1.getValue("email"), "shatner@enterprise.com")
self.assertEqual(author1.getValue("description"), "Everything")
self.assertEqual(pv.getValue('localized/de/long-description'), "Describe the F16-B in German")
def test_node_creation2(self):
(pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/dc3", ["testData/OtherDir"])

View file

@ -11,7 +11,7 @@ import re
import sys
import zipfile
from flightgear.meta import sgprops
from flightgear.meta import sgprops, strutils
from . import catalogTags
CATALOG_VERSION = 4
@ -113,9 +113,13 @@ def scan_set_file(aircraft_dir, set_file, includes):
if sim_node.hasChild('minimum-fg-version'):
variant['minimum-fg-version'] = sim_node.getValue('minimum-fg-version', None)
if sim_node.hasChild('localized'):
variant['localized'] = extract_localized_strings(sim_node.getChild('localized'))
#print(" %s" % variant)
return variant
def extract_previews(previews_node, aircraft_dir):
result = []
for node in previews_node.getChildren("preview"):
@ -131,6 +135,7 @@ def extract_previews(previews_node, aircraft_dir):
return result
def extract_tags(tags_node, set_path):
result = []
for node in tags_node.getChildren("tag"):
@ -142,6 +147,22 @@ def extract_tags(tags_node, set_path):
return result
def extract_localized_strings(localized_node):
result = {}
# iterate langauges below <localized>
for lang in localized_node.getChildren():
strings = {}
# iterate strings below <de> etc
for s in lang.getChildren():
strings[s.name] = strutils.simplify(s.value)
if strings:
result[lang.name] = strings
return result
# scan all the -set.xml files in an aircraft directory. Returns a
# package dict and a list of variants.
def scan_aircraft_dir(aircraft_dir, includes):
@ -199,6 +220,7 @@ def make_xml_leaf(name, text):
leaf.text = ''
return leaf
def append_preview_nodes(node, variant, download_base, package_name):
if not 'previews' in variant:
return
@ -211,6 +233,7 @@ def append_preview_nodes(node, variant, download_base, package_name):
preview_node.append( make_xml_leaf('path', preview['path']) )
node.append(preview_node)
def append_tag_nodes(node, variant):
if not 'tags' in variant:
return
@ -218,6 +241,7 @@ def append_tag_nodes(node, variant):
for tag in variant['tags']:
node.append(make_xml_leaf('tag', tag))
def append_author_nodes(node, info):
if 'authors' in info:
node.append(info['authors']._createXMLElement())
@ -225,6 +249,22 @@ def append_author_nodes(node, info):
# traditional single author string
node.append( make_xml_leaf('author', info['author']) )
def append_localized_strings(node, variant):
if not 'localized' in variant:
return
localized_node = ET.Element('localized')
for lang, v in variant['localized'].items():
lang_node = ET.Element(lang)
for skey, s in v.items():
lang_node.append(make_xml_leaf(skey, s))
localized_node.append(lang_node)
node.append(localized_node)
def make_aircraft_node(aircraftDirName, package, variants, downloadBase, mirrors):
#print("package: %s" % package)
#print("variants: %s" % variants)
@ -271,6 +311,7 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase, mirrors
append_preview_nodes(variant_node, variant, downloadBase, aircraftDirName)
append_tag_nodes(variant_node, variant)
append_author_nodes(variant_node, variant)
append_localized_strings(variant_node, variant)
package_node.append( make_xml_leaf('dir', aircraftDirName) )
@ -290,6 +331,7 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase, mirrors
append_preview_nodes(package_node, package, downloadBase, aircraftDirName)
append_tag_nodes(package_node, package)
append_localized_strings(package_node, package)
if 'maintainers' in package:
package_node.append(package['maintainers']._createXMLElement())