From 3c2bdee22aefdcfc185c0afd8f48394a6dcf31fe Mon Sep 17 00:00:00 2001 From: Jordan Ruthe Date: Sun, 3 Jan 2021 12:43:53 -0500 Subject: [PATCH] Update to allow translations from config file. Updates to use translations from config file. --- docs/Translations.md | 19 ++ ks_includes/KlipperScreen.conf | 66 +++--- ks_includes/locales/KlipperScreen.pot | 290 +++++++++++++++++++++----- panels/job_status.py | 1 + panels/menu.py | 11 +- panels/temperature.py | 1 + screen.py | 9 + 7 files changed, 307 insertions(+), 90 deletions(-) create mode 100644 docs/Translations.md diff --git a/docs/Translations.md b/docs/Translations.md new file mode 100644 index 00000000..a8f766e0 --- /dev/null +++ b/docs/Translations.md @@ -0,0 +1,19 @@ +## Create Translations + +You can use a editor such as [poedit](https://poedit.net/) to assist in translations. This guide will assume that you +will be using poedit. + +This guide will refer to `language designation`. This can be found from running `echo $LANG` on your pi, as long as you +have set your pi up for your preferred language. + +#### New Language + +* Select `Create a new translation` or `File -> New from POT/PO` and select `ks_includes/locals/KlipperScreen.pot`. +* Enter your language designation. +* Create the translations +* Save the file as `ks_includes/locales/{LANGUAGE DESIGNATION}/KlipperScreen.po`. +* Select `File -> Compile to MO`. Save this file as `ks_includes/locales/{LANGUAGE DESIGNATION}/KlipperScreen.mo` + +Once you have followed those steps, as long as your pi is set up for your preferred language, KlipperScreen will +automatically use the translations provided in the file. KlipperScreen currently does not detect RTL languages, but +support for RTL is planned in the near future. diff --git a/ks_includes/KlipperScreen.conf b/ks_includes/KlipperScreen.conf index f14b8281..686c3307 100644 --- a/ks_includes/KlipperScreen.conf +++ b/ks_includes/KlipperScreen.conf @@ -11,165 +11,165 @@ bed = 90 extruder = 220 [menu __main] -name: Main Menu +name: {{ gettext('Main Menu') }} [menu __main homing] -name: Homing +name: {{ gettext('Homing') }} icon: home [menu __main preheat] -name: Preheat +name: {{ gettext('Preheat') }} icon: heat-up panel: preheat [menu __main actions] -name: Actions +name: {{ gettext('Actions') }} icon: actions [menu __main config] -name: Configuration +name: {{ gettext('Configuration') }} icon: control [menu __main print] -name: Print +name: {{ gettext('Print') }} icon: print panel: print [menu __main homing homeall] -name: Home All +name: {{ gettext('Home All') }} icon: home method: printer.gcode.script params: {"script":"G28"} [menu __main homing homex] -name: Home X +name: {{ gettext('Home X') }} icon: home-x method: printer.gcode.script params: {"script":"G28 X"} [menu __main homing homey] -name: Home Y +name: {{ gettext('Home Y') }} icon: home-y method: printer.gcode.script params: {"script":"G28 Y"} [menu __main homing homez] -name: Home Z +name: {{ gettext('Home Z') }} icon: home-z method: printer.gcode.script params: {"script":"G28 Z"} [menu __main homing homexy] -name: Home XY +name: {{ gettext('Home XY') }} icon: home method: printer.gcode.script params: {"script":"G28 X Y"} [menu __main actions move] -name: Move +name: {{ gettext('Move') }} icon: move panel: move [menu __main actions extrude] -name: Extrude +name: {{ gettext('Extrude') }} icon: filament panel: extrude [menu __main actions fan] -name: Fan +name: {{ gettext('Fan') }} icon: fan panel: fan [menu __main actions temperature] -name: Temperature +name: {{ gettext('Temperature') }} icon: heat-up panel: temperature [menu __main actions macros] -name: Macros +name: {{ gettext('Macros') }} icon: custom-script panel: gcode_macros enable: {{ printer.gcode_macros.count > 0 }} [menu __main actions power] -name: Power +name: {{ gettext('Power') }} icon: shutdown panel: power enable: {{ printer.power_devices.count > 0 }} [menu __main actions disablemotors] -name: Disable Motors +name: {{ gettext('Disable Motors') }} icon: motor-off method: printer.gcode.script params: {"script":"M18"} [menu __main config bedlevel] -name: Bed Level +name: {{ gettext('Bed Level') }} icon: bed-level panel: bed_level [menu __main config bedmesh] -name: Bed Mesh +name: {{ gettext('Bed Mesh') }} icon: bed-level panel: bed_mesh enable: {{ printer.bed_mesh is defined }} [menu __main config zoffset] -name: Z Calibrate +name: {{ gettext('Z Calibrate') }} icon: z-offset-increase panel: zcalibrate enable: {{ ((printer.bltouch is defined) or (printer.probe is defined)) }} [menu __main config network] -name: Network +name: {{ gettext('Network') }} icon: network panel: network [menu __main config system] -name: System +name: {{ gettext('System') }} icon: info panel: system [menu __main config save] -name: Save Config +name: {{ gettext('Save Config') }} icon: complete method: printer.gcode.script params: {"script":"SAVE_CONFIG"} confirm: - Save configuration. + {{ gettext('Save configuration.') }} - Klipper will reboot + {{ gettext('Klipper will reboot') }} [menu __print] -name: Print Control +name: {{ gettext('Print Control') }} [menu __print temperature] -name: Temperature +name: {{ gettext('Temperature') }} icon: heat-up panel: temperature [menu __print tuning] -name: Fine Tuning +name: {{ gettext('Fine Tuning') }} icon: fan panel: fine_tune [menu __print fan] -name: Fan +name: {{ gettext('Fan') }} icon: fan panel: fan [menu __print extrude] -name: Extrude +name: {{ gettext('Extrude') }} icon: filament panel: extrude enable: {{ printer.pause_resume.is_paused == True }} [menu __print network] -name: Network +name: {{ gettext('Network') }} icon: network panel: network [menu __print system] -name: System +name: {{ gettext('System') }} icon: info panel: system diff --git a/ks_includes/locales/KlipperScreen.pot b/ks_includes/locales/KlipperScreen.pot index 0e46d07a..0b287135 100644 --- a/ks_includes/locales/KlipperScreen.pot +++ b/ks_includes/locales/KlipperScreen.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-18 12:37+0000\n" +"POT-Creation-Date: 2021-01-03 17:33+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,23 +17,27 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: panels/print.py:229 +#: panels/print.py:229 panels/print.py:197 msgid "?" msgstr "" -#: panels/zcalibrate.py:65 +#: panels/zcalibrate.py:65 panels/zcalibrate.py:70 msgid "Abort" msgstr "" -#: panels/zcalibrate.py:61 +#: panels/zcalibrate.py:61 panels/zcalibrate.py:67 msgid "Accept" msgstr "" -#: panels/print.py:229 +#: ks_includes/KlipperScreen.conf:26 +msgid "Actions" +msgstr "" + +#: panels/print.py:229 panels/print.py:197 msgid "Are you sure you want to print" msgstr "" -#: panels/job_status.py:108 +#: panels/job_status.py:108 panels/job_status.py:305 msgid "Are you sure you wish to cancel this print?" msgstr "" @@ -43,47 +47,79 @@ msgstr "" msgid "Back" msgstr "" -#: panels/job_status.py:79 panels/print.py:225 +#: ks_includes/KlipperScreen.conf:107 +msgid "Bed Level" +msgstr "" + +#: ks_includes/KlipperScreen.conf:112 +msgid "Bed Mesh" +msgstr "" + +#: panels/job_status.py:79 panels/print.py:225 screen.py:440 +#: panels/job_status.py:267 panels/print.py:193 msgid "Cancel" msgstr "" -#: panels/fan.py:42 +#: panels/fan.py:42 panels/fan.py:45 msgid "Cancel Change" msgstr "" -#: panels/job_status.py:111 +#: panels/job_status.py:111 panels/job_status.py:300 msgid "Cancel Print" msgstr "" -#: panels/temperature.py:146 +#: screen.py:274 +msgid "" +"Check /tmp/KlipperScreen.log for more information.\n" +"Please submit an issue on GitHub for help." +msgstr "" + +#: panels/temperature.py:146 panels/bed_mesh.py:172 panels/temperature.py:149 msgid "Close" msgstr "" -#: panels/job_status.py:85 +#: ks_includes/KlipperScreen.conf:30 +msgid "Configuration" +msgstr "" + +#: screen.py:439 +msgid "Continue" +msgstr "" + +#: panels/job_status.py:85 panels/job_status.py:269 msgid "Control" msgstr "" -#: panels/preheat.py:51 +#: panels/preheat.py:51 panels/preheat.py:54 msgid "Cooldown" msgstr "" -#: panels/temperature.py:49 +#: panels/temperature.py:49 panels/temperature.py:53 msgid "Decrease" msgstr "" -#: panels/bed_level.py:79 +#: ks_includes/KlipperScreen.conf:101 +msgid "Disable Motors" +msgstr "" + +#: panels/bed_level.py:79 panels/bed_level.py:101 msgid "Disable XY" msgstr "" -#: panels/zcalibrate.py:57 +#: panels/zcalibrate.py:57 panels/zcalibrate.py:63 msgid "Distance (mm)" msgstr "" -#: panels/bed_level.py:85 panels/job_status.py:82 +#: panels/job_status.py:135 +msgid "Elapsed:" +msgstr "" + +#: panels/bed_level.py:85 panels/job_status.py:82 panels/job_status.py:271 msgid "Emergency Stop" msgstr "" -#: panels/extrude.py:32 +#: panels/extrude.py:32 panels/extrude.py:43 ks_includes/KlipperScreen.conf:74 +#: ks_includes/KlipperScreen.conf:167 msgid "Extrude" msgstr "" @@ -91,15 +127,16 @@ msgstr "" msgid "Extrusion" msgstr "" -#: panels/fine_tune.py:64 +#: panels/fine_tune.py:64 panels/fine_tune.py:57 msgid "Extrusion +" msgstr "" -#: panels/fine_tune.py:68 +#: panels/fine_tune.py:68 panels/fine_tune.py:61 msgid "Extrusion -" msgstr "" #: panels/fine_tune.py:46 panels/fine_tune.py:141 +#: ks_includes/KlipperScreen.conf:79 ks_includes/KlipperScreen.conf:162 msgid "Fan" msgstr "" @@ -111,111 +148,238 @@ msgstr "" msgid "Fan -" msgstr "" -#: panels/fan.py:32 +#: panels/fan.py:32 panels/fan.py:35 msgid "Fan Off" msgstr "" -#: panels/fan.py:35 +#: panels/fan.py:35 panels/fan.py:38 msgid "Fan On" msgstr "" -#: panels/extrude.py:21 panels/extrude.py:25 +#: panels/extrude.py:21 panels/extrude.py:25 panels/extrude.py:23 +#: panels/extrude.py:27 msgid "Fast" msgstr "" -#: panels/system.py:22 panels/splash_screen.py:59 +#: ks_includes/KlipperScreen.conf:157 +msgid "Fine Tuning" +msgstr "" + +#: panels/system.py:22 panels/splash_screen.py:59 panels/splash_screen.py:62 +#: panels/system.py:24 msgid "Firmware Restart" msgstr "" -#: panels/job_status.py:115 +#: panels/job_status.py:115 screen.py:269 panels/job_status.py:301 msgid "Go Back" msgstr "" -#: panels/bed_level.py:76 panels/move.py:38 +#: panels/bed_level.py:76 panels/move.py:38 panels/bed_level.py:98 +#: panels/move.py:40 ks_includes/KlipperScreen.conf:39 msgid "Home All" msgstr "" -#: panels/zcalibrate.py:25 +#: ks_includes/KlipperScreen.conf:45 +msgid "Home X" +msgstr "" + +#: ks_includes/KlipperScreen.conf:63 +msgid "Home XY" +msgstr "" + +#: ks_includes/KlipperScreen.conf:51 +msgid "Home Y" +msgstr "" + +#: ks_includes/KlipperScreen.conf:57 +msgid "Home Z" +msgstr "" + +#: panels/zcalibrate.py:25 panels/zcalibrate.py:29 +#: ks_includes/KlipperScreen.conf:17 msgid "Homing" msgstr "" -#: panels/temperature.py:47 +#: panels/temperature.py:47 panels/temperature.py:51 msgid "Increase" msgstr "" +#. self._load_panels() +#: screen.py:121 +msgid "Initializing" +msgstr "" + #: panels/splash_screen.py:23 msgid "Initializing printer..." msgstr "" -#: panels/system.py:20 +#: ks_includes/KlipperScreen.conf:144 +msgid "KS Settings" +msgstr "" + +#: panels/system.py:20 panels/system.py:22 msgid "Klipper Restart" msgstr "" -#: panels/system.py:43 panels/system.py:42 +#: panels/system.py:35 +msgid "Klipper Version" +msgstr "" + +#: screen.py:369 +msgid "Klipper has disconnected" +msgstr "" + +#: screen.py:380 +msgid "" +"Klipper has encountered an error with the micro-controller.\n" +"Please recompile and flash." +msgstr "" + +#: screen.py:384 +msgid "Klipper has encountered an error." +msgstr "" + +#: screen.py:376 +msgid "" +"Klipper has encountered an error.\n" +"Issue a FIRMWARE_RESTART to attempt fixing the issue." +msgstr "" + +#: screen.py:402 +msgid "Klipper has shutdown" +msgstr "" + +#: screen.py:398 +msgid "Klipper is attempting to start" +msgstr "" + +#: ks_includes/KlipperScreen.conf:141 +msgid "Klipper will reboot" +msgstr "" + +#: panels/system.py:43 panels/system.py:42 panels/system.py:39 msgid "KlipperScreen Version" msgstr "" -#: panels/system.py:62 +#: panels/job_status.py:123 +msgid "Left:" +msgstr "" + +#: panels/system.py:62 panels/system.py:57 msgid "Load Average" msgstr "" -#: panels/zcalibrate.py:34 +#: panels/zcalibrate.py:34 panels/zcalibrate.py:39 msgid "Lower Nozzle" msgstr "" +#: ks_includes/KlipperScreen.conf:89 +msgid "Macros" +msgstr "" + +#: panels/job_status.py:273 ks_includes/KlipperScreen.conf:14 +msgid "Main Menu" +msgstr "" + #: panels/extrude.py:20 panels/extrude.py:21 panels/extrude.py:24 +#: panels/extrude.py:22 panels/extrude.py:23 panels/extrude.py:26 msgid "Medium" msgstr "" -#: panels/move.py:87 +#: ks_includes/KlipperScreen.conf:69 +msgid "Move" +msgstr "" + +#: panels/move.py:87 panels/move.py:86 msgid "Move Distance (mm)" msgstr "" -#: panels/network.py:28 +#: ks_includes/KlipperScreen.conf:124 ks_includes/KlipperScreen.conf:173 +msgid "Network" +msgstr "" + +#: panels/network.py:28 panels/network.py:31 msgid "Network Info" msgstr "" -#: panels/temperature.py:51 +#: panels/temperature.py:51 panels/temperature.py:55 msgid "Number Pad" msgstr "" -#: panels/job_status.py:70 +#: panels/job_status.py:70 panels/job_status.py:275 msgid "Pause" msgstr "" -#: panels/print.py:224 +#: panels/job_status.py:454 +msgid "Paused" +msgstr "" + +#: ks_includes/KlipperScreen.conf:95 +msgid "Power" +msgstr "" + +#: panels/splash_screen.py:59 +msgid "Power On Printer" +msgstr "" + +#: ks_includes/KlipperScreen.conf:21 +msgid "Preheat" +msgstr "" + +#: panels/print.py:224 panels/print.py:192 ks_includes/KlipperScreen.conf:34 msgid "Print" msgstr "" -#: panels/print.py:154 +#: ks_includes/KlipperScreen.conf:149 +msgid "Print Control" +msgstr "" + +#: panels/print.py:154 panels/print.py:122 msgid "Print Time" msgstr "" -#: panels/zcalibrate.py:32 +#: panels/job_status.py:231 +msgid "Printing" +msgstr "" + +#: panels/zcalibrate.py:32 panels/zcalibrate.py:37 msgid "Raise Nozzle" msgstr "" -#: panels/splash_screen.py:57 +#: panels/splash_screen.py:57 panels/job_status.py:277 +#: panels/splash_screen.py:60 msgid "Restart" msgstr "" -#: panels/job_status.py:68 +#: panels/job_status.py:68 panels/job_status.py:279 msgid "Resume" msgstr "" -#: panels/extrude.py:34 +#: panels/extrude.py:34 panels/extrude.py:45 msgid "Retract" msgstr "" -#: panels/fan.py:39 +#: ks_includes/KlipperScreen.conf:134 +msgid "Save Config" +msgstr "" + +#: ks_includes/KlipperScreen.conf:139 +msgid "Save configuration." +msgstr "" + +#: panels/bed_level.py:108 +msgid "Screws Adjust" +msgstr "" + +#: panels/fan.py:39 panels/fan.py:42 msgid "Set Speed" msgstr "" -#: panels/print.py:152 +#: panels/print.py:152 panels/print.py:120 msgid "Size" msgstr "" -#: panels/extrude.py:21 panels/extrude.py:23 +#: panels/extrude.py:21 panels/extrude.py:23 panels/extrude.py:25 msgid "Slow" msgstr "" @@ -223,19 +387,24 @@ msgstr "" msgid "Speed" msgstr "" -#: panels/fine_tune.py:54 +#: panels/fine_tune.py:54 panels/fine_tune.py:47 msgid "Speed +" msgstr "" -#: panels/fine_tune.py:58 +#: panels/fine_tune.py:58 panels/fine_tune.py:51 msgid "Speed -" msgstr "" +#: ks_includes/KlipperScreen.conf:129 ks_includes/KlipperScreen.conf:178 +msgid "System" +msgstr "" + #: panels/system.py:31 panels/system.py:30 msgid "System Information" msgstr "" -#: panels/extrude.py:36 +#: panels/extrude.py:36 panels/extrude.py:47 ks_includes/KlipperScreen.conf:84 +#: ks_includes/KlipperScreen.conf:152 msgid "Temperature" msgstr "" @@ -247,42 +416,53 @@ msgstr "" msgid "Time Left" msgstr "" +#: panels/extrude.py:35 +msgid "Tool" +msgstr "" + #: panels/extrude.py:30 msgid "Tool 1" msgstr "" -#: panels/print.py:150 +#: panels/print.py:150 panels/print.py:118 msgid "Uploaded" msgstr "" -#: panels/move.py:23 +#: panels/move.py:23 panels/move.py:25 msgid "X+" msgstr "" -#: panels/move.py:25 +#: panels/move.py:25 panels/move.py:27 msgid "X-" msgstr "" -#: panels/move.py:28 +#: panels/move.py:28 panels/move.py:30 msgid "Y+" msgstr "" -#: panels/move.py:30 +#: panels/move.py:30 panels/move.py:32 msgid "Y-" msgstr "" +#: ks_includes/KlipperScreen.conf:118 +msgid "Z Calibrate" +msgstr "" + #: panels/fine_tune.py:35 panels/fine_tune.py:131 panels/zcalibrate.py:23 +#: panels/zcalibrate.py:28 msgid "Z Offset" msgstr "" -#: panels/fine_tune.py:33 panels/move.py:33 +#: panels/fine_tune.py:33 panels/move.py:33 panels/fine_tune.py:36 +#: panels/move.py:35 msgid "Z+" msgstr "" -#: panels/fine_tune.py:37 panels/move.py:35 +#: panels/fine_tune.py:37 panels/move.py:35 panels/fine_tune.py:40 +#: panels/move.py:37 msgid "Z-" msgstr "" -#: panels/fine_tune.py:35 +#: panels/fine_tune.py:35 panels/fine_tune.py:38 msgid "mm" msgstr "" diff --git a/panels/job_status.py b/panels/job_status.py index c3d43456..92b5940b 100644 --- a/panels/job_status.py +++ b/panels/job_status.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import gi import logging import math diff --git a/panels/menu.py b/panels/menu.py index 0822707d..00f30a7e 100644 --- a/panels/menu.py +++ b/panels/menu.py @@ -1,9 +1,10 @@ +import gettext import gi import logging gi.require_version("Gtk", "3.0") from gi.repository import Gtk, Gdk, GLib -from jinja2 import Template +from jinja2 import Environment, Template from ks_includes.screen_panel import ScreenPanel @@ -57,8 +58,14 @@ class MenuPanel(ScreenPanel): for i in range(len(self.items)): key = list(self.items[i])[0] item = self.items[i][key] + + env = Environment(extensions=["jinja2.ext.i18n"]) + env.install_gettext_translations(self.lang) + j2_temp = env.from_string(item['name']) + parsed_name = j2_temp.render() + b = self._gtk.ButtonImage( - item['icon'], item['name'], "color"+str((i%4)+1) + item['icon'], parsed_name, "color"+str((i%4)+1) ) if item['panel'] != False: b.connect("clicked", self.menu_item_clicked, item['panel'], item) diff --git a/panels/temperature.py b/panels/temperature.py index b9b5fcdf..70221fa3 100644 --- a/panels/temperature.py +++ b/panels/temperature.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import gi import logging diff --git a/screen.py b/screen.py index c73cfed2..2f9a6e22 100644 --- a/screen.py +++ b/screen.py @@ -18,6 +18,7 @@ import subprocess gi.require_version("Gtk", "3.0") from gi.repository import Gtk, Gdk, GLib, Pango +from jinja2 import Environment, Template from ks_includes.KlippyWebsocket import KlippyWebsocket from ks_includes.KlippyRest import KlippyRest @@ -440,6 +441,14 @@ class KlipperScreen(Gtk.Window): {"name":_("Cancel"),"response": Gtk.ResponseType.CANCEL} ] + try: + env = Environment(extensions=["jinja2.ext.i18n"]) + env.install_gettext_translations(self.lang) + j2_temp = env.from_string(text) + text = j2_temp.render() + except: + logger.debug("Error parsing jinja for confirm_send_action") + label = Gtk.Label() label.set_markup(text) label.set_hexpand(True)