Skip to content

Commit 4a5d27f

Browse files
committed
Move translated config files to src/translations
And strip unneeded content and don't hardcode the list of languages
1 parent b3c2a7d commit 4a5d27f

11 files changed

Lines changed: 2274 additions & 6802 deletions

File tree

addon/doxywizard/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ add_custom_command(
6969
)
7070
set_source_files_properties(${GENERATED_SRC_WIZARD}/configdoc.cpp PROPERTIES GENERATED 1)
7171

72-
# Localized config.xml files are manually placed in ${PROJECT_SOURCE_DIR}/src/
72+
# Localized config.xml files are manually placed in ${PROJECT_SOURCE_DIR}/src/translations
7373
# They are referenced directly in doxywizard.qrc
7474

7575
set(LEX_FILES config_doxyw)
@@ -152,8 +152,10 @@ qt_add_resources(doxywizard_RESOURCES_RCC doxywizard.qrc)
152152
# Generate localized config.qrc
153153
set(CONFIG_QRC_CONTENT "<!DOCTYPE RCC>\n<RCC version=\"1.0\">\n<qresource prefix=\"/\">\n")
154154
string(APPEND CONFIG_QRC_CONTENT " <file alias=\"config.xml\">${PROJECT_SOURCE_DIR}/src/config.xml</file>\n")
155-
foreach(lang zh_CN zh_TW de fr ja ko es ru)
156-
string(APPEND CONFIG_QRC_CONTENT " <file alias=\"config_${lang}.xml\">${LOCALIZED_CONFIG_DIR}/config_${lang}.xml</file>\n")
155+
file(GLOB LANG_CONFIG_FILES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/translations/config_*.xml")
156+
foreach(lang_file ${LANG_CONFIG_FILES})
157+
get_filename_component(lang_name "${lang_file}" NAME) # e.g. config_zh_CN.xml
158+
string(APPEND CONFIG_QRC_CONTENT " <file alias=\"${lang_name}\">${lang_file}</file>\n")
157159
endforeach()
158160
string(APPEND CONFIG_QRC_CONTENT "</qresource>\n</RCC>\n")
159161

addon/doxywizard/doxywizard.qrc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<!DOCTYPE RCC><RCC version="1.0">
22
<qresource prefix="/">
33
<file alias="config.xml">../../src/config.xml</file>
4-
<file alias="config_zh_CN.xml">../../src/config_zh_CN.xml</file>
5-
<file alias="config_zh_TW.xml">../../src/config_zh_TW.xml</file>
6-
<file alias="config_de.xml">../../src/config_de.xml</file>
7-
<file alias="config_fr.xml">../../src/config_fr.xml</file>
8-
<file alias="config_ja.xml">../../src/config_ja.xml</file>
9-
<file alias="config_ko.xml">../../src/config_ko.xml</file>
10-
<file alias="config_es.xml">../../src/config_es.xml</file>
11-
<file alias="config_ru.xml">../../src/config_ru.xml</file>
124
<file>images/add.svg</file>
135
<file>images/del.svg</file>
146
<file>images/file.svg</file>

src/configgen.py

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import textwrap
1919
from xml.dom import Node
2020
import io
21+
import glob
2122

2223
messages = {}
2324

@@ -735,65 +736,54 @@ def parseGenerator(node):
735736
doc += n1.nodeValue.rstrip("\r\n").lstrip("\r\n")
736737
messages[name] = doc
737738

738-
LANGUAGES = ['zh_CN', 'zh_TW', 'de', 'fr', 'ja', 'ko', 'es', 'ru']
739-
740739
def collectOptions(elem):
741740
"""Collect all option IDs from config.xml."""
742741
options = set()
742+
optionsWithElems = {}
743743
for group in elem.getElementsByTagName('group'):
744744
for option in group.getElementsByTagName('option'):
745745
optionId = option.getAttribute('id')
746-
if optionId:
746+
optionType = option.getAttribute('type')
747+
if optionId and optionType!='obsolete':
747748
options.add(optionId)
748-
return options
749-
750-
def collectOptionsWithElements(elem):
751-
"""Collect all option IDs and their elements from config.xml."""
752-
options = {}
753-
for group in elem.getElementsByTagName('group'):
754-
for option in group.getElementsByTagName('option'):
755-
optionId = option.getAttribute('id')
756-
if optionId:
757-
options[optionId] = option
758-
return options
749+
optionsWithElems[optionId] = option
750+
return (options,optionsWithElems)
759751

760752
def syncLocalizedConfig(elem, translationsDir, autoSync=False):
761753
"""Sync localized config_xx.xml files with original config.xml.
762-
754+
763755
Args:
764756
elem: The root element of config.xml
765757
translationsDir: Path to translations directory
766758
autoSync: If True, automatically sync; if False, only report differences
767759
"""
768760
import os
769761
import shutil
770-
771-
existingOptions = collectOptions(elem)
772-
existingOptionsWithElements = collectOptionsWithElements(elem)
773-
print("Found %d options in config.xml" % len(existingOptions))
774-
762+
763+
existingOptions, existingOptionsWithElements = collectOptions(elem)
764+
print("Found %d active options in config.xml" % len(existingOptions))
765+
775766
srcDir = os.path.dirname(translationsDir)
776767
if os.path.basename(srcDir) == 'addon':
777768
srcDir = os.path.dirname(srcDir)
778769
srcDir = os.path.join(srcDir, 'src')
779-
780-
for lang in LANGUAGES:
781-
configFile = os.path.join(srcDir, "config_%s.xml" % lang)
782-
770+
771+
for configFile in sorted(glob.glob("translations/config_*.xml")):
772+
783773
if not os.path.exists(configFile):
784-
print("Skipping %s: config file not found" % lang)
774+
print("Skipping %s: config file not found" % configFile)
785775
continue
786-
787-
print("Processing %s..." % lang)
788-
776+
777+
print("Processing %s..." % configFile)
778+
789779
try:
790780
with io.open(configFile, 'r', encoding='utf8') as f:
791781
content = f.read()
792782
langDoc = xml.dom.minidom.parseString(content)
793783
except Exception as e:
794784
print(" Error parsing %s: %s" % (configFile, e))
795785
continue
796-
786+
797787
langOptions = set()
798788
langOptionsWithElements = {}
799789
for group in langDoc.getElementsByTagName('group'):
@@ -802,64 +792,64 @@ def syncLocalizedConfig(elem, translationsDir, autoSync=False):
802792
if optionId:
803793
langOptions.add(optionId)
804794
langOptionsWithElements[optionId] = option
805-
795+
806796
missingOptions = existingOptions - langOptions
807797
extraOptions = langOptions - existingOptions
808-
798+
809799
if missingOptions:
810800
print(" Missing %d options: %s" % (len(missingOptions), ', '.join(sorted(list(missingOptions))[:5])))
811801
if len(missingOptions) > 5:
812802
print(" ... and %d more" % (len(missingOptions) - 5))
813-
803+
814804
if extraOptions:
815805
print(" Extra %d options (not in original): %s" % (len(extraOptions), ', '.join(sorted(list(extraOptions))[:5])))
816806
if len(extraOptions) > 5:
817807
print(" ... and %d more" % (len(extraOptions) - 5))
818-
808+
819809
if not missingOptions and not extraOptions:
820810
print(" OK - all options synchronized")
821811
continue
822-
812+
823813
if autoSync and (missingOptions or extraOptions):
824814
print(" Auto-syncing...")
825-
815+
826816
rootElement = langDoc.documentElement
827-
817+
828818
for optionId in extraOptions:
829819
optionElem = langOptionsWithElements[optionId]
830820
parentGroup = optionElem.parentNode
831821
parentGroup.removeChild(optionElem)
832822
print(" Removed: %s" % optionId)
833-
823+
834824
for optionId in missingOptions:
835825
optionElem = existingOptionsWithElements[optionId]
836826
importedElem = langDoc.importNode(optionElem, True)
837-
827+
838828
parentGroup = None
839829
for group in rootElement.getElementsByTagName('group'):
840830
parentGroup = group
841831
break
842-
832+
843833
if parentGroup:
844834
parentGroup.appendChild(importedElem)
845835
print(" Added: %s" % optionId)
846-
836+
847837
backupFile = configFile + ".bak"
848838
shutil.copy2(configFile, backupFile)
849-
839+
850840
outputContent = langDoc.toprettyxml(indent=' ', encoding='utf-8')
851841
outputStr = outputContent.decode('utf-8') if isinstance(outputContent, bytes) else outputContent
852-
842+
853843
lines = outputStr.split('\n')
854844
filteredLines = [line for line in lines if line.strip()]
855845
outputStr = '\n'.join(filteredLines)
856-
846+
857847
with io.open(configFile, 'w', encoding='utf8') as f:
858848
f.write(outputStr)
859-
849+
860850
print(" Backup saved to: %s" % backupFile)
861851
print(" File updated: %s" % configFile)
862-
852+
863853
print("\nSync %s!" % ("complete" if not autoSync else "and update complete"))
864854

865855
def main():
@@ -1104,7 +1094,7 @@ def main():
11041094
parseGroupCDocs(n)
11051095
print("}")
11061096
elif (sys.argv[1] == "-sync"):
1107-
if len(sys.argv) < 4:
1097+
if len(sys.argv) < 3:
11081098
sys.exit('Usage: %s -sync config.xml translations_dir [--auto]' % sys.argv[0])
11091099
translationsDir = sys.argv[3]
11101100
autoSync = '--auto' in sys.argv

0 commit comments

Comments
 (0)