Change the email language in the email pipeline from English to Chinese based on the selected language

Change the email language in the email pipeline from English to Chinese based on the selected language.
I have added a script before the alarm notification block and written the script below.


# Step 1: Get the locale (defaults to 'en' if not set)
locale = alarmEvent.get("locale") or "en"

# Step 2: Extract common alarm event values
displayPath = alarmEvent.get("displayPath", "")
eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
priority = alarmEvent.get("priority", "")
setpoint = alarmEvent.get("SetpointA", "")
eventValue = alarmEvent.get("eventValue", "")
eventState = alarmEvent.get("eventState", "")

# Step 3: Create localized HTML email body
if locale == "zh":
    emailBody = u"""
    <html>
        <body>
            <h3>标题: COE 报警通知</h3>
            <p>有一个报警已被触发,详情如下:</p>
            <ul>
                <li><strong>描述:</strong> {displayPath}</li>
                <li><strong>事件时间:</strong> {eventTime}</li>
                <li><strong>报警类型:</strong> {priority}</li>
                <li><strong>设定值:</strong> {setpoint}</li>
                <li><strong>事件值:</strong> {eventValue}</li>
                <li><strong>状态变化:</strong> {eventState}</li>
            </ul>
            <p>请采取相应的措施。</p>
            <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
            <p>此致敬礼,<br>COE SCADA 系统</p>
        </body>
    </html>
    """.format(
        displayPath=displayPath,
        eventTime=eventTime,
        priority=priority,
        setpoint=setpoint,
        eventValue=eventValue,
        eventState=eventState
    )
else:
    emailBody = """
    <html>
        <body>
            <h3>Title: COE Alarm Notification</h3>
            <p>An alarm has been triggered. Please find the details below:</p>
            <ul>
                <li><strong>Description:</strong> {displayPath}</li>
                <li><strong>Event Time:</strong> {eventTime}</li>
                <li><strong>Alarm Type:</strong> {priority}</li>
                <li><strong>Setpoint Value:</strong> {setpoint}</li>
                <li><strong>Event Value:</strong> {eventValue}</li>
                <li><strong>Transitioned:</strong> {eventState}</li>
            </ul>
            <p>Please take action accordingly.</p>
            <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
            <p>Best Regards,<br>COE SCADA System</p>
        </body>
    </html>
    """.format(
        displayPath=displayPath,
        eventTime=eventTime,
        priority=priority,
        setpoint=setpoint,
        eventValue=eventValue,
        eventState=eventState
    )

# Step 4: Store it in pipelineVars to be used in Email Notification block
pipelineVars["emailBody"] = emailBody

After that, I have added the notification pipeline. In the notification pipeline message section, I passed the parameter {emailBody}



Now, my email is sent, but it passes NULL data. If I remove the script and pass the message in HTML format, it sends the message accurately. However, we require the message in multiple languages. What can I do?

