Make translatePrinter use dict

A translation dictionary makes it much easier to edit the translations. Also this now just translates one printer, instead of a list.

Contributes to issue CURA-844.
This commit is contained in:
Ghostkeeper 2016-07-03 23:58:38 +02:00
parent b5efb2eee8
commit f13db7de10
2 changed files with 15 additions and 9 deletions

View file

@ -85,7 +85,7 @@ class Profile:
if self._weight:
config.set("general", "weight", self._weight)
if self._machine_type_id:
translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinters([self._machine_type_id])[0]
translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._machine_type_id)
config.set("general", "definition", translated_machine)
else:
config.set("general", "definition", "fdmprinter")

View file

@ -9,6 +9,11 @@ from . import MachineInstance # To upgrade machine instances.
from . import Preferences #To upgrade preferences.
from . import Profile # To upgrade profiles.
## How to translate printer names from the old version to the new.
_printer_translation = {
"ultimaker2plus": "ultimaker2_plus"
}
## How to translate profile names from the old version to the new.
_profile_translation = {
"PLA": "generic_pla",
@ -16,6 +21,7 @@ _profile_translation = {
"CPE": "generic_cpe"
}
## How to translate setting names from the old version to the new.
_setting_name_translation = {
"speed_support_lines": "speed_support_infill"
}
@ -69,16 +75,16 @@ class VersionUpgrade21to22(VersionUpgrade):
return None
return profile.export()
## Translates printer names that have changed since the last version.
## Translates a printer name that might have changed since the last
# version.
#
# \param printers A list of printer names in the old version.
# \return The same list, but with printer names translated.
# \param printer A printer name in Cura 2.1.
# \return The name of the corresponding printer in Cura 2.2.
@staticmethod
def translatePrinters(printers):
for index, printer in enumerate(printers):
if printer == "ultimaker2plus":
printers[index] = "ultimaker2_plus"
return printers
def translatePrinter(printer):
if printer in _printer_translation:
return _printer_translation[printer]
return printer #Doesn't need to be translated.
## Translates a built-in profile name that might have changed since the
# last version.