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 43KB

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