Skip to content

Commit 65f9376

Browse files
committed
MarlinUI multi-language support (MarlinFirmware#20725)
1 parent d91dea6 commit 65f9376

16 files changed

Lines changed: 202 additions & 26 deletions

File tree

Marlin/Configuration_adv.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,16 @@
15261526
#endif
15271527
#endif // HAS_DGUS_LCD
15281528

1529+
//
1530+
// Specify additional languages for the UI. Default specified by LCD_LANGUAGE.
1531+
//
1532+
#if EITHER(DOGLCD, TOUCH_UI_FTDI_EVE)
1533+
//#define LCD_LANGUAGE_2 fr
1534+
//#define LCD_LANGUAGE_3 de
1535+
//#define LCD_LANGUAGE_4 es
1536+
//#define LCD_LANGUAGE_5 it
1537+
#endif
1538+
15291539
//
15301540
// Touch UI for the FTDI Embedded Video Engine (EVE)
15311541
//
@@ -1601,13 +1611,6 @@
16011611
// Use a smaller font when labels don't fit buttons
16021612
#define TOUCH_UI_FIT_TEXT
16031613

1604-
// Allow language selection from menu at run-time (otherwise use LCD_LANGUAGE)
1605-
//#define LCD_LANGUAGE_1 en
1606-
//#define LCD_LANGUAGE_2 fr
1607-
//#define LCD_LANGUAGE_3 de
1608-
//#define LCD_LANGUAGE_4 es
1609-
//#define LCD_LANGUAGE_5 it
1610-
16111614
// Use a numeric passcode for "Screen lock" keypad.
16121615
// (recommended for smaller displays)
16131616
//#define TOUCH_UI_PASSCODE

Marlin/src/core/multi_language.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
****************************************************************************/
2121
#pragma once
2222

23+
#include "../inc/MarlinConfigPre.h"
24+
2325
typedef const char Language_Str[];
2426

2527
#ifdef LCD_LANGUAGE_5
@@ -57,26 +59,27 @@ typedef const char Language_Str[];
5759
#define GET_LANG(LANG) _GET_LANG(LANG)
5860

5961
#if NUM_LANGUAGES > 1
60-
extern uint8_t lang;
62+
#define HAS_MULTI_LANGUAGE 1
6163
#define GET_TEXT(MSG) ( \
62-
lang == 0 ? GET_LANG(LCD_LANGUAGE)::MSG : \
63-
lang == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
64-
lang == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
65-
lang == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
66-
GET_LANG(LCD_LANGUAGE_5)::MSG \
67-
)
68-
#define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE)::CHARSIZE, \
69-
GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
70-
GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
71-
GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
72-
GET_LANG(LCD_LANGUAGE_5)::CHARSIZE)
64+
ui.language == 0 ? GET_LANG(LCD_LANGUAGE )::MSG : \
65+
ui.language == 1 ? GET_LANG(LCD_LANGUAGE_2)::MSG : \
66+
ui.language == 2 ? GET_LANG(LCD_LANGUAGE_3)::MSG : \
67+
ui.language == 3 ? GET_LANG(LCD_LANGUAGE_4)::MSG : \
68+
GET_LANG(LCD_LANGUAGE_5)::MSG )
69+
#define MAX_LANG_CHARSIZE _MAX(GET_LANG(LCD_LANGUAGE )::CHARSIZE, \
70+
GET_LANG(LCD_LANGUAGE_2)::CHARSIZE, \
71+
GET_LANG(LCD_LANGUAGE_3)::CHARSIZE, \
72+
GET_LANG(LCD_LANGUAGE_4)::CHARSIZE, \
73+
GET_LANG(LCD_LANGUAGE_5)::CHARSIZE )
7374
#else
7475
#define GET_TEXT(MSG) GET_LANG(LCD_LANGUAGE)::MSG
75-
#define MAX_LANG_CHARSIZE GET_LANG(LCD_LANGUAGE)::CHARSIZE
76+
#define MAX_LANG_CHARSIZE LANG_CHARSIZE
7677
#endif
7778
#define GET_TEXT_F(MSG) (const __FlashStringHelper*)GET_TEXT(MSG)
7879

7980
#define GET_LANGUAGE_NAME(INDEX) GET_LANG(LCD_LANGUAGE_##INDEX)::LANGUAGE
81+
#define LANG_CHARSIZE GET_TEXT(CHARSIZE)
82+
#define USE_WIDE_GLYPH (LANG_CHARSIZE > 2)
8083

8184
#define MSG_1_LINE(A) A "\0" "\0"
8285
#define MSG_2_LINE(A,B) A "\0" B "\0"

Marlin/src/gcode/gcode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
718718
case 412: M412(); break; // M412: Enable/Disable filament runout detection
719719
#endif
720720

721+
#if HAS_MULTI_LANGUAGE
722+
case 414: M414(); break; // M414: Select multi language menu
723+
#endif
724+
721725
#if HAS_LEVELING
722726
case 420: M420(); break; // M420: Enable/Disable Bed Leveling
723727
#endif

