From b6faf9144777aeeff6171e24dd243152700bc1a4 Mon Sep 17 00:00:00 2001 From: derek riemer Date: Sat, 17 Jun 2023 15:15:30 -0600 Subject: [PATCH] Depend on the correct moFile for a given md file. We need the correct title for a given languages translated documentation, which comes from the moFile. However, the previous version of the build script accidentally depended on a variable assigned inside the for loop which was used to assign the languages actual moFile. This loop variable is assigned inside the loop, and not outside it, is overridden on each iteration, and is not persisted anywhere so we cann reference the correct moFile when we later generate the html. This pr fixes that. in this pr, I create a moByLang dictionary, and store the moFile as a value. The key for this moFile is the language code. That way, the html for language KR depends on the moFile for kr, and not the moFile for whatever language was last assigned in the for loop. That way, if the ES languagges po file updates, the dependency system will correctly attribute that Korean is the language we need to regenenrate HTML for. This also undoes the try/except logic that incorrectly hid the real issue, which was the inappropriate refrencing of a for loop variable that may have never been created. --- sconstruct | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sconstruct b/sconstruct index f1bad99..9596a33 100644 --- a/sconstruct +++ b/sconstruct @@ -279,9 +279,11 @@ addon = env.NVDAAddon(addonFile, env.Dir('addon')) langDirs = [f for f in env.Glob(os.path.join("addon", "locale", "*"))] # Allow all NVDA's gettext po files to be compiled in source/locale, and manifest files to be generated +moByLang = {} for dir in langDirs: poFile = dir.File(os.path.join("LC_MESSAGES", "nvda.po")) moFile = env.gettextMoFile(poFile) + moByLang[dir] = moFile env.Depends(moFile, poFile) translatedManifest = env.NVDATranslatedManifest( dir.File("manifest.ini"), @@ -298,13 +300,14 @@ for file in pythonFiles: # We need at least doc in English and should enable the Help button for the add-on in Add-ons Manager createAddonHelp("addon") for mdFile in env.Glob(os.path.join('addon', 'doc', '*', '*.md')): + # the title of the html file is translated based on the contents of something in the moFile for a language. + # Thus, we find the moFile for this language and depend on it if it exists. + lang = os.path.basename(os.path.dirname(mdFile.get_abspath())) + moFile = moByLang.get(lang) htmlFile = env.markdown(mdFile) - try: # It is possible that no moFile was set, because an add-on has no translations. - moFile - except NameError: # Runs if there is no moFile - env.Depends(htmlFile, mdFile) - else: # Runs if there is a moFile - env.Depends(htmlFile, [mdFile, moFile]) + env.Depends(htmlFile, mdFile) + if moFile: + env.Depends(htmlFile, moFile) env.Depends(addon, htmlFile) # Pot target