Please see Wiki - how to post code on this forum. Can you edit your question to fix the code? Thanks.

	# Step 1: Get the locale (defaults to 'en' if not set)
	locale = alarmEvent.get("locale") or "en"
	
	# Step 2: Extract common alarm event values
	displayPath = alarmEvent.get("displayPath", "")
	eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
	priority = alarmEvent.get("priority", "")
	setpoint = alarmEvent.get("SetpointA", "")
	eventValue = alarmEvent.get("eventValue", "")
	eventState = alarmEvent.get("eventState", "")
	
	# Step 3: Create localized HTML email body
	if locale == "zh":
	    emailBody = u"""
	    <html>
	        <body>
	            <h3>标题: COE 报警通知</h3>
	            <p>有一个报警已被触发,详情如下:</p>
	            <ul>
	                <li><strong>描述:</strong> {displayPath}</li>
	                <li><strong>事件时间:</strong> {eventTime}</li>
	                <li><strong>报警类型:</strong> {priority}</li>
	                <li><strong>设定值:</strong> {setpoint}</li>
	                <li><strong>事件值:</strong> {eventValue}</li>
	                <li><strong>状态变化:</strong> {eventState}</li>
	            </ul>
	            <p>请采取相应的措施。</p>
	            <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
	            <p>此致敬礼,<br>COE SCADA 系统</p>
	        </body>
	    </html>
	    """.format(
	        displayPath=displayPath,
	        eventTime=eventTime,
	        priority=priority,
	        setpoint=setpoint,
	        eventValue=eventValue,
	        eventState=eventState
	    )
	else:
	    emailBody = """
	    <html>
	        <body>
	            <h3>Title: COE Alarm Notification</h3>
	            <p>An alarm has been triggered. Please find the details below:</p>
	            <ul>
	                <li><strong>Description:</strong> {displayPath}</li>
	                <li><strong>Event Time:</strong> {eventTime}</li>
	                <li><strong>Alarm Type:</strong> {priority}</li>
	                <li><strong>Setpoint Value:</strong> {setpoint}</li>
	                <li><strong>Event Value:</strong> {eventValue}</li>
	                <li><strong>Transitioned:</strong> {eventState}</li>
	            </ul>
	            <p>Please take action accordingly.</p>
	            <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
	            <p>Best Regards,<br>COE SCADA System</p>
	        </body>
	    </html>
	    """.format(
	        displayPath=displayPath,
	        eventTime=eventTime,
	        priority=priority,
	        setpoint=setpoint,
	        eventValue=eventValue,
	        eventState=eventState
	    )
	
	# Step 4: Store it in pipelineVars to be used in Email Notification block
	pipelineVars["emailBody"] = emailBody

####### In Alarm notification (Massage) i have write below code.

{emailBody}

in your script pipelineVars is local to this script so the email notification block does not have access to this. Try setting the email Body like this event.setGlobal("emailBody", emailBody) Then in your notification block you can reference the email body like above as {emailBody}

1 Like

Get locale (default to English)

locale = alarmEvent.get("locale", "en")

Extract alarm values

displayPath = alarmEvent.get("displayPath", "")
eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
priority = alarmEvent.get("priority", "")
setpoint = alarmEvent.get("SetpointA", "")
eventValue = alarmEvent.get("eventValue", "")
eventState = alarmEvent.get("eventState", "")

Build localized email body

if locale == "zh":
emailBody = u"""


标题: COE 报警通知


有一个报警已被触发,详情如下:



  • 描述: {displayPath}

  • 事件时间: {eventTime}

  • 报警类型: {priority}

  • 设定值: {setpoint}

  • 事件值: {eventValue}

  • 状态变化: {eventState}


请采取相应的措施。


点击此处确认报警

此致敬礼,
COE SCADA 系统




""".format(
displayPath=displayPath,
eventTime=eventTime,
priority=priority,
setpoint=setpoint,
eventValue=eventValue,
eventState=eventState
)
else:
emailBody = """


Title: COE Alarm Notification


An alarm has been triggered. Please find the details below:



  • Description: {displayPath}

  • Event Time: {eventTime}

  • Alarm Type: {priority}

  • Setpoint: {setpoint}

  • Event Value: {eventValue}

  • Status: {eventState}


Please take action accordingly.


Click here for Alarm Ack

Best Regards,
COE SCADA System




""".format(
displayPath=displayPath,
eventTime=eventTime,
priority=priority,
setpoint=setpoint,
eventValue=eventValue,
eventState=eventState
)

Store the email body globally so the next block can use it

event.setGlobal("emailBody", emailBody)

Can you please check the script I shared in the chat? When I added it again, I received a null message. Could you please assist me with this?

# Get locale (default to English)
locale = alarmEvent.get("locale", "en")

# Extract alarm values
displayPath = alarmEvent.get("displayPath", "")
eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
priority = alarmEvent.get("priority", "")
setpoint = alarmEvent.get("SetpointA", "")
eventValue = alarmEvent.get("eventValue", "")
eventState = alarmEvent.get("eventState", "")

