diff options
author | Remco Burema <r.burema@ultimaker.com> | 2019-11-14 20:26:46 +0300 |
---|---|---|
committer | Remco Burema <r.burema@ultimaker.com> | 2019-11-14 20:26:46 +0300 |
commit | 22fe13890eb950dce8e82ac9d8cd98f28cb848f1 (patch) | |
tree | d68fc8796457feb2536eec351765b97c5553e881 | |
parent | ed63a9037d9fbb504405469eb79e28c618467ca6 (diff) |
Make sure translations are loaded before init. Intents.
part of CURA-6957
-rw-r--r-- | cura/Machines/Models/IntentCategoryModel.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index cb81aec3c7..48889b1144 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/cura/Machines/Models/IntentCategoryModel.py @@ -29,24 +29,29 @@ class IntentCategoryModel(ListModel): modelUpdated = pyqtSignal() + _translations = collections.OrderedDict() # type: "collections.OrderedDict[str,Dict[str,Optional[str]]]" + # Translations to user-visible string. Ordered by weight. # TODO: Create a solution for this name and weight to be used dynamically. - _translations = collections.OrderedDict() # type: "collections.OrderedDict[str,Dict[str,Optional[str]]]" - _translations["default"] = { - "name": catalog.i18nc("@label", "Default") - } - _translations["visual"] = { - "name": catalog.i18nc("@label", "Visual"), - "description": catalog.i18nc("@text", "The visual profile is designed to print visual prototypes and models with the intent of high visual and surface quality.") - } - _translations["engineering"] = { - "name": catalog.i18nc("@label", "Engineering"), - "description": catalog.i18nc("@text", "The engineering profile is designed to print functional prototypes and end-use parts with the intent of better accuracy and for closer tolerances.") - } - _translations["quick"] = { - "name": catalog.i18nc("@label", "Draft"), - "description": catalog.i18nc("@text", "The draft profile is designed to print initial prototypes and concept validation with the intent of significant print time reduction.") - } + @classmethod + def _get_translations(cls): + if len(cls._translations) == 0: + cls._translations["default"] = { + "name": catalog.i18nc("@label", "Default") + } + cls._translations["visual"] = { + "name": catalog.i18nc("@label", "Visual"), + "description": catalog.i18nc("@text", "The visual profile is designed to print visual prototypes and models with the intent of high visual and surface quality.") + } + cls._translations["engineering"] = { + "name": catalog.i18nc("@label", "Engineering"), + "description": catalog.i18nc("@text", "The engineering profile is designed to print functional prototypes and end-use parts with the intent of better accuracy and for closer tolerances.") + } + cls._translations["quick"] = { + "name": catalog.i18nc("@label", "Draft"), + "description": catalog.i18nc("@text", "The draft profile is designed to print initial prototypes and concept validation with the intent of significant print time reduction.") + } + return cls._translations ## Creates a new model for a certain intent category. @@ -99,7 +104,7 @@ class IntentCategoryModel(ListModel): "name": IntentCategoryModel.translation(category, "name", catalog.i18nc("@label", "Unknown")), "description": IntentCategoryModel.translation(category, "description", None), "intent_category": category, - "weight": list(self._translations.keys()).index(category), + "weight": list(IntentCategoryModel._get_translations().keys()).index(category), "qualities": qualities }) result.sort(key = lambda k: k["weight"]) @@ -109,5 +114,5 @@ class IntentCategoryModel(ListModel): ## for categories and keys @staticmethod def translation(category: str, key: str, default: Optional[str] = None): - display_strings = IntentCategoryModel._translations.get(category, {}) + display_strings = IntentCategoryModel._get_translations().get(category, {}) return display_strings.get(key, default) |