Improve translatability of cloud printer syncing texts

Here are a number of improvements to the translated texts that make it easier for the translators to translate them:
* Never include layout elements such as <ul> or <li> in the translated text. The translators don't know what to do with them. Instead, leave the tags out of the translated parts and then wrap them around it in Python.
* If there are replacement keys in the source text, explain all of them in the context.
* Use a name within the brackets, to make it clear from context what the brackets mean and to disambiguate multiple keys if there are multiple.
* No invisible whitespace (such as space at the end of a line).
* Use plural forms with i18ncp if applicable (or i18np if no context is necessary).

I also changed the catalogue variable to lowercase with underscores, as per our code style.
This commit is contained in:
Ghostkeeper 2020-08-12 09:45:51 +02:00
parent 5840205442
commit 5ec57d42d0
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -1,5 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import os import os
from typing import Dict, List, Optional, Set from typing import Dict, List, Optional, Set
@ -37,7 +38,7 @@ class CloudOutputDeviceManager:
SYNC_SERVICE_NAME = "CloudOutputDeviceManager" SYNC_SERVICE_NAME = "CloudOutputDeviceManager"
# The translation catalog for this device. # The translation catalog for this device.
I18N_CATALOG = i18nCatalog("cura") i18n_catalog = i18nCatalog("cura")
# Signal emitted when the list of discovered devices changed. # Signal emitted when the list of discovered devices changed.
discoveredDevicesChanged = Signal() discoveredDevicesChanged = Signal()
@ -221,7 +222,7 @@ class CloudOutputDeviceManager:
) )
message = Message( message = Message(
title = self.I18N_CATALOG.i18ncp( title = self.i18n_catalog.i18ncp(
"info:status", "info:status",
"New printer detected from your Ultimaker account", "New printer detected from your Ultimaker account",
"New printers detected from your Ultimaker account", "New printers detected from your Ultimaker account",
@ -234,11 +235,7 @@ class CloudOutputDeviceManager:
message.show() message.show()
for idx, device in enumerate(new_devices): for idx, device in enumerate(new_devices):
message_text = self.I18N_CATALOG.i18nc( message_text = self.i18n_catalog.i18nc("info:status %1 is printer name, %2 is printer type", "Adding printer {name} ({type}) from your account").format(name = device.name, type = device.printerTypeName)
"info:status", "Adding printer {} ({}) from your account",
device.name,
device.printerTypeName
)
message.setText(message_text) message.setText(message_text)
if len(new_devices) > 1: if len(new_devices) > 1:
message.setProgress((idx / len(new_devices)) * 100) message.setProgress((idx / len(new_devices)) * 100)
@ -255,16 +252,12 @@ class CloudOutputDeviceManager:
if len(new_devices) > max_disp_devices: if len(new_devices) > max_disp_devices:
num_hidden = len(new_devices) - max_disp_devices num_hidden = len(new_devices) - max_disp_devices
device_name_list = ["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices[0:max_disp_devices]] device_name_list = ["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices[0:max_disp_devices]]
device_name_list.append(self.I18N_CATALOG.i18nc("info:hidden list items", "<li>... and {} others</li>", num_hidden)) device_name_list.append("<li>" + self.i18n_catalog.i18ncp("info:{num_hidden} gets replaced by a number of printers", "... and {num_hidden} other", "... and {num_hidden} others", num_hidden).format(num_hidden = num_hidden) + "</li>")
device_names = "".join(device_name_list) device_names = "".join(device_name_list)
else: else:
device_names = "".join(["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices]) device_names = "".join(["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices])
message_text = self.I18N_CATALOG.i18nc( message_text = self.i18n_catalog.i18nc("info:status", "Printers added from Digital Factory:") + "<ul>" + device_names + "</ul>"
"info:status",
"Printers added from Digital Factory:<ul>{}</ul>",
device_names
)
message.setText(message_text) message.setText(message_text)
def _updateOutdatedMachine(self, outdated_machine: GlobalStack, new_cloud_output_device: CloudOutputDevice) -> None: def _updateOutdatedMachine(self, outdated_machine: GlobalStack, new_cloud_output_device: CloudOutputDevice) -> None:
@ -318,7 +311,7 @@ class CloudOutputDeviceManager:
# Generate message # Generate message
self._removed_printers_message = Message( self._removed_printers_message = Message(
title = self.I18N_CATALOG.i18ncp( title = self.i18n_catalog.i18ncp(
"info:status", "info:status",
"A cloud connection is not available for a printer", "A cloud connection is not available for a printer",
"A cloud connection is not available for some printers", "A cloud connection is not available for some printers",
@ -326,27 +319,27 @@ class CloudOutputDeviceManager:
) )
) )
device_names = "".join(["<li>{} ({})</li>".format(self._um_cloud_printers[device].name, self._um_cloud_printers[device].definition.name) for device in self.reported_device_ids]) device_names = "".join(["<li>{} ({})</li>".format(self._um_cloud_printers[device].name, self._um_cloud_printers[device].definition.name) for device in self.reported_device_ids])
message_text = self.I18N_CATALOG.i18ncp( message_text = self.i18n_catalog.i18ncp(
"info:status", "info:status",
"This printer is not linked to the Digital Factory:", "This printer is not linked to the Digital Factory:",
"These printers are not linked to the Digital Factory:", "These printers are not linked to the Digital Factory:",
len(self.reported_device_ids) len(self.reported_device_ids)
) )
message_text += "<br/><ul>{}</ul><br/>".format(device_names) message_text += "<br/><ul>{}</ul><br/>".format(device_names)
digital_factory_string = self.I18N_CATALOG.i18nc("info:name", "Ultimaker Digital Factory") digital_factory_string = self.i18n_catalog.i18nc("info:name", "Ultimaker Digital Factory")
message_text += self.I18N_CATALOG.i18nc( message_text += self.i18n_catalog.i18nc(
"info:status", "info:status",
"To establish a connection, please visit the {website_link}".format(website_link = "<a href='https://digitalfactory.ultimaker.com/'>{}</a>.".format(digital_factory_string)) "To establish a connection, please visit the {website_link}".format(website_link = "<a href='https://digitalfactory.ultimaker.com/'>{}</a>.".format(digital_factory_string))
) )
self._removed_printers_message.setText(message_text) self._removed_printers_message.setText(message_text)
self._removed_printers_message.addAction("keep_printer_configurations_action", self._removed_printers_message.addAction("keep_printer_configurations_action",
name = self.I18N_CATALOG.i18nc("@action:button", "Keep printer configurations"), name = self.i18n_catalog.i18nc("@action:button", "Keep printer configurations"),
icon = "", icon = "",
description = "Keep cloud printers in Ultimaker Cura when not connected to your account.", description = "Keep cloud printers in Ultimaker Cura when not connected to your account.",
button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) button_align = Message.ActionButtonAlignment.ALIGN_RIGHT)
self._removed_printers_message.addAction("remove_printers_action", self._removed_printers_message.addAction("remove_printers_action",
name = self.I18N_CATALOG.i18nc("@action:button", "Remove printers"), name = self.i18n_catalog.i18nc("@action:button", "Remove printers"),
icon = "", icon = "",
description = "Remove cloud printer(s) which aren't linked to your account.", description = "Remove cloud printer(s) which aren't linked to your account.",
button_style = Message.ActionButtonStyle.SECONDARY, button_style = Message.ActionButtonStyle.SECONDARY,
@ -423,9 +416,9 @@ class CloudOutputDeviceManager:
machine.setMetaDataEntry(self.META_HOST_GUID, device.clusterData.host_guid) machine.setMetaDataEntry(self.META_HOST_GUID, device.clusterData.host_guid)
machine.setMetaDataEntry("group_name", device.name) machine.setMetaDataEntry("group_name", device.name)
machine.setMetaDataEntry("group_size", device.clusterSize) machine.setMetaDataEntry("group_size", device.clusterSize)
digital_factory_string = self.I18N_CATALOG.i18nc("info:name", "Ultimaker Digital Factory") digital_factory_string = self.i18n_catalog.i18nc("info:name", "Ultimaker Digital Factory")
digital_factory_link = "<a href='https://digitalfactory.ultimaker.com/'>{}</a>".format(digital_factory_string) digital_factory_link = "<a href='https://digitalfactory.ultimaker.com/'>{}</a>".format(digital_factory_string)
removal_warning_string = self.I18N_CATALOG.i18nc( removal_warning_string = self.i18n_catalog.i18nc(
"@label ({printer_name} is replaced with the name of the printer", "@label ({printer_name} is replaced with the name of the printer",
"{printer_name} will be removed until the next account sync. <br> To remove {printer_name} permanently, " "{printer_name} will be removed until the next account sync. <br> To remove {printer_name} permanently, "
"visit {digital_factory_link}" "visit {digital_factory_link}"
@ -469,10 +462,15 @@ class CloudOutputDeviceManager:
remove_printers_ids = {self._um_cloud_printers[i].getId() for i in self.reported_device_ids} remove_printers_ids = {self._um_cloud_printers[i].getId() for i in self.reported_device_ids}
all_ids = {m.getId() for m in CuraApplication.getInstance().getContainerRegistry().findContainerStacks(type = "machine")} all_ids = {m.getId() for m in CuraApplication.getInstance().getContainerRegistry().findContainerStacks(type = "machine")}
question_title = self.I18N_CATALOG.i18nc("@title:window", "Remove printers?") question_title = self.i18n_catalog.i18nc("@title:window", "Remove printers?")
question_content = self.I18N_CATALOG.i18nc("@label", "You are about to remove {} printer(s) from Cura. This action cannot be undone. \nAre you sure you want to continue?".format(len(remove_printers_ids))) question_content = self.i18n_catalog.i18ncp(
"@label",
"You are about to remove {num_printers} printer from Cura. This action cannot be undone.\nAre you sure you want to continue?",
"You are about to remove {num_printers} printers from Cura. This action cannot be undone.\nAre you sure you want to continue?",
len(remove_printers_ids)
).format(num_printers = len(remove_printers_ids))
if remove_printers_ids == all_ids: if remove_printers_ids == all_ids:
question_content = self.I18N_CATALOG.i18nc("@label", "You are about to remove all printers from Cura. This action cannot be undone. \nAre you sure you want to continue?") question_content = self.i18n_catalog.i18nc("@label", "You are about to remove all printers from Cura. This action cannot be undone.\nAre you sure you want to continue?")
result = QMessageBox.question(None, question_title, question_content) result = QMessageBox.question(None, question_title, question_content)
if result == QMessageBox.No: if result == QMessageBox.No:
return return