# Build localized email body
if locale == "zh":
	emailBody = u"""
	<html>
	    <body>
	        <h3>标题: COE 报警通知</h3>
	        <p>有一个报警已被触发,详情如下:</p>
	        <ul>
	            <li><strong>描述:</strong> {displayPath}</li>
	            <li><strong>事件时间:</strong> {eventTime}</li>
	            <li><strong>报警类型:</strong> {priority}</li>
	            <li><strong>设定值:</strong> {setpoint}</li>
	            <li><strong>事件值:</strong> {eventValue}</li>
	            <li><strong>状态变化:</strong> {eventState}</li>
	        </ul>
	        <p>请采取相应的措施。</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
	        <p>此致敬礼,<br>COE SCADA 系统</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)
else:
	emailBody = """
	<html>
	    <body>
	        <h3>Title: COE Alarm Notification</h3>
	        <p>An alarm has been triggered. Please find the details below:</p>
	        <ul>
	            <li><strong>Description:</strong> {displayPath}</li>
	            <li><strong>Event Time:</strong> {eventTime}</li>
	            <li><strong>Alarm Type:</strong> {priority}</li>
	            <li><strong>Setpoint:</strong> {setpoint}</li>
	            <li><strong>Event Value:</strong> {eventValue}</li>
	            <li><strong>Status:</strong> {eventState}</li>
	        </ul>
	        <p>Please take action accordingly.</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
	        <p>Best Regards,<br>COE SCADA System</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)

# Store the email body globally so the next block can use it
event.setGlobal("emailBody", emailBody)

Can you fix your most recent post as well?

Below code working on script Console correctly but not working on alarm pipeline. I don't understand required any other setting.

alarmEvent = {
"locale": "zh", # change to "zh" to test Chinese output
"displayPath": "Tank Level High",
"eventTime": system.date.now(),
"priority": "High",
"SetpointA": "85.0",
"eventValue": "92.3",
"eventState": "Active"
}

Function (paste your function here or import from project.alarm_utils if saved)

def build_email_body(alarmEvent):
locale = alarmEvent.get("locale", "en")
displayPath = alarmEvent.get("displayPath", "")
eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
priority = alarmEvent.get("priority", "")
setpoint = alarmEvent.get("SetpointA", "")
eventValue = alarmEvent.get("eventValue", "")
eventState = alarmEvent.get("eventState", "")

if locale == "zh":
	emailBody = u"""
	<html>
	    <body>
	        <h3>标题: COE 报警通知</h3>
	        <p>有一个报警已被触发,详情如下:</p>
	        <ul>
	            <li><strong>描述:</strong> {displayPath}</li>
	            <li><strong>事件时间:</strong> {eventTime}</li>
	            <li><strong>报警类型:</strong> {priority}</li>
	            <li><strong>设定值:</strong> {setpoint}</li>
	            <li><strong>事件值:</strong> {eventValue}</li>
	            <li><strong>状态变化:</strong> {eventState}</li>
	        </ul>
	        <p>请采取相应的措施。</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
	        <p>此致敬礼,<br>COE SCADA 系统</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)
else:
	emailBody = """
	<html>
	    <body>
	        <h3>Title: COE Alarm Notification</h3>
	        <p>An alarm has been triggered. Please find the details below:</p>
	        <ul>
	            <li><strong>Description:</strong> {displayPath}</li>
	            <li><strong>Event Time:</strong> {eventTime}</li>
	            <li><strong>Alarm Type:</strong> {priority}</li>
	            <li><strong>Setpoint:</strong> {setpoint}</li>
	            <li><strong>Event Value:</strong> {eventValue}</li>
	            <li><strong>Status:</strong> {eventState}</li>
	        </ul>
	        <p>Please take action accordingly.</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
	        <p>Best Regards,<br>COE SCADA System</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)

return emailBody

Run the function and print the result

print build_email_body(alarmEvent)

Please check this email to confirm if the code was sent correctly. The code was working as expected in the script console.

# Simulate alarmEvent dictionary
alarmEvent = {
    "locale": "en",  # change to "zh" to test Chinese output
    "displayPath": "Tank Level High",
    "eventTime": system.date.now(),
    "priority": "High",
    "SetpointA": "85.0",
    "eventValue": "92.3",
    "eventState": "Active"
}

