[Bf-blender-cvs] [b3306cf669f] master: i18n utils: Add a helper to list and match po files with languages codes.
Bastien Montagne
noreply at git.blender.org
Fri Dec 4 15:14:22 CET 2020
Commit: b3306cf669fb1035c6ec2ac3569a4f3dca4aa1c2
Author: Bastien Montagne
Date: Fri Dec 4 15:10:43 2020 +0100
Branches: master
https://developer.blender.org/rBb3306cf669fb1035c6ec2ac3569a4f3dca4aa1c2
i18n utils: Add a helper to list and match po files with languages codes.
This code was previously done in the add-on, but we'll need it for the
CLI tool as well, so now it is a utils generator instead.
===================================================================
M release/scripts/modules/bl_i18n_utils/utils.py
===================================================================
diff --git a/release/scripts/modules/bl_i18n_utils/utils.py b/release/scripts/modules/bl_i18n_utils/utils.py
index 2224c39e48c..40b76b617b3 100644
--- a/release/scripts/modules/bl_i18n_utils/utils.py
+++ b/release/scripts/modules/bl_i18n_utils/utils.py
@@ -181,6 +181,36 @@ def get_po_files_from_dir(root_dir, langs=set()):
yield uid, po_file
+def list_po_dir(root_path, settings):
+ """
+ Generator. List given directory (expecting one sub-directory per languages)
+ and return all files matching languages listed in settings.
+
+ Yield tuples (can_use, uid, num_id, name, isocode, po_path)
+
+ Note that po_path may not actually exists.
+ """
+ isocodes = ((e, os.path.join(root_path, e, e + ".po")) for e in os.listdir(root_path))
+ isocodes = dict(e for e in isocodes if os.path.isfile(e[1]))
+ for num_id, name, uid in settings.LANGUAGES[2:]: # Skip "default" and "en" languages!
+ best_po = find_best_isocode_matches(uid, isocodes)
+ #print(uid, "->", best_po)
+ if best_po:
+ isocode = best_po[0]
+ yield (True, uid, num_id, name, isocode, isocodes[isocode])
+ else:
+ yielded = False
+ language, _1, _2, language_country, language_variant = locale_explode(uid)
+ for isocode in (language, language_variant, language_country, uid):
+ p = os.path.join(root_path, isocode, isocode + ".po")
+ if not os.path.exists(p):
+ yield (True, uid, num_id, name, isocode, p)
+ yielded = True
+ break
+ if not yielded:
+ yield (False, uid, num_id, name, None, None)
+
+
def enable_addons(addons=None, support=None, disable=False, check_only=False):
"""
Enable (or disable) addons based either on a set of names, or a set of 'support' types.
More information about the Bf-blender-cvs
mailing list