From 92b80bdba589672b99820a90ad2624d89f555ef1 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Mon, 22 May 2023 10:30:13 -0400 Subject: [PATCH] lang: Support languages that speak the units before a numerical value Previously, it was hardcoded to the english convention of units-last, so "100%" would be voiced as "one hundred percent". This adds a new language flag that makes the units be voiced first, ie "100%" will be voiced as "percent one hundred". So far only the Chinese-traditional and Chinese-simplified languages utilize this feature (taken from an old ticket, FS#10340) but I'm sure others would want this feature too. Change-Id: Idf825ec9299dc0ed09921cf67aec61b1ab262fc6 --- apps/lang/chinese-simp.lang | 2 ++ apps/lang/chinese-trad.lang | 2 ++ apps/language.c | 13 ++++++++++--- apps/language.h | 2 ++ apps/talk.c | 6 +++++- tools/genlang | 4 ++++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/lang/chinese-simp.lang b/apps/lang/chinese-simp.lang index 3d1d0ecaa3..b7702ee3c7 100644 --- a/apps/lang/chinese-simp.lang +++ b/apps/lang/chinese-simp.lang @@ -13,6 +13,8 @@ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # +# LANGUAGE_UNITS_FIRST +# # Simplified Chinese language file, translated by: # - Ye Wei # - Xinlu Huang diff --git a/apps/lang/chinese-trad.lang b/apps/lang/chinese-trad.lang index 02e14645e0..e7ee7ae607 100644 --- a/apps/lang/chinese-trad.lang +++ b/apps/lang/chinese-trad.lang @@ -13,6 +13,8 @@ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # +# LANGUAGE_UNITS_FIRST +# # Traditional Chinese language file, translated by: # - Wenbin Leo # - Xinlu Huang diff --git a/apps/language.c b/apps/language.c index 1ad1d5c829..d177303d89 100644 --- a/apps/language.c +++ b/apps/language.c @@ -37,7 +37,9 @@ /* See tools/genlang (TODO: Use common include for both) */ #define LANGUAGE_COOKIE 0x1a #define LANGUAGE_VERSION 0x06 -#define LANGUAGE_FLAG_RTL 0x01 + +#define LANGUAGE_FLAG_RTL 0x01 +#define LANGUAGE_FLAG_UNITS_FIRST 0x02 #define HEADER_SIZE 4 #define SUBHEADER_SIZE 6 @@ -54,8 +56,8 @@ void lang_init(const unsigned char *builtin, unsigned char **dest, int count) } } -int lang_load(const char *filename, const unsigned char *builtin, - unsigned char **dest, unsigned char *buffer, +int lang_load(const char *filename, const unsigned char *builtin, + unsigned char **dest, unsigned char *buffer, unsigned int user_num, int max_lang_size, unsigned int max_id) { @@ -143,3 +145,8 @@ int lang_is_rtl(void) { return (lang_options & LANGUAGE_FLAG_RTL) != 0; } + +int lang_units_first(void) +{ + return (lang_options & LANGUAGE_FLAG_UNITS_FIRST) != 0; +} diff --git a/apps/language.h b/apps/language.h index cbfa7e2c1d..85fa7f6efa 100644 --- a/apps/language.h +++ b/apps/language.h @@ -37,4 +37,6 @@ int lang_english_to_id(const char *english); /* returns whether the loaded language is a right-to-left language */ int lang_is_rtl(void); +/* returns whether the loaded language needs units spoken before the value */ +int lang_units_first(void); #endif diff --git a/apps/talk.c b/apps/talk.c index 2ef7fea84d..5d6e7ac0b6 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -35,6 +35,7 @@ #include "voice_thread.h" #include "audio.h" #include "lang.h" +#include "language.h" #include "talk.h" #include "metadata.h" /*#define LOGF_ENABLE*/ @@ -1419,8 +1420,11 @@ int talk_value_decimal(long n, int unit, int decimals, bool enqueue) return 0; } + if (lang_units_first()) + talk_id(unit_id, true); /* say the unit, if any */ talk_number(n, enqueue); /* say the number */ - talk_id(unit_id, true); /* say the unit, if any */ + if (!lang_units_first()) + talk_id(unit_id, true); /* say the unit, if any */ return 0; } diff --git a/tools/genlang b/tools/genlang index 4f7386890d..abff3e8e18 100755 --- a/tools/genlang +++ b/tools/genlang @@ -16,6 +16,7 @@ my $LANGUAGE_COOKIE = 0x1a; my $VOICE_COOKIE = 0x9a; my $LANGUAGE_VERSION = 0x06; my $LANGUAGE_FLAG_RTL = 0x01; +my $LANGUAGE_FLAG_UNITS_FIRST = 0x02; my $HEADER_SIZE = 4; my $SUBHEADER_SIZE = 6; @@ -372,6 +373,9 @@ while() { if ($_ =~ /LANGUAGE_IS_RTL/) { $langoptions |= $LANGUAGE_FLAG_RTL; } + if ($_ =~ /LANGUAGE_UNITS_FIRST/) { + $langoptions |= $LANGUAGE_FLAG_UNITS_FIRST; + } if ($header and $sortfile) { print($_);