[Bf-blender-cvs] [7bd8b8cdacd] master: i18n utils: reduce dependency to Blender bpy API, step 1.
Bastien Montagne
noreply at git.blender.org
Fri Dec 4 15:14:22 CET 2020
Commit: 7bd8b8cdacd2cd7036851a77b41c4c7767f09e5e
Author: Bastien Montagne
Date: Fri Dec 4 15:04:28 2020 +0100
Branches: master
https://developer.blender.org/rB7bd8b8cdacd2cd7036851a77b41c4c7767f09e5e
i18n utils: reduce dependency to Blender bpy API, step 1.
This involves re-implementing some of Blender-defined helpers in utils,
we keep debug code to ensure those are still matching on
behavior/results sides.
This will allow to get more i18n tools independent from blender
executable.
===================================================================
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 4cb25816a34..14587100aea 100644
--- a/release/scripts/modules/bl_i18n_utils/utils.py
+++ b/release/scripts/modules/bl_i18n_utils/utils.py
@@ -39,9 +39,6 @@ import bpy
##### Misc Utils #####
-from bpy.app.translations import locale_explode
-
-
_valid_po_path_re = re.compile(r"^\S+:[0-9]+$")
@@ -79,6 +76,28 @@ def get_best_similar(data):
return key, tmp
+_locale_explode_re = re.compile(r"^([a-z]{2,})(?:_([A-Z]{2,}))?(?:@([a-z]{2,}))?$")
+
+
+def locale_explode(locale):
+ """Copies behavior of `BLT_lang_locale_explode`, keep them in sync."""
+ ret = (None, None, None, None, None)
+ m = _locale_explode_re.match(locale)
+ if m:
+ lang, country, variant = m.groups()
+ return (lang, country, variant,
+ "%s_%s" % (lang, country) if country else None,
+ "%s@%s" % (lang, variant) if variant else None)
+
+ try:
+ import bpy.app.translations as bpy_translations
+ assert(ret == bpy_translations.locale_explode(locale))
+ except ModuleNotFoundError:
+ pass
+
+ return ret
+
+
def locale_match(loc1, loc2):
"""
Return:
More information about the Bf-blender-cvs
mailing list