Marlin/src/gcode/gcode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
* M410 - Quickstop. Abort all planned moves.
214214
* M412 - Enable / Disable Filament Runout Detection. (Requires FILAMENT_RUNOUT_SENSOR)
215215
* M413 - Enable / Disable Power-Loss Recovery. (Requires POWER_LOSS_RECOVERY)
216+
* M414 - Set language by index. (Requires LCD_LANGUAGE_2...)
216217
* M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
217218
* M421 - Set a single Z coordinate in the Mesh Leveling grid. X<units> Y<units> Z<units> (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL)
218219
* M422 - Set Z Stepper automatic alignment position using probe. X<units> Y<units> A<axis> (Requires Z_STEPPER_AUTO_ALIGN)
@@ -747,6 +748,8 @@ class GcodeSuite {
747748

748749
TERN_(HAS_FILAMENT_SENSOR, static void M412());
749750

751+
TERN_(HAS_MULTI_LANGUAGE, static void M414());
752+
750753
#if HAS_LEVELING
751754
static void M420();
752755
static void M421();

Marlin/src/gcode/lcd/M414.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "../../inc/MarlinConfig.h"
24+
25+
#if HAS_MULTI_LANGUAGE
26+
27+
#include "../gcode.h"
28+
#include "../../MarlinCore.h"
29+
#include "../../lcd/marlinui.h"
30+
31+
/**
32+
* M414: Set the language for the UI
33+
*
34+
* Parameters
35+
* S<index> : The language to select
36+
*/
37+
void GcodeSuite::M414() {
38+
39+
if (parser.seenval('S'))
40+
ui.set_language(parser.value_byte());
41+
42+
}
43+
44+
#endif // HAS_MULTI_LANGUAGE

Marlin/src/inc/MarlinConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@
5555
#include "../core/serial.h"
5656

5757
#endif
58+
59+
#include "../core/multi_language.h"

Marlin/src/lcd/dogm/marlinui_DOGM.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "../../sd/cardreader.h"
5555
#include "../../module/temperature.h"
5656
#include "../../module/printcounter.h"
57+
#include "../../MarlinCore.h"
5758

5859
#if ENABLED(SDSUPPORT)
5960
#include "../../libs/duration_t.h"
@@ -455,20 +456,22 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
455456
inline void draw_boxed_string(const u8g_uint_t x, const u8g_uint_t y, PGM_P const pstr, const bool inv) {
456457
const u8g_uint_t len = utf8_strlen_P(pstr),
457458
by = (y + 1) * (MENU_FONT_HEIGHT);
458-
const pixel_len_t bw = len * (MENU_FONT_WIDTH), bx = x * (MENU_FONT_WIDTH);
459+
const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
460+
const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH);
459461
if (inv) {
460462
u8g.setColorIndex(1);
461-
u8g.drawBox(bx - 1, by - (MENU_FONT_ASCENT) + 1, bw + 2, MENU_FONT_HEIGHT - 1);
463+
u8g.drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT) + 1, bw / prop + 2, MENU_FONT_HEIGHT - 1);
462464
u8g.setColorIndex(0);
463465
}
464-
lcd_put_u8str_P(bx, by, pstr);
466+
lcd_put_u8str_P(bx / prop, by, pstr);
465467
if (inv) u8g.setColorIndex(1);
466468
}
467469

468470
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
469471
ui.draw_select_screen_prompt(pref, string, suff);
470472
draw_boxed_string(1, LCD_HEIGHT - 1, no, !yesno);
471-
draw_boxed_string(LCD_WIDTH - (utf8_strlen_P(yes) + 1), LCD_HEIGHT - 1, yes, yesno);
473+
const u8g_uint_t xpos = (LCD_WIDTH) / (USE_WIDE_GLYPH ? 2 : 1);
474+
draw_boxed_string(xpos - (utf8_strlen_P(yes) + 1), LCD_HEIGHT - 1, yes, yesno);
472475
}
473476

474477
#if ENABLED(SDSUPPORT)

Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ static const char assets[][LONG_FILENAME_LENGTH] = {
6464
"bmp_speed255.bin",
6565
"bmp_speed127.bin",
6666
"bmp_speed0.bin",
67-
"bmp_speed0.bin",
6867

6968
"bmp_bed.bin",
7069
"bmp_step1_degree.bin",

Marlin/src/lcd/lcdprint.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#if HAS_WIRED_LCD && !HAS_GRAPHICAL_TFT
3030

31+
#include "marlinui.h"
3132
#include "lcdprint.h"
3233

3334
/**

Marlin/src/lcd/marlinui.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
7878
#endif
7979
#endif
8080

81+
#if HAS_MULTI_LANGUAGE
82+
uint8_t MarlinUI::language; // Initialized by settings.load()
83+
#endif
84+
8185
#if ENABLED(SOUND_MENU_ITEM)
8286
bool MarlinUI::buzzer_enabled = true;
8387
#endif

0 commit comments

Comments
 (0)