Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-12-04 17:10:43 +0300
committerBastien Montagne <bastien@blender.org>2020-12-04 17:14:16 +0300
commitb3306cf669fb1035c6ec2ac3569a4f3dca4aa1c2 (patch)
tree3669b5ee39151fc73b3b5e099437f29cc99e52e5
parent06ae2e3a609fdc2081108e4163b7c62540618310 (diff)
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.
-rw-r--r--release/scripts/modules/bl_i18n_utils/utils.py30
1 files changed, 30 insertions, 0 deletions
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.