# Function (paste your function here or import from project.alarm_utils if saved)
def build_email_body(alarmEvent):
	locale = alarmEvent.get("locale", "en")
	displayPath = alarmEvent.get("displayPath", "")
	eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
	priority = alarmEvent.get("priority", "")
	setpoint = alarmEvent.get("SetpointA", "")
	eventValue = alarmEvent.get("eventValue", "")
	eventState = alarmEvent.get("eventState", "")

	if locale == "zh":
		emailBody = u"""
		<html>
		    <body>
		        <h3>标题: COE 报警通知</h3>
		        <p>有一个报警已被触发,详情如下:</p>
		        <ul>
		            <li><strong>描述:</strong> {displayPath}</li>
		            <li><strong>事件时间:</strong> {eventTime}</li>
		            <li><strong>报警类型:</strong> {priority}</li>
		            <li><strong>设定值:</strong> {setpoint}</li>
		            <li><strong>事件值:</strong> {eventValue}</li>
		            <li><strong>状态变化:</strong> {eventState}</li>
		        </ul>
		        <p>请采取相应的措施。</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
		        <p>此致敬礼,<br>COE SCADA 系统</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)
	else:
		emailBody = """
		<html>
		    <body>
		        <h3>Title: COE Alarm Notification</h3>
		        <p>An alarm has been triggered. Please find the details below:</p>
		        <ul>
		            <li><strong>Description:</strong> {displayPath}</li>
		            <li><strong>Event Time:</strong> {eventTime}</li>
		            <li><strong>Alarm Type:</strong> {priority}</li>
		            <li><strong>Setpoint:</strong> {setpoint}</li>
		            <li><strong>Event Value:</strong> {eventValue}</li>
		            <li><strong>Status:</strong> {eventState}</li>
		        </ul>
		        <p>Please take action accordingly.</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
		        <p>Best Regards,<br>COE SCADA System</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)

	return emailBody

# Run the function and print the result
print build_email_body(alarmEvent)

I wrote this code in the Alarm Pipeline script section, but it was not working."

# Get locale (default to English)
locale = alarmEvent.get("locale", "en")

