fix: custorm fields i18n

This commit is contained in:
ibuler
2026-05-18 10:26:56 +08:00
parent d2db901e3c
commit d4920f6eb8
2 changed files with 16 additions and 7 deletions

View File

@@ -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:

View File

@@ -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: