From d4920f6eb8c8ba13f035aee0d4a417efc8540c39 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 18 May 2026 10:26:56 +0800 Subject: [PATCH] fix: custorm fields i18n --- apps/assets/serializers/asset/custom.py | 15 ++++++++------- apps/terminal/models/applet/applet.py | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/assets/serializers/asset/custom.py b/apps/assets/serializers/asset/custom.py index 97629952e..fde011f99 100644 --- a/apps/assets/serializers/asset/custom.py +++ b/apps/assets/serializers/asset/custom.py @@ -50,28 +50,29 @@ class CustomSerializer(AssetSerializer): return default_field custom_fields = platform.custom_fields - if not custom_fields: return default_field + return self._get_custom_fields(platform, custom_fields) + + def _get_custom_fields(self, platform, custom_fields): name = platform.name.title() + 'CustomSerializer' applet = Applet.objects.filter( name=platform.created_by.replace('Applet:', '') ).first() - if not applet: + if not applet or not applet.platform_manifest or not applet.platform_manifest.get('i18n'): return create_serializer_class(name, custom_fields)() - i18n = applet.manifest.get('i18n', {}) - + i18n = applet.platform_manifest['i18n'] lang = get_language() lang_short = lang[:2] def translate_text(key): return ( - i18n.get(key, {}).get(lang) - or i18n.get(key, {}).get(lang_short) - or key + i18n.get(key, {}).get(lang) + or i18n.get(key, {}).get(lang_short) + or key ) for field in custom_fields: diff --git a/apps/terminal/models/applet/applet.py b/apps/terminal/models/applet/applet.py index ac46a4003..694a9e700 100644 --- a/apps/terminal/models/applet/applet.py +++ b/apps/terminal/models/applet/applet.py @@ -77,6 +77,14 @@ class Applet(JMSBaseModel): return None with open(path, 'r') as f: return yaml.safe_load(f) + + @lazyproperty + def platform_manifest(self) -> dict: + path = os.path.join(self.path, 'platform.yml') + if not os.path.exists(path): + return None + with open(path, 'r') as f: + return yaml.safe_load(f) @property def icon(self) -> str: