eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tr_languages.cpp 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2010 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <wctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <locale.h>
  26. #include <wctype.h>
  27. #include "speak_lib.h"
  28. #include "speech.h"
  29. #include "phoneme.h"
  30. #include "synthesize.h"
  31. #include "translate.h"
  32. #define L_qa 0x716100
  33. #define L_grc 0x677263 // grc Ancient Greek
  34. #define L_jbo 0x6a626f // jbo Lojban
  35. #define L_pap 0x706170 // pap Papiamento
  36. #define L_zhy 0x7a6879 // zhy
  37. // start of unicode pages for character sets
  38. #define OFFSET_GREEK 0x380
  39. #define OFFSET_CYRILLIC 0x420
  40. #define OFFSET_ARMENIAN 0x530
  41. #define OFFSET_ARABIC 0x600
  42. #define OFFSET_DEVANAGARI 0x900
  43. #define OFFSET_BENGALI 0x980
  44. #define OFFSET_GURMUKHI 0xa00
  45. #define OFFSET_TAMIL 0xb80
  46. #define OFFSET_KANNADA 0xc80
  47. #define OFFSET_MALAYALAM 0xd00
  48. #define OFFSET_KOREAN 0x1100
  49. static void Translator_Russian(Translator *tr);
  50. static void SetLetterVowel(Translator *tr, int c)
  51. {//==============================================
  52. tr->letter_bits[c] = (tr->letter_bits[c] & 0x40) | 0x81; // keep value for group 6 (front vowels e,i,y)
  53. }
  54. static void ResetLetterBits(Translator *tr, int groups)
  55. {//====================================================
  56. // Clear all the specified groups
  57. unsigned int ix;
  58. unsigned int mask;
  59. mask = ~groups;
  60. for(ix=0; ix<sizeof(tr->letter_bits); ix++)
  61. {
  62. tr->letter_bits[ix] &= mask;
  63. }
  64. }
  65. static void SetLetterBits(Translator *tr, int group, const char *string)
  66. {//=====================================================================
  67. int bits;
  68. unsigned char c;
  69. bits = (1L << group);
  70. while((c = *string++) != 0)
  71. tr->letter_bits[c] |= bits;
  72. }
  73. static void SetLetterBitsRange(Translator *tr, int group, int first, int last)
  74. {//===========================================================================
  75. int bits;
  76. int ix;
  77. bits = (1L << group);
  78. for(ix=first; ix<=last; ix++)
  79. {
  80. tr->letter_bits[ix] |= bits;
  81. }
  82. }
  83. static Translator* NewTranslator(void)
  84. {//===================================
  85. Translator *tr;
  86. int ix;
  87. static const unsigned char stress_amps2[] = {17,17, 20,20, 20,22, 22,20 };
  88. static const short stress_lengths2[8] = {182,140, 220,220, 220,240, 260,280};
  89. static const wchar_t empty_wstring[1] = {0};
  90. static const wchar_t punct_in_word[2] = {'\'', 0}; // allow hyphen within words
  91. tr = (Translator *)Alloc(sizeof(Translator));
  92. if(tr == NULL)
  93. return(NULL);
  94. tr->charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8
  95. dictionary_name[0] = 0;
  96. tr->dict_condition=0;
  97. tr->data_dictrules = NULL; // language_1 translation rules file
  98. tr->data_dictlist = NULL; // language_2 dictionary lookup file
  99. tr->transpose_offset = 0;
  100. // only need lower case
  101. tr->letter_bits_offset = 0;
  102. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  103. memset(tr->letter_groups,0,sizeof(tr->letter_groups));
  104. // 0-5 sets of characters matched by A B C E F G in pronunciation rules
  105. // these may be set differently for different languages
  106. SetLetterBits(tr,0,"aeiou"); // A vowels, except y
  107. SetLetterBits(tr,1,"bcdfgjklmnpqstvxz"); // B hard consonants, excluding h,r,w
  108. SetLetterBits(tr,2,"bcdfghjklmnpqrstvwxz"); // C all consonants
  109. SetLetterBits(tr,3,"hlmnr"); // H 'soft' consonants
  110. SetLetterBits(tr,4,"cfhkpqstx"); // F voiceless consonants
  111. SetLetterBits(tr,5,"bdgjlmnrvwyz"); // G voiced
  112. SetLetterBits(tr,6,"eiy"); // Letter group Y, front vowels
  113. SetLetterBits(tr,7,"aeiouy"); // vowels, including y
  114. tr->char_plus_apostrophe = empty_wstring;
  115. tr->punct_within_word = punct_in_word;
  116. for(ix=0; ix<8; ix++)
  117. {
  118. tr->stress_amps[ix] = stress_amps2[ix];
  119. tr->stress_amps_r[ix] = stress_amps2[ix] - 1;
  120. tr->stress_lengths[ix] = stress_lengths2[ix];
  121. }
  122. memset(&(tr->langopts),0,sizeof(tr->langopts));
  123. tr->langopts.max_lengthmod = 500;
  124. tr->langopts.stress_rule = STRESSPOSN_2R;
  125. tr->langopts.unstressed_wd1 = 1;
  126. tr->langopts.unstressed_wd2 = 3;
  127. tr->langopts.param[LOPT_SONORANT_MIN] = 95;
  128. tr->langopts.param[LOPT_MAXAMP_EOC] = 19;
  129. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 's'; // don't count this character at start of word
  130. tr->langopts.param[LOPT_BRACKET_PAUSE] = 4; // pause at bracket
  131. tr->langopts.param2[LOPT_BRACKET_PAUSE] = 2; // pauses when announcing bracket names
  132. tr->langopts.param[LOPT_MIN_LONG_VOWEL] = 40;
  133. tr->langopts.max_initial_consonants = 3;
  134. tr->langopts.replace_chars = NULL;
  135. tr->langopts.ascii_language = ""; // Non-Latin alphabet languages, use this language to speak Latin words, default is English
  136. SetLengthMods(tr,201);
  137. // tr->langopts.length_mods = length_mods_en;
  138. // tr->langopts.length_mods0 = length_mods_en0;
  139. tr->langopts.long_stop = 100;
  140. tr->langopts.max_roman = 49;
  141. tr->langopts.min_roman = 2;
  142. tr->langopts.thousands_sep = ',';
  143. tr->langopts.decimal_sep = '.';
  144. tr->langopts.break_numbers = BREAK_THOUSANDS; // 1000, 1000,000 1,000,000 etc
  145. memcpy(tr->punct_to_tone, punctuation_to_tone, sizeof(tr->punct_to_tone));
  146. return(tr);
  147. }
  148. static const unsigned int replace_cyrillic_latin[] =
  149. {0x430,'a',
  150. 0x431,'b',
  151. 0x446,'c',
  152. 0x45b,0x107,
  153. 0x447,0x10d,
  154. 0x45f,'d'+(0x17e<<16),
  155. 0x455,'d'+('z'<<16),
  156. 0x434,'d',
  157. 0x452,0x111,
  158. 0x435,'e',
  159. 0x444,'f',
  160. 0x433,'g',
  161. 0x445,'h',
  162. 0x438,'i',
  163. 0x458,'j',
  164. 0x43a,'k',
  165. 0x459,'l'+('j'<<16),
  166. 0x43b,'l',
  167. 0x43c,'m',
  168. 0x45a,'n'+('j'<<16),
  169. 0x43d,'n',
  170. 0x43e,'o',
  171. 0x43f,'p',
  172. 0x440,'r',
  173. 0x441,'s',
  174. 0x448,0x161,
  175. 0x442,'t',
  176. 0x443,'u',
  177. 0x432,'v',
  178. 0x437,'z',
  179. 0x436,0x17e,
  180. 0x453,0x111,
  181. 0x45c,0x107,
  182. 0}; // ѓ ѕ ќ
  183. void SetIndicLetters(Translator *tr)
  184. {//=================================
  185. // Set letter types for Indic scripts, Devanagari, Tamill, etc
  186. static const char dev_consonants2[] = {0x02,0x03,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f};
  187. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  188. SetLetterBitsRange(tr,LETTERGP_A,0x04,0x14); // vowel letters
  189. SetLetterBitsRange(tr,LETTERGP_A,0x3e,0x4d); // + vowel signs, and virama
  190. SetLetterBitsRange(tr,LETTERGP_B,0x3e,0x4d); // vowel signs, and virama
  191. SetLetterBitsRange(tr,LETTERGP_C,0x15,0x39); // the main consonant range
  192. SetLetterBits(tr,LETTERGP_C,dev_consonants2); // + additional consonants
  193. SetLetterBitsRange(tr,LETTERGP_Y,0x04,0x14); // vowel letters
  194. SetLetterBitsRange(tr,LETTERGP_Y,0x3e,0x4c); // + vowel signs
  195. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  196. tr->langopts.suffix_add_e = tr->letter_bits_offset + 0x4d; //virama
  197. }
  198. void SetupTranslator(Translator *tr, const short *lengths, const unsigned char *amps)
  199. {//==================================================================================
  200. if(lengths != NULL)
  201. memcpy(tr->stress_lengths,lengths,sizeof(tr->stress_lengths));
  202. if(amps != NULL)
  203. memcpy(tr->stress_amps,amps,sizeof(tr->stress_amps));
  204. }
  205. Translator *SelectTranslator(const char *name)
  206. {//===========================================
  207. int name2 = 0;
  208. Translator *tr;
  209. static const unsigned char stress_amps_sk[8] = {17,17, 20,20, 20,22, 22,21 };
  210. static const short stress_lengths_sk[8] = {190,190, 210,210, 0,0, 210,210};
  211. // convert name string into a word of up to 4 characters, for the switch()
  212. while(*name != 0)
  213. name2 = (name2 << 8) + *name++;
  214. tr = NewTranslator();
  215. switch(name2)
  216. {
  217. case L('a','f'):
  218. {
  219. static const short stress_lengths_af[8] = {170,140, 220,220, 0, 0, 250,270};
  220. SetupTranslator(tr,stress_lengths_af,NULL);
  221. tr->langopts.stress_rule = STRESSPOSN_1L;
  222. tr->langopts.vowel_pause = 0x30;
  223. tr->langopts.param[LOPT_DIERESES] = 1;
  224. tr->langopts.param[LOPT_PREFIXES] = 1;
  225. SetLetterVowel(tr,'y'); // add 'y' to vowels
  226. tr->langopts.numbers = NUM_SWAP_TENS | NUM_HUNDRED_AND | NUM_SINGLE_AND | NUM_ROMAN | NUM_1900;
  227. tr->langopts.accents = 1;
  228. }
  229. break;
  230. case L('a','r'): // Arabic
  231. tr->letter_bits_offset = OFFSET_ARABIC;
  232. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  233. break;
  234. case L('b','n'): // Bengali
  235. {
  236. static const short stress_lengths_bn[8] = {180, 180, 210, 210, 0, 0, 230, 240};
  237. static const unsigned char stress_amps_bn[8] = {18,18, 18,18, 20,20, 22,22 };
  238. SetupTranslator(tr,stress_lengths_bn,stress_amps_bn);
  239. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  240. tr->langopts.stress_rule = STRESSPOSN_1L;
  241. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  242. tr->letter_bits_offset = OFFSET_BENGALI;
  243. SetIndicLetters(tr); // call this after setting OFFSET_BENGALI
  244. SetLetterBitsRange(tr,LETTERGP_F,0x3e,0x4c); // vowel signs, but not virama
  245. tr->langopts.numbers = 0x1;
  246. tr->langopts.break_numbers = 0x24924aa8; // for languages which have numbers for 100,000 and 100,00,000, eg Hindi
  247. }
  248. break;
  249. case L('c','y'): // Welsh
  250. {
  251. static const short stress_lengths_cy[8] = {170,220, 180,180, 0, 0, 250,270};
  252. static const unsigned char stress_amps_cy[8] = {17,15, 18,18, 0,0, 22,20 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  253. SetupTranslator(tr,stress_lengths_cy,stress_amps_cy);
  254. tr->charset_a0 = charsets[14]; // ISO-8859-14
  255. // tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  256. tr->langopts.stress_rule = STRESSPOSN_2R;
  257. // tr->langopts.intonation_group = 4;
  258. // 'diminished' is an unstressed final syllable
  259. tr->langopts.stress_flags = 0x6 | 0x10;
  260. tr->langopts.unstressed_wd1 = 0;
  261. tr->langopts.unstressed_wd2 = 2;
  262. tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
  263. tr->langopts.numbers = NUM_OMIT_1_HUNDRED;
  264. SetLetterVowel(tr,'w'); // add letter to vowels and remove from consonants
  265. SetLetterVowel(tr,'y');
  266. }
  267. break;
  268. case L('d','a'): // Danish
  269. {
  270. static const short stress_lengths_da[8] = {160,140, 200,200, 0,0, 220,210};
  271. SetupTranslator(tr,stress_lengths_da,NULL);
  272. tr->langopts.stress_rule = STRESSPOSN_1L;
  273. SetLetterVowel(tr,'y');
  274. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_HUNDRED_AND | NUM_OMIT_1_HUNDRED | NUM_ORDINAL_DOT | NUM_1900;
  275. }
  276. break;
  277. case L('d','e'):
  278. {
  279. static const short stress_lengths_de[8] = {150,130, 200,200, 0, 0, 260,275};
  280. tr->langopts.stress_rule = STRESSPOSN_1L;
  281. tr->langopts.word_gap = 0x8; // don't use linking phonemes
  282. tr->langopts.vowel_pause = 0x30;
  283. tr->langopts.param[LOPT_PREFIXES] = 1;
  284. memcpy(tr->stress_lengths,stress_lengths_de,sizeof(tr->stress_lengths));
  285. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_OMIT_1_HUNDRED | NUM_ALLOW_SPACE | NUM_ORDINAL_DOT | NUM_ROMAN;
  286. SetLetterVowel(tr,'y');
  287. }
  288. break;
  289. case L('e','n'):
  290. {
  291. static const short stress_lengths_en[8] = {182,140, 220,220, 0,0, 248,275};
  292. SetupTranslator(tr,stress_lengths_en,NULL);
  293. tr->langopts.stress_rule = STRESSPOSN_1L;
  294. tr->langopts.numbers = NUM_HUNDRED_AND | NUM_ROMAN | NUM_1900;
  295. tr->langopts.param[LOPT_COMBINE_WORDS] = 2; // allow "mc" to cmbine with the following word
  296. tr->langopts.suffix_add_e = 'e';
  297. }
  298. break;
  299. case L('e','l'): // Greek
  300. case L_grc: // Ancient Greek
  301. {
  302. static const short stress_lengths_el[8] = {155, 180, 210, 210, 0, 0, 270, 300};
  303. static const unsigned char stress_amps_el[8] = {15,12, 20,20, 20,22, 22,21 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  304. // character codes offset by 0x380
  305. static const char el_vowels[] = {0x10,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x35,0x37,0x39,0x3f,0x45,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0};
  306. static const char el_fvowels[] = {0x2d,0x2e,0x2f,0x35,0x37,0x39,0x45,0x4d,0}; // ε η ι υ έ ή ί ύ
  307. static const char el_voiceless[]= {0x38,0x3a,0x3e,0x40,0x42,0x43,0x44,0x46,0x47,0}; // θ κ ξ π ς σ τ φ χ
  308. static const char el_consonants[]={0x32,0x33,0x34,0x36,0x38,0x3a,0x3b,0x3c,0x3d,0x3e,0x40,0x41,0x42,0x43,0x44,0x46,0x47,0x48,0};
  309. static const wchar_t el_char_apostrophe[] = {0x3c3,0}; // σ
  310. SetupTranslator(tr,stress_lengths_el,stress_amps_el);
  311. tr->charset_a0 = charsets[7]; // ISO-8859-7
  312. tr->char_plus_apostrophe = el_char_apostrophe;
  313. tr->letter_bits_offset = OFFSET_GREEK;
  314. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  315. SetLetterBits(tr,LETTERGP_A,el_vowels);
  316. SetLetterBits(tr,LETTERGP_B,el_voiceless);
  317. SetLetterBits(tr,LETTERGP_C,el_consonants);
  318. SetLetterBits(tr,LETTERGP_Y,el_fvowels); // front vowels: ε η ι υ
  319. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  320. tr->langopts.stress_rule = STRESSPOSN_2R;
  321. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  322. tr->langopts.unstressed_wd1 = 0;
  323. tr->langopts.unstressed_wd2 = 2;
  324. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  325. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA;
  326. tr->langopts.numbers2 = 0x2; // variant form of numbers before thousands
  327. if(name2 == L_grc)
  328. {
  329. // ancient greek
  330. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1;
  331. }
  332. }
  333. break;
  334. case L('e','o'):
  335. {
  336. static const short stress_lengths_eo[8] = {145, 145, 230, 170, 0, 0, 360, 370};
  337. static const unsigned char stress_amps_eo[] = {16,14, 20,20, 20,22, 22,21 };
  338. static const wchar_t eo_char_apostrophe[2] = {'l',0};
  339. SetupTranslator(tr,stress_lengths_eo,stress_amps_eo);
  340. tr->charset_a0 = charsets[3]; // ISO-8859-3
  341. tr->char_plus_apostrophe = eo_char_apostrophe;
  342. tr->langopts.word_gap = 1;
  343. tr->langopts.vowel_pause = 2;
  344. tr->langopts.stress_rule = STRESSPOSN_2R;
  345. tr->langopts.stress_flags = 0x6 | 0x10;
  346. tr->langopts.unstressed_wd1 = 3;
  347. tr->langopts.unstressed_wd2 = 2;
  348. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_OMIT_1_HUNDRED | NUM_ALLOW_SPACE | NUM_ROMAN;
  349. }
  350. break;
  351. case L('e','s'): // Spanish
  352. case L('c','a'): // Catalan
  353. case L_pap: // Papiamento
  354. {
  355. static const short stress_lengths_es[8] = {180, 210, 190, 190, 0, 0, 230, 260};
  356. // static const short stress_lengths_es[8] = {170, 200, 180, 180, 0, 0, 220, 250};
  357. static const unsigned char stress_amps_es[8] = {16,12, 18,18, 20,20, 20,20 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  358. static const wchar_t ca_punct_within_word[] = {'\'',0xb7,0}; // ca: allow middle-dot within word
  359. SetupTranslator(tr,stress_lengths_es,stress_amps_es);
  360. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  361. tr->langopts.stress_rule = STRESSPOSN_2R;
  362. // stress last syllable if it doesn't end in vowel or "s" or "n"
  363. // 'diminished' is an unstressed final syllable
  364. tr->langopts.stress_flags = 0x200 | 0x6 | 0x10;
  365. tr->langopts.unstressed_wd1 = 0;
  366. tr->langopts.unstressed_wd2 = 2;
  367. tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
  368. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_ROMAN | NUM_ROMAN_AFTER;
  369. if(name2 == L('c','a'))
  370. {
  371. tr->punct_within_word = ca_punct_within_word;
  372. tr->langopts.stress_flags = 0x200 | 0x6 | 0x30; // stress last syllable unless word ends with a vowel
  373. }
  374. else
  375. if(name2 == L_pap)
  376. {
  377. tr->langopts.stress_flags = 0x100 | 0x6 | 0x30; // stress last syllable unless word ends with a vowel
  378. }
  379. }
  380. break;
  381. case L('e','u'): // basque
  382. {
  383. static const short stress_lengths_eu[8] = {200, 200, 200, 200, 0, 0, 210, 230}; // very weak stress
  384. static const unsigned char stress_amps_eu[8] = {16,16, 18,18, 18,18, 18,18 };
  385. SetupTranslator(tr,stress_lengths_eu,stress_amps_eu);
  386. tr->langopts.stress_rule = STRESSPOSN_2L; // ?? second syllable ??
  387. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_HUNDRED_AND | NUM_OMIT_1_HUNDRED | NUM_VIGESIMAL;
  388. }
  389. break;
  390. case L('f','a'): // Farsi
  391. {
  392. tr->letter_bits_offset = OFFSET_ARABIC;
  393. tr->langopts.numbers = NUM_AND_UNITS | NUM_HUNDRED_AND;
  394. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  395. }
  396. break;
  397. case L('f','i'): // Finnish
  398. {
  399. static const unsigned char stress_amps_fi[8] = {18,16, 22,22, 20,22, 22,22 };
  400. static const short stress_lengths_fi[8] = {150,180, 200,200, 0,0, 210,250};
  401. SetupTranslator(tr,stress_lengths_fi,stress_amps_fi);
  402. tr->langopts.stress_rule = STRESSPOSN_1L;
  403. tr->langopts.stress_flags = 0x56; // move secondary stress from light to a following heavy syllable
  404. tr->langopts.param[LOPT_IT_DOUBLING] = 1;
  405. tr->langopts.long_stop = 130;
  406. tr->langopts.param[LOPT_MIN_LONG_VOWEL] = 65;
  407. tr->langopts.numbers = NUM_DECIMAL_COMMA + NUM_ALLOW_SPACE;
  408. SetLetterVowel(tr,'y');
  409. // tr->langopts.max_initial_consonants = 2; // BUT foreign words may have 3
  410. tr->langopts.spelling_stress = 1;
  411. tr->langopts.intonation_group = 3; // less intonation, don't raise pitch at comma
  412. }
  413. break;
  414. case L('f','r'): // french
  415. {
  416. static const short stress_lengths_fr[8] = {190, 170, 190, 200, 0, 0, 235, 240};
  417. static const unsigned char stress_amps_fr[8] = {18,16, 20,20, 20,22, 22,21 };
  418. SetupTranslator(tr,stress_lengths_fr,stress_amps_fr);
  419. tr->langopts.stress_rule = STRESSPOSN_1R; // stress on final syllable
  420. tr->langopts.stress_flags = 0x0024; // don't use secondary stress
  421. tr->langopts.param[LOPT_IT_LENGTHEN] = 1; // remove lengthen indicator from unstressed syllables
  422. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_OMIT_1_HUNDRED | NUM_NOPAUSE | NUM_ROMAN | NUM_VIGESIMAL | NUM_DFRACTION_4;
  423. SetLetterVowel(tr,'y');
  424. }
  425. break;
  426. case L('h','i'): // Hindi
  427. case L('n','e'): // Nepali
  428. case L('p','a'): // Punjabi
  429. {
  430. static const short stress_lengths_hi[8] = {190, 190, 210, 210, 0, 0, 230, 250};
  431. static const unsigned char stress_amps_hi[8] = {17,14, 20,19, 20,22, 22,21 };
  432. SetupTranslator(tr,stress_lengths_hi,stress_amps_hi);
  433. tr->charset_a0 = charsets[19]; // ISCII
  434. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  435. tr->langopts.stress_rule = 6; // stress on last heaviest syllable, excluding final syllable
  436. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  437. tr->langopts.numbers = NUM_SWAP_TENS;
  438. tr->langopts.break_numbers = 0x14aa8; // for languages which have numbers for 100,000 and 100,00,000, eg Hindi
  439. tr->letter_bits_offset = OFFSET_DEVANAGARI;
  440. if(name2 == L('p','a'))
  441. {
  442. tr->letter_bits_offset = OFFSET_GURMUKHI;
  443. }
  444. SetIndicLetters(tr);
  445. }
  446. break;
  447. case L('h','r'): // Croatian
  448. case L('b','s'): // Bosnian
  449. case L('s','r'): // Serbian
  450. {
  451. static const unsigned char stress_amps_hr[8] = {17,17, 20,20, 20,22, 22,21 };
  452. static const short stress_lengths_hr[8] = {180,160, 200,200, 0,0, 220,230};
  453. static const short stress_lengths_sr[8] = {160,150, 200,200, 0,0, 250,260};
  454. if(name2 == L('s','r'))
  455. SetupTranslator(tr,stress_lengths_sr,stress_amps_hr);
  456. else
  457. SetupTranslator(tr,stress_lengths_hr,stress_amps_hr);
  458. tr->charset_a0 = charsets[2]; // ISO-8859-2
  459. tr->langopts.stress_rule = STRESSPOSN_1L;
  460. tr->langopts.stress_flags = 0x10;
  461. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  462. tr->langopts.max_initial_consonants = 5;
  463. tr->langopts.spelling_stress = 1;
  464. tr->langopts.accents = 1;
  465. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_HUNDRED_AND | NUM_OMIT_1_HUNDRED | NUM_DECIMAL_COMMA | NUM_THOUS_SPACE | NUM_DFRACTION_2 | NUM_ROMAN_UC;
  466. tr->langopts.numbers2 = 0x4a; // variant numbers before thousands,milliards
  467. tr->langopts.replace_chars = replace_cyrillic_latin;
  468. SetLetterVowel(tr,'y');
  469. SetLetterVowel(tr,'r');
  470. }
  471. break;
  472. case L('h','u'): // Hungarian
  473. {
  474. static const unsigned char stress_amps_hu[8] = {17,17, 19,19, 20,22, 22,21 };
  475. static const short stress_lengths_hu[8] = {185,195, 195,190, 0,0, 210,220};
  476. SetupTranslator(tr,stress_lengths_hu,stress_amps_hu);
  477. tr->charset_a0 = charsets[2]; // ISO-8859-2
  478. tr->langopts.vowel_pause = 0x20;
  479. tr->langopts.stress_rule = STRESSPOSN_1L;
  480. tr->langopts.stress_flags = 0x8036 | S_HYPEN_UNSTRESS;
  481. tr->langopts.unstressed_wd1 = 2;
  482. tr->langopts.param[LOPT_IT_DOUBLING] = 1;
  483. tr->langopts.param[LOPT_ANNOUNCE_PUNCT] = 2; // don't break clause before announcing . ? !
  484. tr->langopts.param[LOPT_MIN_LONG_VOWEL] = 65;
  485. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_DFRACTION_5 | NUM_ROMAN | NUM_ROMAN_ORDINAL | NUM_ROMAN_CAPITALS | NUM_ORDINAL_DOT | NUM_OMIT_1_HUNDRED;
  486. tr->langopts.min_roman = 1;
  487. SetLetterVowel(tr,'y');
  488. tr->langopts.spelling_stress = 1;
  489. SetLengthMods(tr,3); // all equal
  490. }
  491. break;
  492. case L('h','y'): // Armenian
  493. {
  494. static const short stress_lengths_hy[8] = {250, 200, 250, 250, 0, 0, 250, 250};
  495. static const char hy_vowels[] = {0x31, 0x35, 0x37, 0x38, 0x3b, 0x48, 0x55, 0};
  496. static const char hy_consonants[] = {0x32,0x33,0x34,0x36,0x39,0x3a,0x3c,0x3d,0x3e,0x3f,
  497. 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x56,0};
  498. SetupTranslator(tr,stress_lengths_hy,NULL);
  499. tr->langopts.stress_rule = STRESSPOSN_1R; // default stress on final syllable
  500. tr->letter_bits_offset = OFFSET_ARMENIAN;
  501. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  502. SetLetterBits(tr,LETTERGP_A,hy_vowels);
  503. SetLetterBits(tr,LETTERGP_C,hy_consonants);
  504. tr->langopts.max_initial_consonants = 6;
  505. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_OMIT_1_HUNDRED;
  506. // tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  507. }
  508. break;
  509. case L('i','d'): // Indonesian
  510. {
  511. static const short stress_lengths_id[8] = {160, 200, 180, 180, 0, 0, 220, 240};
  512. static const unsigned char stress_amps_id[8] = {16,18, 18,18, 20,22, 22,21 };
  513. SetupTranslator(tr,stress_lengths_id,stress_amps_id);
  514. tr->langopts.stress_rule = STRESSPOSN_2R;
  515. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_ROMAN;
  516. tr->langopts.stress_flags = 0x6 | 0x10;
  517. tr->langopts.accents = 2; // "capital" after letter name
  518. }
  519. break;
  520. case L('i','s'): // Icelandic
  521. {
  522. static const short stress_lengths_is[8] = {180,160, 200,200, 0,0, 240,250};
  523. static const wchar_t is_lettergroup_B[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
  524. SetupTranslator(tr,stress_lengths_is,NULL);
  525. tr->langopts.stress_rule = STRESSPOSN_1L;
  526. tr->langopts.stress_flags = 0x10;
  527. tr->langopts.param[LOPT_IT_LENGTHEN] = 0x11; // remove lengthen indicator from unstressed vowels
  528. tr->langopts.param[LOPT_REDUCE] = 2;
  529. ResetLetterBits(tr,0x18);
  530. SetLetterBits(tr,4,"kpst"); // Letter group F
  531. SetLetterBits(tr,3,"jvr"); // Letter group H
  532. tr->letter_groups[1] = is_lettergroup_B;
  533. SetLetterVowel(tr,'y');
  534. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SINGLE_AND | NUM_HUNDRED_AND | NUM_AND_UNITS | NUM_1900;
  535. tr->langopts.numbers2 = 0x2;
  536. }
  537. break;
  538. case L('i','t'): // Italian
  539. {
  540. static const short stress_lengths_it[8] = {150, 140, 170, 170, 0, 0, 300, 330};
  541. static const unsigned char stress_amps_it[8] = {15,14, 19,19, 20,22, 22,20 };
  542. SetupTranslator(tr,stress_lengths_it,stress_amps_it);
  543. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  544. tr->langopts.stress_rule = STRESSPOSN_2R;
  545. tr->langopts.stress_flags = 0x10 | 0x20000;
  546. tr->langopts.vowel_pause = 1;
  547. tr->langopts.unstressed_wd1 = 2;
  548. tr->langopts.unstressed_wd2 = 2;
  549. tr->langopts.param[LOPT_IT_LENGTHEN] = 2; // remove lengthen indicator from unstressed or non-penultimate syllables
  550. tr->langopts.param[LOPT_IT_DOUBLING] = 2; // double the first consonant if the previous word ends in a stressed vowel
  551. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  552. tr->langopts.param[LOPT_REDUCE] = 1; // reduce vowels even if phonemes are specified in it_list
  553. tr->langopts.param[LOPT_ALT] = 2; // call ApplySpecialAttributes2() if a word has $alt or $alt2
  554. tr->langopts.numbers = NUM_SINGLE_VOWEL | NUM_OMIT_1_HUNDRED |NUM_DECIMAL_COMMA | NUM_ROMAN | NUM_DFRACTION_1;
  555. tr->langopts.accents = 2; // Say "Capital" after the letter.
  556. SetLetterVowel(tr,'y');
  557. }
  558. break;
  559. case L_jbo: // Lojban
  560. {
  561. static const short stress_lengths_jbo[8] = {145,145, 170,160, 0,0, 330,350};
  562. static const wchar_t jbo_punct_within_word[] = {'.',',','\'',0x2c8,0}; // allow period and comma within a word, also stress marker (from LOPT_CAPS_IN_WORD)
  563. SetupTranslator(tr,stress_lengths_jbo,NULL);
  564. tr->langopts.stress_rule = STRESSPOSN_2R;
  565. tr->langopts.vowel_pause = 0x20c; // pause before a word which starts with a vowel, or after a word which ends in a consonant
  566. // tr->langopts.word_gap = 1;
  567. tr->punct_within_word = jbo_punct_within_word;
  568. tr->langopts.param[LOPT_CAPS_IN_WORD] = 2; // capitals indicate stressed syllables
  569. SetLetterVowel(tr,'y');
  570. tr->langopts.max_lengthmod = 368;
  571. }
  572. break;
  573. case L('k','o'): // Korean, TEST
  574. {
  575. static const char ko_ivowels[] = {0x63,0x64,0x67,0x68,0x6d,0x72,0x74,0x75,0}; // y and i vowels
  576. static const unsigned char ko_voiced[] = {0x02,0x05,0x06,0xab,0xaf,0xb7,0xbc,0}; // voiced consonants, l,m,n,N
  577. tr->letter_bits_offset = OFFSET_KOREAN;
  578. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  579. SetLetterBitsRange(tr,LETTERGP_A,0x61,0x75);
  580. SetLetterBits(tr,LETTERGP_Y,ko_ivowels);
  581. SetLetterBits(tr,LETTERGP_G,(const char *)ko_voiced);
  582. tr->langopts.stress_rule = 8; // ?? 1st syllable if it is heavy, else 2nd syllable
  583. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  584. tr->langopts.numbers = NUM_OMIT_1_HUNDRED;
  585. }
  586. break;
  587. case L('k','u'): // Kurdish
  588. {
  589. static const unsigned char stress_amps_ku[8] = {18,18, 20,20, 20,22, 22,21 };
  590. static const short stress_lengths_ku[8] = {180,180, 190,180, 0,0, 230,240};
  591. SetupTranslator(tr,stress_lengths_ku,stress_amps_ku);
  592. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  593. tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
  594. tr->langopts.numbers = NUM_HUNDRED_AND | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_AND_HUNDRED;
  595. tr->langopts.max_initial_consonants = 2;
  596. }
  597. break;
  598. case L('l','a'): //Latin
  599. {
  600. tr->charset_a0 = charsets[4]; // ISO-8859-4, includes a,e,i,o,u-macron
  601. tr->langopts.stress_rule = STRESSPOSN_2R;
  602. tr->langopts.stress_flags = 0x20;
  603. tr->langopts.unstressed_wd1 = 0;
  604. tr->langopts.unstressed_wd2 = 2;
  605. tr->langopts.param[LOPT_DIERESES] = 1;
  606. tr->langopts.numbers = NUM_ROMAN;
  607. tr->langopts.max_roman = 5000;
  608. }
  609. break;
  610. case L('l','v'): // latvian
  611. {
  612. static const unsigned char stress_amps_lv[8] = {17,13, 20,20, 20,22, 22,21 };
  613. static const short stress_lengths_lv[8] = {180,130, 210,210, 0,0, 210,210};
  614. SetupTranslator(tr,stress_lengths_lv,stress_amps_lv);
  615. tr->langopts.stress_rule = STRESSPOSN_1L;
  616. tr->langopts.spelling_stress = 1;
  617. tr->charset_a0 = charsets[4]; // ISO-8859-4
  618. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_OMIT_1_HUNDRED | NUM_DFRACTION_4 | NUM_ORDINAL_DOT;
  619. tr->langopts.stress_flags = 0x16 + 0x40000;
  620. }
  621. break;
  622. case L('m','k'): // Macedonian
  623. {
  624. static wchar_t vowels_cyrillic[] = {0x440, // also include 'р' [R]
  625. 0x430,0x435,0x438,0x439,0x43e,0x443,0x44b,0x44d,0x44e,0x44f,0x450,0x451,0x456,0x457,0x45d,0x45e,0};
  626. static const unsigned char stress_amps_mk[8] = {17,17, 20,20, 20,22, 22,21 };
  627. static const short stress_lengths_mk[8] = {180,160, 200,200, 0,0, 220,230};
  628. SetupTranslator(tr,stress_lengths_mk,stress_amps_mk);
  629. tr->charset_a0 = charsets[5]; // ISO-8859-5
  630. tr->letter_groups[0] = vowels_cyrillic;
  631. tr->langopts.stress_rule = STRESSPOSN_3R; // antipenultimate
  632. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_AND_UNITS | NUM_OMIT_1_HUNDRED | NUM_DFRACTION_2;
  633. tr->langopts.numbers2 = 0x8a; // variant numbers before thousands,milliards
  634. }
  635. break;
  636. case L('n','l'): // Dutch
  637. {
  638. static const short stress_lengths_nl[8] = {160,135, 210,210, 0, 0, 260,280};
  639. tr->langopts.stress_rule = STRESSPOSN_1L;
  640. tr->langopts.vowel_pause = 1;
  641. tr->langopts.param[LOPT_DIERESES] = 1;
  642. tr->langopts.param[LOPT_PREFIXES] = 1;
  643. SetLetterVowel(tr,'y');
  644. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_SWAP_TENS | NUM_OMIT_1_HUNDRED | NUM_ALLOW_SPACE | NUM_1900 | NUM_ORDINAL_DOT;
  645. memcpy(tr->stress_lengths,stress_lengths_nl,sizeof(tr->stress_lengths));
  646. }
  647. break;
  648. case L('n','o'): // Norwegian
  649. {
  650. static const short stress_lengths_no[8] = {160,140, 200,200, 0,0, 220,230};
  651. SetupTranslator(tr,stress_lengths_no,NULL);
  652. tr->langopts.stress_rule = STRESSPOSN_1L;
  653. SetLetterVowel(tr,'y');
  654. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_HUNDRED_AND | NUM_ALLOW_SPACE | NUM_1900 | NUM_ORDINAL_DOT;
  655. }
  656. break;
  657. case L('o','m'):
  658. {
  659. static const unsigned char stress_amps_om[] = {18,15, 20,20, 20,22, 22,22 };
  660. static const short stress_lengths_om[8] = {200,200, 200,200, 0,0, 200,200};
  661. SetupTranslator(tr,stress_lengths_om,stress_amps_om);
  662. tr->langopts.stress_rule = STRESSPOSN_2R;
  663. tr->langopts.stress_flags = 0x16 + 0x80000;
  664. }
  665. break;
  666. case L('p','l'): // Polish
  667. {
  668. static const short stress_lengths_pl[8] = {160, 190, 175, 175, 0, 0, 200, 210};
  669. static const unsigned char stress_amps_pl[8] = {17,13, 19,19, 20,22, 22,21 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  670. SetupTranslator(tr,stress_lengths_pl,stress_amps_pl);
  671. tr->charset_a0 = charsets[2]; // ISO-8859-2
  672. tr->langopts.stress_rule = STRESSPOSN_2R;
  673. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  674. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x8;
  675. tr->langopts.max_initial_consonants = 7; // for example: wchrzczony :)
  676. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_DFRACTION_2;
  677. tr->langopts.numbers2 = 0x40;
  678. tr->langopts.param[LOPT_COMBINE_WORDS] = 4 + 0x100; // combine 'nie' (marked with $alt2) with some 1-syllable (and 2-syllable) words (marked with $alt)
  679. SetLetterVowel(tr,'y');
  680. }
  681. break;
  682. case L('p','t'): // Portuguese
  683. {
  684. static const short stress_lengths_pt[8] = {170, 115, 210, 240, 0, 0, 260, 280};
  685. static const unsigned char stress_amps_pt[8] = {16,11, 19,21, 20,22, 22,21 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  686. SetupTranslator(tr,stress_lengths_pt,stress_amps_pt);
  687. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  688. tr->langopts.stress_rule = STRESSPOSN_1R; // stress on final syllable
  689. tr->langopts.stress_flags = 0x6 | 0x10 | 0x2000 | 0x20000;
  690. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_DFRACTION_2 | NUM_HUNDRED_AND | NUM_AND_UNITS | NUM_ROMAN;
  691. SetLetterVowel(tr,'y');
  692. ResetLetterBits(tr,0x2);
  693. SetLetterBits(tr,1,"bcdfgjkmnpqstvxz"); // B hard consonants, excluding h,l,r,w,y
  694. tr->langopts.param[LOPT_ALT] = 2; // call ApplySpecialAttributes2() if a word has $alt or $alt2
  695. }
  696. break;
  697. case L('r','o'): // Romanian
  698. {
  699. static const short stress_lengths_ro[8] = {170, 170, 180, 180, 0, 0, 240, 260};
  700. static const unsigned char stress_amps_ro[8] = {15,13, 18,18, 20,22, 22,21 };
  701. SetupTranslator(tr,stress_lengths_ro,stress_amps_ro);
  702. tr->langopts.stress_rule = STRESSPOSN_2R;
  703. tr->langopts.stress_flags = 0x100 + 0x6;
  704. tr->charset_a0 = charsets[2]; // ISO-8859-2
  705. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_DFRACTION_3 | NUM_AND_UNITS | NUM_ROMAN;
  706. tr->langopts.numbers2 = 0x1e; // variant numbers before all thousandplex
  707. }
  708. break;
  709. case L('r','u'): // Russian
  710. Translator_Russian(tr);
  711. break;
  712. case L('r','w'): // Kiryarwanda
  713. {
  714. tr->langopts.stress_rule = STRESSPOSN_2R;
  715. tr->langopts.stress_flags = 0x16;
  716. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  717. tr->langopts.numbers = NUM_HUNDRED_AND | NUM_AND_UNITS | NUM_DFRACTION_2 | NUM_AND_HUNDRED;
  718. tr->langopts.numbers2 = 0x200; // say "thousands" before its number
  719. }
  720. break;
  721. case L('s','k'): // Slovak
  722. case L('c','s'): // Czech
  723. {
  724. static const char *sk_voiced = "bdgjlmnrvwzaeiouy";
  725. SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
  726. tr->charset_a0 = charsets[2]; // ISO-8859-2
  727. tr->langopts.stress_rule = STRESSPOSN_1L;
  728. tr->langopts.stress_flags = 0x16;
  729. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  730. tr->langopts.max_initial_consonants = 5;
  731. tr->langopts.spelling_stress = 1;
  732. tr->langopts.param[LOPT_COMBINE_WORDS] = 4; // combine some prepositions with the following word
  733. tr->langopts.numbers = NUM_OMIT_1_HUNDRED | NUM_DFRACTION_2 | NUM_ROMAN;
  734. tr->langopts.numbers2 = 0x100;
  735. tr->langopts.thousands_sep = STRESSPOSN_1L; //no thousands separator
  736. tr->langopts.decimal_sep = ',';
  737. if(name2 == L('c','s'))
  738. {
  739. tr->langopts.numbers2 = 0x108; // variant numbers before milliards
  740. }
  741. SetLetterVowel(tr,'y');
  742. SetLetterVowel(tr,'r');
  743. ResetLetterBits(tr,0x20);
  744. SetLetterBits(tr,5,sk_voiced);
  745. }
  746. break;
  747. case L('s','q'): // Albanian
  748. {
  749. static const short stress_lengths_sq[8] = {150, 150, 180, 180, 0, 0, 300, 300};
  750. static const unsigned char stress_amps_sq[8] = {16,12, 16,16, 20,20, 21,19 };
  751. SetupTranslator(tr,stress_lengths_sq,stress_amps_sq);
  752. tr->langopts.stress_rule = STRESSPOSN_2R;
  753. tr->langopts.stress_flags = 0x16 + 0x100;
  754. SetLetterVowel(tr,'y');
  755. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_HUNDRED_AND | NUM_AND_UNITS | NUM_DFRACTION_4;
  756. tr->langopts.accents = 2; // "capital" after letter name
  757. }
  758. break;
  759. case L('s','v'): // Swedish
  760. {
  761. static const unsigned char stress_amps_sv[] = {16,16, 20,20, 20,22, 22,21 };
  762. static const short stress_lengths_sv[8] = {160,135, 220,220, 0,0, 250,280};
  763. SetupTranslator(tr,stress_lengths_sv,stress_amps_sv);
  764. tr->langopts.stress_rule = STRESSPOSN_1L;
  765. SetLetterVowel(tr,'y');
  766. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_1900;
  767. tr->langopts.accents = 1;
  768. }
  769. break;
  770. case L('s','w'): // Swahili
  771. {
  772. static const short stress_lengths_sw[8] = {160, 170, 200, 200, 0, 0, 320, 340};
  773. static const unsigned char stress_amps_sw[] = {16,12, 19,19, 20,22, 22,21 };
  774. SetupTranslator(tr,stress_lengths_sw,stress_amps_sw);
  775. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  776. tr->langopts.vowel_pause = 1;
  777. tr->langopts.stress_rule = STRESSPOSN_2R;
  778. tr->langopts.stress_flags = 0x6 | 0x10;
  779. tr->langopts.numbers = NUM_AND_UNITS | NUM_HUNDRED_AND | NUM_SINGLE_AND | NUM_OMIT_1_HUNDRED;
  780. tr->langopts.break_numbers = 0x49249268; // for languages which have numbers for 100,000 and 1,000,000
  781. }
  782. break;
  783. case L('t','a'): // Tamil
  784. case L('m','l'): // Malayalam
  785. case L('k','n'): // Kannada
  786. case L('m','r'): // Marathi
  787. {
  788. static const short stress_lengths_ta[8] = {200, 200, 210, 210, 0, 0, 230, 230};
  789. static const unsigned char stress_amps_ta[8] = {18,18, 18,18, 20,20, 22,22 };
  790. SetupTranslator(tr,stress_lengths_ta,stress_amps_ta);
  791. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  792. tr->langopts.stress_rule = STRESSPOSN_1L;
  793. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  794. tr->langopts.break_numbers = 0x14a8; // 1000, 100,000 10,000,000
  795. if(name2 == L('t','a'))
  796. {
  797. tr->letter_bits_offset = OFFSET_TAMIL;
  798. tr->langopts.numbers = 0x1;
  799. }
  800. if(name2 == L('m','r'))
  801. {
  802. tr->letter_bits_offset = OFFSET_DEVANAGARI;
  803. }
  804. else
  805. if(name2 == L('m','l'))
  806. {
  807. tr->letter_bits_offset = OFFSET_MALAYALAM;
  808. }
  809. else
  810. if(name2 == L('k','n'))
  811. {
  812. tr->letter_bits_offset = OFFSET_KANNADA;
  813. tr->langopts.numbers = 0x1;
  814. }
  815. tr->langopts.param[LOPT_WORD_MERGE] = 1; // don't break vowels betwen words
  816. SetIndicLetters(tr); // call this after setting OFFSET_
  817. }
  818. break;
  819. #ifdef deleted
  820. case L('t','h'): // Thai
  821. {
  822. static const short stress_lengths_th[8] = {230,150, 230,230, 230,0, 230,250};
  823. static const unsigned char stress_amps_th[] = {22,16, 22,22, 22,22, 22,22 };
  824. SetupTranslator(tr,stress_lengths_th,stress_amps_th);
  825. tr->langopts.stress_rule = 0; // stress on final syllable of a "word"
  826. tr->langopts.stress_flags = 2; // don't automatically set diminished stress (may be set in the intonation module)
  827. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  828. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  829. // tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  830. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  831. }
  832. break;
  833. #endif
  834. case L('t','r'): // Turkish
  835. {
  836. static const unsigned char stress_amps_tr[8] = {18,18, 20,20, 20,22, 22,21 };
  837. static const short stress_lengths_tr[8] = {190,190, 190,190, 0,0, 250,270};
  838. SetupTranslator(tr,stress_lengths_tr,stress_amps_tr);
  839. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  840. tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
  841. tr->langopts.stress_flags = 0x20; //no automatic secondary stress
  842. tr->langopts.numbers = NUM_SINGLE_STRESS | NUM_DECIMAL_COMMA | NUM_ALLOW_SPACE | NUM_OMIT_1_HUNDRED | NUM_DFRACTION_2;
  843. tr->langopts.max_initial_consonants = 2;
  844. }
  845. break;
  846. case L('u','r'): // Urdu
  847. tr->letter_bits_offset = OFFSET_ARABIC;
  848. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  849. tr->langopts.numbers = NUM_SWAP_TENS;
  850. tr->langopts.break_numbers = 0x52a8; // for languages which have numbers for 100,000 and 100,00,000, eg Hindi
  851. break;
  852. case L('v','i'): // Vietnamese
  853. {
  854. static const short stress_lengths_vi[8] = {150, 150, 180, 180, 210, 230, 230, 240};
  855. static const unsigned char stress_amps_vi[] = {16,16, 16,16, 22,22, 22,22 };
  856. static wchar_t vowels_vi[] = {
  857. 0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a
  858. 0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă
  859. 0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â
  860. 0x65, 0xe8, 0xe9, 0x1ebb, 0x1ebd, 0x1eb9, // e
  861. 0xea, 0x1ec1, 0x1ebf, 0x1ec3, 0x1ec5, 0x1ec7, // i
  862. 0x69, 0xec, 0xed, 0x1ec9, 0x129, 0x1ecb, // i
  863. 0x6f, 0xf2, 0xf3, 0x1ecf, 0xf5, 0x1ecd, // o
  864. 0xf4, 0x1ed3, 0x1ed1, 0x1ed5, 0x1ed7, 0x1ed9, // ô
  865. 0x1a1, 0x1edd, 0x1edb, 0x1edf, 0x1ee1, 0x1ee3, // ơ
  866. 0x75, 0xf9, 0xfa, 0x1ee7, 0x169, 0x1ee5, // u
  867. 0x1b0, 0x1eeb, 0x1ee9, 0x1eed, 0x1eef, 0x1ef1, // ư
  868. 0x79, 0x1ef3, 0xfd, 0x1ef7, 0x1ef9, 0x1e, 0 }; // y
  869. SetupTranslator(tr,stress_lengths_vi,stress_amps_vi);
  870. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  871. tr->langopts.stress_rule = STRESSPOSN_1L;
  872. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  873. // tr->langopts.vowel_pause = 4;
  874. tr->letter_groups[0] = vowels_vi;
  875. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  876. tr->langopts.unstressed_wd1 = 2;
  877. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_HUNDRED_AND | NUM_DFRACTION_4;
  878. }
  879. break;
  880. case L('z','h'):
  881. case L_zhy:
  882. {
  883. static const short stress_lengths_zh[8] = {230,150, 230,230, 230,0, 240,250}; // 1=tone5. end-of-sentence, 6=tone 1&4, 7=tone 2&3
  884. static const unsigned char stress_amps_zh[] = {22,16, 22,22, 22,22, 22,22 };
  885. SetupTranslator(tr,stress_lengths_zh,stress_amps_zh);
  886. tr->langopts.stress_rule = STRESSPOSN_1R; // stress on final syllable of a "word"
  887. tr->langopts.stress_flags = 2; // don't automatically set diminished stress (may be set in the intonation module)
  888. tr->langopts.vowel_pause = 0;
  889. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  890. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  891. tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  892. tr->langopts.ideographs = 1;
  893. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  894. if(name2 == L('z','h'))
  895. {
  896. tr->langopts.textmode = 1;
  897. tr->langopts.listx = 1; // compile zh_listx after zh_list
  898. }
  899. }
  900. break;
  901. default:
  902. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  903. break;
  904. }
  905. tr->translator_name = name2;
  906. if(tr->langopts.numbers & NUM_DECIMAL_COMMA)
  907. {
  908. // use . and ; for thousands and decimal separators
  909. tr->langopts.thousands_sep = '.';
  910. tr->langopts.decimal_sep = ',';
  911. }
  912. if(tr->langopts.numbers & NUM_THOUS_SPACE)
  913. {
  914. tr->langopts.thousands_sep = 0; // don't allow thousands separator, except space
  915. }
  916. return(tr);
  917. } // end of SelectTranslator
  918. //**********************************************************************************************************
  919. static void Translator_Russian(Translator *tr)
  920. {//===========================================
  921. static const unsigned char stress_amps_ru[] = {16,16, 18,18, 20,24, 24,22 };
  922. static const short stress_lengths_ru[8] = {150,140, 220,220, 0,0, 260,280};
  923. // character codes offset by 0x420
  924. static const char ru_vowels[] = {0x10,0x15,0x31,0x18,0x1e,0x23,0x2b,0x2d,0x2e,0x2f,0};
  925. static const char ru_consonants[] = {0x11,0x12,0x13,0x14,0x16,0x17,0x19,0x1a,0x1b,0x1c,0x1d,0x1f,0x20,0x21,0x22,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0};
  926. static const char ru_soft[] = {0x2c,0x19,0x27,0x29,0}; // letter group B [k ts; s;]
  927. static const char ru_hard[] = {0x2a,0x16,0x26,0x28,0}; // letter group H [S Z ts]
  928. static const char ru_nothard[] = {0x11,0x12,0x13,0x14,0x17,0x19,0x1a,0x1b,0x1c,0x1d,0x1f,0x20,0x21,0x22,0x24,0x25,0x27,0x29,0x2c,0};
  929. static const char ru_voiced[] = {0x11,0x12,0x13,0x14,0x16,0x17,0}; // letter group G (voiced obstruents)
  930. static const char ru_ivowels[] = {0x2c,0x15,0x31,0x18,0x2e,0x2f,0}; // letter group Y (iotated vowels & soft-sign)
  931. SetupTranslator(tr,stress_lengths_ru,stress_amps_ru);
  932. tr->charset_a0 = charsets[18]; // KOI8-R
  933. tr->transpose_offset = 0x42f; // convert cyrillic from unicode into range 0x01 to 0x22
  934. tr->transpose_min = 0x430;
  935. tr->transpose_max = 0x451;
  936. tr->letter_bits_offset = OFFSET_CYRILLIC;
  937. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  938. SetLetterBits(tr,0,ru_vowels);
  939. SetLetterBits(tr,1,ru_soft);
  940. SetLetterBits(tr,2,ru_consonants);
  941. SetLetterBits(tr,3,ru_hard);
  942. SetLetterBits(tr,4,ru_nothard);
  943. SetLetterBits(tr,5,ru_voiced);
  944. SetLetterBits(tr,6,ru_ivowels);
  945. SetLetterBits(tr,7,ru_vowels);
  946. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 0x432; // [v] don't count this character at start of word
  947. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 1;
  948. tr->langopts.param[LOPT_REDUCE] = 2;
  949. tr->langopts.stress_rule = 5;
  950. tr->langopts.stress_flags = 0x0020; // waas 0x1010
  951. tr->langopts.numbers = NUM_DECIMAL_COMMA | NUM_OMIT_1_HUNDRED;
  952. tr->langopts.numbers2 = 0xc2; // variant numbers before thousands
  953. tr->langopts.phoneme_change = 1;
  954. tr->langopts.testing = 2;
  955. } // end of Translator_Russian
  956. /*
  957. typedef struct {
  958. int flags;
  959. unsigned char stress; // stress level of this vowel
  960. unsigned char stress_highest; // the highest stress level of a vowel in this word
  961. unsigned char n_vowels; // number of vowels in the word
  962. unsigned char vowel_this; // syllable number of this vowel (counting from 1)
  963. unsigned char vowel_stressed; // syllable number of the highest stressed vowel
  964. } CHANGEPH;
  965. */
  966. #ifdef RUSSIAN2
  967. // This is now done in the phoneme data, ph_russian
  968. int ChangePhonemes_ru(Translator *tr, PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  969. {//=============================================================================================================
  970. // Called for each phoneme in the phoneme list, to allow a language to make changes
  971. // ph The current phoneme
  972. int variant;
  973. int vowelix;
  974. PHONEME_TAB *prev, *next;
  975. if(ch->flags & 8)
  976. return(0); // full phoneme translation has already been given
  977. // Russian vowel softening and reduction rules
  978. if(ph->type == phVOWEL)
  979. {
  980. int prestressed = ch->vowel_stressed==ch->vowel_this+1; // the next vowel after this has the main stress
  981. #define N_VOWELS_RU 11
  982. static unsigned int vowels_ru[N_VOWELS_RU] = {'a','V','O','I',PH('I','#'),PH('E','#'),PH('E','2'),
  983. PH('V','#'),PH('I','3'),PH('I','2'),PH('E','3')};
  984. static unsigned int vowel_replace[N_VOWELS_RU][6] = {
  985. // stressed, soft, soft-stressed, j+stressed, j+soft, j+soft-stressed
  986. /*0*/ {'A', 'I', PH('j','a'), 'a', 'a', 'a'}, // a Uses 3,4,5 columns.
  987. /*1*/ {'A', 'V', PH('j','a'), 'a', 'V', 'a'}, // V Uses 3,4,5 columns.
  988. /*2*/ {'o', '8', '8', 'o', '8', '8'}, // O
  989. /*3*/ {'i', 'I', 'i', 'a', 'I', 'a'}, // I Uses 3,4,5 columns.
  990. /*4*/ {'i', PH('I','#'), 'i', 'i', PH('I','#'), 'i'}, // I#
  991. /*5*/ {'E', PH('E','#'), 'E', 'e', PH('E','#'), 'e'}, // E#
  992. /*6*/ {'E', PH('E','2'), 'E', 'e', PH('E','2'), 'e'}, // E2 Uses 3,4,5 columns.
  993. /*7*/ {PH('j','a'), 'V', PH('j','a'), 'A', 'V', 'A'}, // V#
  994. /*8*/ {PH('j','a'), 'I', PH('j','a'), 'e', 'I', 'e'}, // I3 Uses 3,4,5 columns.
  995. /*9*/ {'e', 'I', 'e', 'e', 'I', 'e'}, // I2
  996. /*10*/ {'e', PH('E', '2'), 'e', 'e', PH('E','2'), 'e'} // E3
  997. };
  998. prev = phoneme_tab[phlist[index-1].phcode];
  999. next = phoneme_tab[phlist[index+1].phcode];
  1000. // lookup the vowel name to get an index into the vowel_replace[] table
  1001. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  1002. {
  1003. if(vowels_ru[vowelix] == ph->mnemonic)
  1004. break;
  1005. }
  1006. if(vowelix == N_VOWELS_RU)
  1007. return(0);
  1008. if(prestressed)
  1009. {
  1010. if((vowelix==6)&&(prev->mnemonic=='j'))
  1011. vowelix=8;
  1012. if(vowelix==1)
  1013. vowelix=0;
  1014. if(vowelix==4)
  1015. vowelix=3;
  1016. if(vowelix==6)
  1017. vowelix=5;
  1018. if(vowelix==7)
  1019. vowelix=8;
  1020. if(vowelix==10)
  1021. vowelix=9;
  1022. }
  1023. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  1024. variant = -1;
  1025. int stressed = ch->flags & 2;
  1026. int soft=prev->phflags & phPALATAL;
  1027. if (soft && stressed)
  1028. variant = 2; else
  1029. if (stressed)
  1030. variant = 0; else
  1031. if (soft)
  1032. variant = 1;
  1033. if(variant >= 0)
  1034. {
  1035. if(prev->mnemonic == 'j')
  1036. variant += 3;
  1037. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  1038. }
  1039. else
  1040. {
  1041. phlist[index].phcode = PhonemeCode(vowels_ru[vowelix]);
  1042. }
  1043. }
  1044. return(0);
  1045. }
  1046. #endif