summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-05-19 17:14:35 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-06-09 22:44:56 +0200
commitd6ef5a0d8057bd6a0f9925d1002cc1a3207ff3b7 (patch)
tree4a87f6b59b203d54d931e4351d851fa00b540ae2
parent1e2c6506fbf503bace8356f90cd54a5b01a32f88 (diff)
downloadrockbox-d6ef5a0d8057bd6a0f9925d1002cc1a3207ff3b7.tar.gz
rockbox-d6ef5a0d8057bd6a0f9925d1002cc1a3207ff3b7.zip
Create binary voice string archive on target.
Extend genlang to create files holding the voice strings in a binary format similar to lng. Create such files for all languages during a normal build, put them in a zip file and add them to rockbox.zip so they are installed with a main build. Creating a voice file requires access to the voice strings, which are currently not distributed with Rockbox. Therefore it is necessary to either have access to the source code of the installed build or to use a build the genlang service on rockbox.org can retrieve the strings for, making it impossible for normal users to generate a voice file for custom builds, test builds and older builds that aren't supported by the rockbox.org script. It also requires a network connection when creating voice files with Rockbox Utility even if creating a voice file by itself isn't network related. Furthermore, putting the voice strings on the target is also a prerequisite for eventually supporting a TTS on the player. Strip voice strings path. Change-Id: Ic2f86130909b3b257986a348e5cfcf618c4500c3
-rw-r--r--apps/lang/lang.make11
-rwxr-xr-xtools/buildzip.pl1
-rwxr-xr-xtools/genlang60
3 files changed, 57 insertions, 15 deletions
diff --git a/apps/lang/lang.make b/apps/lang/lang.make
index d0dac71e95..a1351cee67 100644
--- a/apps/lang/lang.make
+++ b/apps/lang/lang.make
@@ -9,6 +9,7 @@
9 9
10LANGS := $(call preprocess, $(APPSDIR)/lang/SOURCES) 10LANGS := $(call preprocess, $(APPSDIR)/lang/SOURCES)
11LANGOBJ := $(LANGS:$(ROOTDIR)/%.lang=$(BUILDDIR)/%.lng) 11LANGOBJ := $(LANGS:$(ROOTDIR)/%.lang=$(BUILDDIR)/%.lng)
12VOICEOBJ := $(LANGS:$(ROOTDIR)/%.lang=$(BUILDDIR)/%.vstrings)
12LANG_O = $(BUILDDIR)/lang/lang_core.o 13LANG_O = $(BUILDDIR)/lang/lang_core.o
13 14
14CLEANOBJS += $(BUILDDIR)/lang/max_language_size.h $(BUILDDIR)/lang/lang* 15CLEANOBJS += $(BUILDDIR)/lang/max_language_size.h $(BUILDDIR)/lang/lang*
@@ -23,7 +24,7 @@ CLEANOBJS += $(BUILDDIR)/lang/max_language_size.h $(BUILDDIR)/lang/lang*
23# SUBHEADER_SIZE. 24# SUBHEADER_SIZE.
24# TODO: In the future generate this file within genlang or another script 25# TODO: In the future generate this file within genlang or another script
25# in order to only calculate the maximum size based on the core strings. 26# in order to only calculate the maximum size based on the core strings.
26$(BUILDDIR)/lang/max_language_size.h: $(LANGOBJ) 27$(BUILDDIR)/lang/max_language_size.h: $(LANGOBJ) $(BUILDDIR)/apps/lang/voicestrings.zip
27 $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@)) 28 $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@))
28 $(SILENT)echo "#define MAX_LANGUAGE_SIZE `ls -ln $(BUILDDIR)/apps/lang/* | awk '{print $$5-10}' | sort -n | tail -1`" > $@ 29 $(SILENT)echo "#define MAX_LANGUAGE_SIZE `ls -ln $(BUILDDIR)/apps/lang/* | awk '{print $$5-10}' | sort -n | tail -1`" > $@
29 30
@@ -34,7 +35,11 @@ $(BUILDDIR)/lang/lang_core.o: $(APPSDIR)/lang/$(LANGUAGE).lang $(BUILDDIR)/apps/
34 35
35$(BUILDDIR)/lang/lang.h: $(BUILDDIR)/lang/lang_core.o 36$(BUILDDIR)/lang/lang.h: $(BUILDDIR)/lang/lang_core.o
36 37
37$(BUILDDIR)/%.lng : $(ROOTDIR)/%.lang $(BUILDDIR)/apps/genlang-features 38$(BUILDDIR)/%.lng $(BUILDDIR)/%.vstrings: $(ROOTDIR)/%.lang $(BUILDDIR)/apps/genlang-features
38 $(call PRINTS,GENLANG $(subst $(ROOTDIR)/,,$<)) 39 $(call PRINTS,GENLANG $(subst $(ROOTDIR)/,,$<))
39 $(SILENT)mkdir -p $(dir $@) 40 $(SILENT)mkdir -p $(dir $@)
40 $(SILENT)$(TOOLSDIR)/genlang -e=$(APPSDIR)/lang/english.lang -t=$(MODELNAME):`cat $(BUILDDIR)/apps/genlang-features` -i=$(TARGET_ID) -b=$@ $< 41 $(SILENT)$(TOOLSDIR)/genlang -e=$(APPSDIR)/lang/english.lang -t=$(MODELNAME):`cat $(BUILDDIR)/apps/genlang-features` -i=$(TARGET_ID) -b=$*.lng -c=$*.vstrings $<
42
43$(BUILDDIR)/apps/lang/voicestrings.zip: $(VOICEOBJ)
44 $(call PRINTS,ZIP $(subst $(BUILDDIR)/,,$@))
45 $(SILENT)zip -9 -q $@ $(subst $(BUILDDIR)/,,$^)
diff --git a/tools/buildzip.pl b/tools/buildzip.pl
index e2341f4252..70445570f8 100755
--- a/tools/buildzip.pl
+++ b/tools/buildzip.pl
@@ -683,6 +683,7 @@ STOP
683 683
684 # copy the already built lng files 684 # copy the already built lng files
685 glob_copy('apps/lang/*lng', "$temp_dir/langs/"); 685 glob_copy('apps/lang/*lng', "$temp_dir/langs/");
686 glob_copy('apps/lang/*.zip', "$temp_dir/langs/");
686 687
687 # copy the .lua files 688 # copy the .lua files
688 glob_mkdir("$temp_dir/rocks/viewers/lua/"); 689 glob_mkdir("$temp_dir/rocks/viewers/lua/");
diff --git a/tools/genlang b/tools/genlang
index bfd9fac7b5..ac49e594d3 100755
--- a/tools/genlang
+++ b/tools/genlang
@@ -13,6 +13,7 @@
13# See apps/language.c (TODO: Use common include for both) 13# See apps/language.c (TODO: Use common include for both)
14# Cookie and binary version for the binary lang file 14# Cookie and binary version for the binary lang file
15my $LANGUAGE_COOKIE = 0x1a; 15my $LANGUAGE_COOKIE = 0x1a;
16my $VOICE_COOKIE = 0x9a;
16my $LANGUAGE_VERSION = 0x06; 17my $LANGUAGE_VERSION = 0x06;
17my $LANGUAGE_FLAG_RTL = 0x01; 18my $LANGUAGE_FLAG_RTL = 0x01;
18 19
@@ -38,6 +39,10 @@ Usage: genlang [options] <langv2 file>
38 Make the tool create a binary language (.lng) file named [outfile]. 39 Make the tool create a binary language (.lng) file named [outfile].
39 The use of this option requires that you also use -e, -t and -i. 40 The use of this option requires that you also use -e, -t and -i.
40 41
42 -c=<outfile>
43 Create binary voicestring file named [outfile]. Works like -b and can be
44 used the same time.
45
41 -u 46 -u
42 Update language file. Given the translated file and the most recent english 47 Update language file. Given the translated file and the most recent english
43 file, you\'ll get an updated version sent to stdout. Suitable action to do 48 file, you\'ll get an updated version sent to stdout. Suitable action to do
@@ -89,18 +94,19 @@ my $prefix = $p;
89my $binary = $b; 94my $binary = $b;
90my $update = $u; 95my $update = $u;
91my $sortfile = $s; 96my $sortfile = $s;
97my $binvoice = $c;
92 98
93my $english = $e; 99my $english = $e;
94my $voiceout = $o; 100my $voiceout = $o;
95 101
96my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0) + ($sortfile?1:0); 102my $check = ($binary?.5:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0) + ($sortfile?1:0) + ($binvoice?.5:0);
97 103
98if($check > 1) { 104if($check > 1) {
99 print STDERR "Please use only one of -p, -u, -o, -b and -s\n"; 105 print STDERR "Please use only one of -p, -u, -o, -b, -c and -s\n";
100 exit; 106 exit;
101} 107}
102if(!$check) { 108if(!$check) {
103 print STDERR "Please use at least one of -p, -u, -o, -b and -s\n"; 109 print STDERR "Please use at least one of -p, -u, -o, -c, -e and -s\n";
104 exit; 110 exit;
105} 111}
106 112
@@ -724,7 +730,7 @@ MOO
724 close(HFILE_CORE); 730 close(HFILE_CORE);
725 close(CFILE_CORE); 731 close(CFILE_CORE);
726} # end of the c/h file generation 732} # end of the c/h file generation
727elsif($binary) { 733elsif($binary || $binvoice) {
728 # Creation of a binary lang file was requested 734 # Creation of a binary lang file was requested
729 735
730 # We must first scan the english file to get the correct order of the id 736 # We must first scan the english file to get the correct order of the id
@@ -732,10 +738,18 @@ elsif($binary) {
732 # files. The english file is scanned before the translated file was 738 # files. The english file is scanned before the translated file was
733 # scanned. 739 # scanned.
734 740
735 open(OUTF, ">$binary") or die "Error: Can't create $binary"; 741 if($binary) {
736 binmode OUTF; 742 open(OUTF, ">$binary") or die "Error: Can't create $binary";
737 printf OUTF ("%c%c%c%c", $LANGUAGE_COOKIE, $LANGUAGE_VERSION, $target_id, 743 binmode OUTF;
738 $langoptions); # magic lang file header 744 printf OUTF ("%c%c%c%c", $LANGUAGE_COOKIE, $LANGUAGE_VERSION, $target_id,
745 $langoptions); # magic lang file header
746 }
747 if($binvoice) {
748 open(OUTV, ">$binvoice") or die "Error: Can't create $binary";
749 binmode OUTV;
750 printf OUTV ("%c%c%c%c", $VOICE_COOKIE, $LANGUAGE_VERSION, $target_id,
751 $langoptions); # magic lang file header
752 }
739 753
740 # output the number of strings for each user 754 # output the number of strings for each user
741 my $foffset = $HEADER_SIZE + $SUBHEADER_SIZE * keys(%users); 755 my $foffset = $HEADER_SIZE + $SUBHEADER_SIZE * keys(%users);
@@ -744,18 +758,28 @@ elsif($binary) {
744 for $n (0 .. $idcount[$_]-1) { 758 for $n (0 .. $idcount[$_]-1) {
745 $size += length(trim($dest{$idnum[$_][$n]})) + 1; 759 $size += length(trim($dest{$idnum[$_][$n]})) + 1;
746 } 760 }
747 printf OUTF ("%c%c%c%c%c%c", ($idcount[$_] >> 8), ($idcount[$_] & 0xff), 761 if($binary) {
748 ($size >> 8), ($size & 0xff), ($foffset >> 8), ($foffset & 0xff)); 762 printf OUTF ("%c%c%c%c%c%c", ($idcount[$_] >> 8), ($idcount[$_] & 0xff),
763 ($size >> 8), ($size & 0xff), ($foffset >> 8), ($foffset & 0xff));
764 }
765 if($binvoice) {
766 printf OUTV ("%c%c%c%c%c%c", ($idcount[$_] >> 8), ($idcount[$_] & 0xff),
767 ($size >> 8), ($size & 0xff), ($foffset >> 8), ($foffset & 0xff));
768 }
749 $foffset += $size; 769 $foffset += $size;
750 } 770 }
751 771
752 for (keys %users) { 772 for (keys %users) {
753 # loop over the target phrases 773 # loop over the target phrases
754 for $n (0 .. $idcount[$_]-1) { 774 # This loops over the strings in the translated language file order
775 my @ids = ((0 .. ($idcount[$_]-1)));
776 push @ids, (0x8000 .. ($voiceid[$_]-1));
777 for $n (@ids) {
755 my $name=$idnum[$_][$n]; # get the ID 778 my $name=$idnum[$_][$n]; # get the ID
756 my $dest = $dest{$name}; # get the destination phrase 779 my $dest = $dest{$name}; # get the destination phrase
780 my $voice = $voice{$name}; # get the destination voice string
757 781
758 if($dest) { 782 if($dest && $n < 0x8000 && $binary) {
759 $dest =~ s/^\"(.*)\"\s*$/$1/g; # cut off quotes 783 $dest =~ s/^\"(.*)\"\s*$/$1/g; # cut off quotes
760 784
761 # Now, make sure we get the number from the english sort order: 785 # Now, make sure we get the number from the english sort order:
@@ -763,8 +787,20 @@ elsif($binary) {
763 787
764 printf OUTF ("%c%c%s\x00", ($idnum>>8), ($idnum&0xff), $dest); 788 printf OUTF ("%c%c%s\x00", ($idnum>>8), ($idnum&0xff), $dest);
765 } 789 }
790 if($voice && $binvoice) {
791 $voice =~ s/^\"(.*)\"\s*$/$1/g; # cut off quotes
792 # Now, make sure we get the number from the english sort order:
793 $idnum = $idmap[$_]{$name};
794 printf OUTV ("%c%c%s\x00", ($idnum>>8), ($idnum&0xff), $voice);
795 }
766 } 796 }
767 } 797 }
798 if($binary) {
799 close(OUTF);
800 }
801 if($binvoice) {
802 close(OUTV);
803 }
768} 804}
769elsif($voiceout) { 805elsif($voiceout) {
770 # voice output requested, display id: and voice: strings in a v1-like 806 # voice output requested, display id: and voice: strings in a v1-like