# Extract alarm values
displayPath = alarmEvent.get("displayPath", "")
eventTime = system.date.format(alarmEvent.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
priority = alarmEvent.get("priority", "")
setpoint = alarmEvent.get("SetpointA", "")
eventValue = alarmEvent.get("eventValue", "")
eventState = alarmEvent.get("eventState", "")

# Build localized email body
if locale == "zh":
	emailBody = u"""
	<html>
	    <body>
	        <h3>标题: COE 报警通知</h3>
	        <p>有一个报警已被触发,详情如下:</p>
	        <ul>
	            <li><strong>描述:</strong> {displayPath}</li>
	            <li><strong>事件时间:</strong> {eventTime}</li>
	            <li><strong>报警类型:</strong> {priority}</li>
	            <li><strong>设定值:</strong> {setpoint}</li>
	            <li><strong>事件值:</strong> {eventValue}</li>
	            <li><strong>状态变化:</strong> {eventState}</li>
	        </ul>
	        <p>请采取相应的措施。</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
	        <p>此致敬礼,<br>COE SCADA 系统</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)
else:
	emailBody = """
	<html>
	    <body>
	        <h3>Title: COE Alarm Notification</h3>
	        <p>An alarm has been triggered. Please find the details below:</p>
	        <ul>
	            <li><strong>Description:</strong> {displayPath}</li>
	            <li><strong>Event Time:</strong> {eventTime}</li>
	            <li><strong>Alarm Type:</strong> {priority}</li>
	            <li><strong>Setpoint:</strong> {setpoint}</li>
	            <li><strong>Event Value:</strong> {eventValue}</li>
	            <li><strong>Status:</strong> {eventState}</li>
	        </ul>
	        <p>Please take action accordingly.</p>
	        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
	        <p>Best Regards,<br>COE SCADA System</p>
	    </body>
	</html>
	""".format(
	    displayPath=displayPath,
	    eventTime=eventTime,
	    priority=priority,
	    setpoint=setpoint,
	    eventValue=eventValue,
	    eventState=eventState
	)

# Store the email body globally so the next block can use it
event.setGlobal("emailBody", emailBody)

and finally pass notification massage below code.

{emailBody}

now this better i think for understanding.

Have you checked the gateway logs for errors? I did a simple test with this code and there are many errors. Which is why the whole notification returns null.
Are you running this inside the actual script block in the pipeline?
Like this.

In your script you have alarmEvent.get() which is not valid its event.get() with only one argument. When using it in the pipeline scripting block

Locale is not valid parameter in the event object unless you are passing it in somewhere else. I am not sure the full context of this script.
Here below is what I tested

def handleAlarm(event):
	logger = system.util.getLogger("pipeline")
	# Get locale (default to English)
	locale = event.get("locale")
	logger.infof("locale: %s", locale)
	# Extract alarm values
	displayPath = event.get("displayPath")
	eventTime = system.date.format(event.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
	priority = event.get("priority")
	setpoint = event.get("SetpointA")
	eventValue = event.get("eventValue")
	eventState = event.get("eventState")
	
	# Build localized email body
	if locale == "zh":
		emailBody = u"""
		<html>
		    <body>
		        <h3>标题: COE 报警通知</h3>
		        <p>有一个报警已被触发,详情如下:</p>
		        <ul>
		            <li><strong>描述:</strong> {displayPath}</li>
		            <li><strong>事件时间:</strong> {eventTime}</li>
		            <li><strong>报警类型:</strong> {priority}</li>
		            <li><strong>设定值:</strong> {setpoint}</li>
		            <li><strong>事件值:</strong> {eventValue}</li>
		            <li><strong>状态变化:</strong> {eventState}</li>
		        </ul>
		        <p>请采取相应的措施。</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
		        <p>此致敬礼,<br>COE SCADA 系统</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)
	else:
		emailBody = """
		<html>
		    <body>
		        <h3>Title: COE Alarm Notification</h3>
		        <p>An alarm has been triggered. Please find the details below:</p>
		        <ul>
		            <li><strong>Description:</strong> {displayPath}</li>
		            <li><strong>Event Time:</strong> {eventTime}</li>
		            <li><strong>Alarm Type:</strong> {priority}</li>
		            <li><strong>Setpoint:</strong> {setpoint}</li>
		            <li><strong>Event Value:</strong> {eventValue}</li>
		            <li><strong>Status:</strong> {eventState}</li>
		        </ul>
		        <p>Please take action accordingly.</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
		        <p>Best Regards,<br>COE SCADA System</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)
	logger.info(emailBody)
	# Store the email body globally so the next block can use it
	event.setGlobal("emailBody", emailBody)	

This Code generates the html and passes it correctly but locale is always null as it doesn't exist.
Check your gateway logs for errors. If you want to chek if something exists in the event object you can use the event.contains() method. event.contains('locale') returns false. In my case because it is never exists.

1 Like

Hello,
instead of locale I passed label in below script and bind tag to there. but I received massage in English only.
I'm not sure if I'm on the right track with the translation—we're doing this for the first time in the alarm pipeline notification.
Could you please provide the proper solution with an example?

My main concern is how to translate the outgoing alarm message according to the selected language.
If possible, could we arrange a Teams meeting at a time that works best for you? Please let me know when we can connect to find the perfect solution.

	logger = system.util.getLogger("pipeline")
#	
#		# Get label for translation (default to English)
	label = event.get("label")
	logger.infof("label: %s", label)		

	# Extract alarm values
	
	displayPath = event.get("displayPath")
	eventTime = system.date.format(event.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
	priority = event.get("priority")
	setpoint = event.get("SetpointA")
	eventValue = event.get("eventValue")
	eventState = event.get("eventState")

	# Build localized email body based on label
	if label == "zh":
		emailBody = u"""
		<html>
		    <body>
		        <h3>标题: COE 报警通知</h3>
		        <p>有一个报警已被触发,详情如下:</p>
		        <ul>
		            <li><strong>描述:</strong> {displayPath}</li>
		            <li><strong>事件时间:</strong> {eventTime}</li>
		            <li><strong>报警类型:</strong> {priority}</li>
		            <li><strong>设定值:</strong> {setpoint}</li>
		            <li><strong>事件值:</strong> {eventValue}</li>
		            <li><strong>状态变化:</strong> {eventState}</li>
		        </ul>
		        <p>请采取相应的措施。</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
		        <p>此致敬礼,<br>COE SCADA 系统</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)
	else:
		emailBody = """
		<html>
		    <body>
		        <h3>Title: COE Alarm Notification</h3>
		        <p>An alarm has been triggered. Please find the details below:</p>
		        <ul>
		            <li><strong>Description:</strong> {displayPath}</li>
		            <li><strong>Event Time:</strong> {eventTime}</li>
		            <li><strong>Alarm Type:</strong> {priority}</li>
		            <li><strong>Setpoint:</strong> {setpoint}</li>
		            <li><strong>Event Value:</strong> {eventValue}</li>
		            <li><strong>Status:</strong> {eventState}</li>
		        </ul>
		        <p>Please take action accordingly.</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
		        <p>Best Regards,<br>COE SCADA System</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)

	logger.info(emailBody)
	# Store the email body globally so the next block can use it
	event.setGlobal("emailBody", emailBody)

If your force label to equal zh in the script you will see the alternate language. I had done this in my test. The loggers in place should show you what is being passed into the label. If you you still need assistance then please reach out to support.
https://support.inductiveautomation.com/hc/en-us

1 Like


Hello.
Know I have tried with below code as per you said tried with label = "zh"
then I have received attached mail format.
can you have any demo for entire email translation. If you have, please send me.

I am available now if get small session.

def handleAlarm(event):
	logger = system.util.getLogger("pipeline")
	#	
#		# Get label for translation (default to English)
	label = "zh"
	logger.infof("label: %s", label)		

	# Extract alarm values
	
	displayPath = event.get("displayPath")
	eventTime = system.date.format(event.get("eventTime"), "dd:MM:yyyy - HH:mm:ss")
	priority = event.get("priority")
	setpoint = event.get("SetpointA")
	eventValue = event.get("eventValue")
	eventState = event.get("eventState")

	# Build localized email body based on label
	if label == "zh":
		emailBody = u"""
		<html>
		    <body>
		        <h3>标题: COE 报警通知</h3>
		        <p>有一个报警已被触发,详情如下:</p>
		        <ul>
		            <li><strong>描述:</strong> {displayPath}</li>
		            <li><strong>事件时间:</strong> {eventTime}</li>
		            <li><strong>报警类型:</strong> {priority}</li>
		            <li><strong>设定值:</strong> {setpoint}</li>
		            <li><strong>事件值:</strong> {eventValue}</li>
		            <li><strong>状态变化:</strong> {eventState}</li>
		        </ul>
		        <p>请采取相应的措施。</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">点击此处确认报警</a>
		        <p>此致敬礼,<br>COE SCADA 系统</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)
	else:
		emailBody = """
		<html>
		    <body>
		        <h3>Title: COE Alarm Notification</h3>
		        <p>An alarm has been triggered. Please find the details below:</p>
		        <ul>
		            <li><strong>Description:</strong> {displayPath}</li>
		            <li><strong>Event Time:</strong> {eventTime}</li>
		            <li><strong>Alarm Type:</strong> {priority}</li>
		            <li><strong>Setpoint:</strong> {setpoint}</li>
		            <li><strong>Event Value:</strong> {eventValue}</li>
		            <li><strong>Status:</strong> {eventState}</li>
		        </ul>
		        <p>Please take action accordingly.</p>
		        <a href="http://172.16.8.250:8088/data/perspective/client/Ignition_COE_Dev/AlarmPipelineack">Click here for Alarm Ack</a>
		        <p>Best Regards,<br>COE SCADA System</p>
		    </body>
		</html>
		""".format(
		    displayPath=displayPath,
		    eventTime=eventTime,
		    priority=priority,
		    setpoint=setpoint,
		    eventValue=eventValue,
		    eventState=eventState
		)

	logger.info(emailBody)
	# Store the email body globally so the next block can use it
	event.setGlobal("emailBody", emailBody)

Hi,

I have done some R&D and created two email profiles. If the selected language is "zh", profile 1 sends the email, and if "en" is selected, profile 2 sends the email.

However, in this case, the description of alarm, alarm type, and transitioned state are not translated into Chinese, although all the other data is correctly translated.

I did not use any script block in this case.
I have attached a snapshot for your reference.


Hi,
Could you please let me know if it’s possible to translate this? It’s an urgent requirement from the customer side. If possible, we can connect for better understanding.

You need to contact Support. This forum is not an official support venue. Most of us are volunteers.