summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2023-05-22 10:30:13 -0400
committerSolomon Peachy <pizza@shaftnet.org>2023-05-22 10:30:13 -0400
commit92b80bdba589672b99820a90ad2624d89f555ef1 (patch)
treeaa36f69c7f54a941cfb2d1638f0f04daced99e61
parentab0ba139f50a9c9b3eadbe1c15d44ce88cf980d3 (diff)
downloadrockbox-92b80bdba589672b99820a90ad2624d89f555ef1.tar.gz
rockbox-92b80bdba589672b99820a90ad2624d89f555ef1.zip
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
-rw-r--r--apps/lang/chinese-simp.lang2
-rw-r--r--apps/lang/chinese-trad.lang2
-rw-r--r--apps/language.c13
-rw-r--r--apps/language.h2
-rw-r--r--apps/talk.c6
-rwxr-xr-xtools/genlang4
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 @@
13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14# KIND, either express or implied. 14# KIND, either express or implied.
15# 15#
16# LANGUAGE_UNITS_FIRST
17#
16# Simplified Chinese language file, translated by: 18# Simplified Chinese language file, translated by:
17# - Ye Wei 19# - Ye Wei
18# - Xinlu Huang 20# - 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 @@
13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14# KIND, either express or implied. 14# KIND, either express or implied.
15# 15#
16# LANGUAGE_UNITS_FIRST
17#
16# Traditional Chinese language file, translated by: 18# Traditional Chinese language file, translated by:
17# - Wenbin Leo 19# - Wenbin Leo
18# - Xinlu Huang 20# - 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 @@
37/* See tools/genlang (TODO: Use common include for both) */ 37/* See tools/genlang (TODO: Use common include for both) */
38#define LANGUAGE_COOKIE 0x1a 38#define LANGUAGE_COOKIE 0x1a
39#define LANGUAGE_VERSION 0x06 39#define LANGUAGE_VERSION 0x06
40#define LANGUAGE_FLAG_RTL 0x01 40
41#define LANGUAGE_FLAG_RTL 0x01
42#define LANGUAGE_FLAG_UNITS_FIRST 0x02
41 43
42#define HEADER_SIZE 4 44#define HEADER_SIZE 4
43#define SUBHEADER_SIZE 6 45#define SUBHEADER_SIZE 6
@@ -54,8 +56,8 @@ void lang_init(const unsigned char *builtin, unsigned char **dest, int count)
54 } 56 }
55} 57}
56 58
57int lang_load(const char *filename, const unsigned char *builtin, 59int lang_load(const char *filename, const unsigned char *builtin,
58 unsigned char **dest, unsigned char *buffer, 60 unsigned char **dest, unsigned char *buffer,
59 unsigned int user_num, int max_lang_size, 61 unsigned int user_num, int max_lang_size,
60 unsigned int max_id) 62 unsigned int max_id)
61{ 63{
@@ -143,3 +145,8 @@ int lang_is_rtl(void)
143{ 145{
144 return (lang_options & LANGUAGE_FLAG_RTL) != 0; 146 return (lang_options & LANGUAGE_FLAG_RTL) != 0;
145} 147}
148
149int lang_units_first(void)
150{
151 return (lang_options & LANGUAGE_FLAG_UNITS_FIRST) != 0;
152}
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);
37 37
38/* returns whether the loaded language is a right-to-left language */ 38/* returns whether the loaded language is a right-to-left language */
39int lang_is_rtl(void); 39int lang_is_rtl(void);
40/* returns whether the loaded language needs units spoken before the value */
41int lang_units_first(void);
40#endif 42#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 @@
35#include "voice_thread.h" 35#include "voice_thread.h"
36#include "audio.h" 36#include "audio.h"
37#include "lang.h" 37#include "lang.h"
38#include "language.h"
38#include "talk.h" 39#include "talk.h"
39#include "metadata.h" 40#include "metadata.h"
40/*#define LOGF_ENABLE*/ 41/*#define LOGF_ENABLE*/
@@ -1419,8 +1420,11 @@ int talk_value_decimal(long n, int unit, int decimals, bool enqueue)
1419 return 0; 1420 return 0;
1420 } 1421 }
1421 1422
1423 if (lang_units_first())
1424 talk_id(unit_id, true); /* say the unit, if any */
1422 talk_number(n, enqueue); /* say the number */ 1425 talk_number(n, enqueue); /* say the number */
1423 talk_id(unit_id, true); /* say the unit, if any */ 1426 if (!lang_units_first())
1427 talk_id(unit_id, true); /* say the unit, if any */
1424 1428
1425 return 0; 1429 return 0;
1426} 1430}
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;
16my $VOICE_COOKIE = 0x9a; 16my $VOICE_COOKIE = 0x9a;
17my $LANGUAGE_VERSION = 0x06; 17my $LANGUAGE_VERSION = 0x06;
18my $LANGUAGE_FLAG_RTL = 0x01; 18my $LANGUAGE_FLAG_RTL = 0x01;
19my $LANGUAGE_FLAG_UNITS_FIRST = 0x02;
19 20
20my $HEADER_SIZE = 4; 21my $HEADER_SIZE = 4;
21my $SUBHEADER_SIZE = 6; 22my $SUBHEADER_SIZE = 6;
@@ -372,6 +373,9 @@ while(<LANG>) {
372 if ($_ =~ /LANGUAGE_IS_RTL/) { 373 if ($_ =~ /LANGUAGE_IS_RTL/) {
373 $langoptions |= $LANGUAGE_FLAG_RTL; 374 $langoptions |= $LANGUAGE_FLAG_RTL;
374 } 375 }
376 if ($_ =~ /LANGUAGE_UNITS_FIRST/) {
377 $langoptions |= $LANGUAGE_FLAG_UNITS_FIRST;
378 }
375 379
376 if ($header and $sortfile) { 380 if ($header and $sortfile) {
377 print($_); 381 print($_);