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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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,22, 22,21 };
  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,22, 22,21 }; // '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,22, 22,21 };
  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,22, 22,21 };
  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,22, 22,21 };
  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,22, 22,21 };
  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. tr->langopts.numbers = 0x409;
  384. }
  385. break;
  386. case L('i','d'): // Indonesian
  387. {
  388. static const short stress_lengths_id[8] = {160, 200, 180, 180, 0, 0, 220, 240};
  389. static const unsigned char stress_amps_id[8] = {16,18, 18,18, 20,22, 22,21 };
  390. tr = new Translator();
  391. SetupTranslator(tr,stress_lengths_id,stress_amps_id);
  392. tr->langopts.stress_rule = 2;
  393. tr->langopts.numbers = 0x1009 + NUM_ROMAN;
  394. tr->langopts.stress_flags = 0x6 | 0x10;
  395. tr->langopts.accents = 2; // "capital" after letter name
  396. }
  397. break;
  398. case L('i','s'): // Icelandic
  399. {
  400. static const short stress_lengths_is[8] = {180,160, 200,200, 0,0, 240,250};
  401. static const wchar_t is_lettergroup_B[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
  402. tr = new Translator();
  403. SetupTranslator(tr,stress_lengths_is,NULL);
  404. tr->langopts.stress_rule = 0;
  405. tr->langopts.stress_flags = 0x10;
  406. tr->langopts.param[LOPT_IT_LENGTHEN] = 0x11; // remove lengthen indicator from unstressed vowels
  407. tr->langopts.param[LOPT_REDUCE] = 2;
  408. ResetLetterBits(tr,0x18);
  409. SetLetterBits(tr,4,"kpst"); // Letter group F
  410. SetLetterBits(tr,3,"jvr"); // Letter group H
  411. tr->letter_groups[1] = is_lettergroup_B;
  412. SetLetterVowel(tr,'y');
  413. tr->langopts.numbers = 0x8e9;
  414. tr->langopts.numbers2 = 0x2;
  415. }
  416. break;
  417. case L('i','t'): // Italian
  418. {
  419. static const short stress_lengths_it[8] = {150, 140, 170, 170, 0, 0, 300, 330};
  420. static const unsigned char stress_amps_it[8] = {15,14, 19,19, 20,22, 22,20 };
  421. tr = new Translator();
  422. SetupTranslator(tr,stress_lengths_it,stress_amps_it);
  423. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  424. tr->langopts.stress_rule = 2;
  425. tr->langopts.vowel_pause = 1;
  426. tr->langopts.unstressed_wd1 = 2;
  427. tr->langopts.unstressed_wd2 = 2;
  428. tr->langopts.param[LOPT_IT_LENGTHEN] = 2; // remove lengthen indicator from unstressed or non-penultimate syllables
  429. tr->langopts.param[LOPT_IT_DOUBLING] = 2; // double the first consonant if the previous word ends in a stressed vowel
  430. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  431. tr->langopts.param[LOPT_REDUCE] = 1; // reduce vowels even if phonemes are specified in it_list
  432. tr->langopts.numbers = 0x2709 + NUM_ROMAN;
  433. tr->langopts.accents = 2; // Say "Capital" after the letter.
  434. }
  435. break;
  436. case L('j','a'): // TEST
  437. tr = new Translator();
  438. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  439. break;
  440. case L_jbo: // Lojban
  441. {
  442. static const short stress_lengths_jbo[8] = {145,145, 170,160, 0,0, 330,350};
  443. static const wchar_t jbo_punct_within_word[] = {'.',',','\'',0x2c8,0}; // allow period and comma within a word, also stress marker (from LOPT_SYLLABLE_CAPS)
  444. tr = new Translator();
  445. SetupTranslator(tr,stress_lengths_jbo,NULL);
  446. tr->langopts.stress_rule = 2;
  447. tr->langopts.vowel_pause = 0x20c; // pause before a word which starts with a vowel, or after a word which ends in a consonant
  448. // tr->langopts.word_gap = 1;
  449. tr->punct_within_word = jbo_punct_within_word;
  450. tr->langopts.param[LOPT_SYLLABLE_CAPS] = 1; // capitals indicate stressed syllables
  451. SetLetterVowel(tr,'y');
  452. }
  453. break;
  454. case L('k','o'): // Korean, TEST
  455. {
  456. static const char ko_ivowels[] = {0x63,0x64,0x67,0x68,0x6d,0x72,0x74,0x75,0}; // y and i vowels
  457. static const char ko_voiced[] = {0x02,0x05,0x06,0xab,0xaf,0xb7,0xbc,0}; // voiced consonants, l,m,n,N
  458. tr = new Translator();
  459. tr->letter_bits_offset = OFFSET_KOREAN;
  460. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  461. SetLetterBitsRange(tr,LETTERGP_A,0x61,0x75);
  462. SetLetterBits(tr,LETTERGP_Y,ko_ivowels);
  463. SetLetterBits(tr,LETTERGP_G,ko_voiced);
  464. tr->langopts.stress_rule = 8; // ?? 1st syllable if it is heavy, else 2nd syllable
  465. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  466. tr->langopts.numbers = 0x0401;
  467. }
  468. break;
  469. case L('k','u'): // Kurdish
  470. {
  471. static const unsigned char stress_amps_ku[8] = {18,18, 20,20, 20,22, 22,21 };
  472. static const short stress_lengths_ku[8] = {180,180, 190,180, 0,0, 230,240};
  473. tr = new Translator();
  474. SetupTranslator(tr,stress_lengths_ku,stress_amps_ku);
  475. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  476. tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
  477. tr->langopts.numbers = 0x100461;
  478. tr->langopts.max_initial_consonants = 2;
  479. }
  480. break;
  481. case L('l','a'): //Latin
  482. {
  483. tr = new Translator();
  484. tr->charset_a0 = charsets[4]; // ISO-8859-4, includes a,e,i,o,u-macron
  485. tr->langopts.stress_rule = 2;
  486. tr->langopts.stress_flags = 0x20;
  487. tr->langopts.unstressed_wd1 = 0;
  488. tr->langopts.unstressed_wd2 = 2;
  489. tr->langopts.param[LOPT_DIERESES] = 1;
  490. tr->langopts.numbers = 0x1 + NUM_ROMAN;
  491. tr->langopts.max_roman = 5000;
  492. }
  493. break;
  494. case L('l','v'): // latvian
  495. {
  496. static const unsigned char stress_amps_lv[8] = {17,13, 20,20, 20,22, 22,21 };
  497. static const short stress_lengths_lv[8] = {180,130, 210,210, 0,0, 210,210};
  498. tr = new Translator();
  499. SetupTranslator(tr,stress_lengths_lv,stress_amps_lv);
  500. tr->langopts.stress_rule = 0;
  501. tr->langopts.spelling_stress = 1;
  502. tr->charset_a0 = charsets[4]; // ISO-8859-4
  503. tr->langopts.numbers = 0x409 + 0x8000 + 0x10000;
  504. tr->langopts.stress_flags = 0x16 + 0x40000;
  505. }
  506. break;
  507. case L('m','k'): // Macedonian
  508. {
  509. static wchar_t vowels_cyrillic[] = {0x440, // also include 'р' [R]
  510. 0x430,0x435,0x438,0x439,0x43e,0x443,0x44b,0x44d,0x44e,0x44f,0x450,0x451,0x456,0x457,0x45d,0x45e,0};
  511. static const unsigned char stress_amps_mk[8] = {17,17, 20,20, 20,22, 22,21 };
  512. static const short stress_lengths_mk[8] = {180,160, 200,200, 0,0, 220,230};
  513. tr = new Translator();
  514. SetupTranslator(tr,stress_lengths_mk,stress_amps_mk);
  515. tr->charset_a0 = charsets[5]; // ISO-8859-5
  516. tr->letter_groups[0] = vowels_cyrillic;
  517. tr->langopts.stress_rule = 4; // antipenultimate
  518. tr->langopts.numbers = 0x0429 + 0x4000;
  519. tr->langopts.numbers2 = 0x8a; // variant numbers before thousands,milliards
  520. }
  521. break;
  522. case L('n','l'): // Dutch
  523. {
  524. static const short stress_lengths_nl[8] = {160,135, 210,210, 0, 0, 260,280};
  525. tr = new Translator();
  526. tr->langopts.stress_rule = 0;
  527. tr->langopts.vowel_pause = 1;
  528. tr->langopts.param[LOPT_DIERESES] = 1;
  529. tr->langopts.param[LOPT_PREFIXES] = 1;
  530. SetLetterVowel(tr,'y');
  531. tr->langopts.numbers = 0x11c19;
  532. memcpy(tr->stress_lengths,stress_lengths_nl,sizeof(tr->stress_lengths));
  533. }
  534. break;
  535. case L('n','o'): // Norwegian
  536. {
  537. static const short stress_lengths_no[8] = {160,140, 200,200, 0,0, 220,210};
  538. tr = new Translator();
  539. SetupTranslator(tr,stress_lengths_no,NULL);
  540. tr->langopts.stress_rule = 0;
  541. SetLetterVowel(tr,'y');
  542. tr->langopts.numbers = 0x11849;
  543. }
  544. break;
  545. case L('o','m'):
  546. {
  547. static const unsigned char stress_amps_om[] = {18,15, 20,20, 20,22, 22,22 };
  548. static const short stress_lengths_om[8] = {200,200, 200,200, 0,0, 200,200};
  549. tr = new Translator();
  550. SetupTranslator(tr,stress_lengths_om,stress_amps_om);
  551. tr->langopts.stress_rule = 2;
  552. tr->langopts.stress_flags = 0x16 + 0x80000;
  553. }
  554. break;
  555. case L('p','l'): // Polish
  556. {
  557. static const short stress_lengths_pl[8] = {160, 190, 175, 175, 0, 0, 200, 210};
  558. 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
  559. tr = new Translator();
  560. SetupTranslator(tr,stress_lengths_pl,stress_amps_pl);
  561. tr->charset_a0 = charsets[2]; // ISO-8859-2
  562. tr->langopts.stress_rule = 2;
  563. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  564. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x8;
  565. tr->langopts.max_initial_consonants = 7; // for example: wchrzczony :)
  566. tr->langopts.numbers=0x1009 + 0x4000;
  567. tr->langopts.numbers2=0x40;
  568. tr->langopts.param[LOPT_COMBINE_WORDS] = 4 + 0x100; // combine 'nie' (marked with $alt2) with some 1-syllable (and 2-syllable) words (marked with $alt)
  569. SetLetterVowel(tr,'y');
  570. }
  571. break;
  572. case L('p','t'): // Portuguese
  573. {
  574. static const short stress_lengths_pt[8] = {180, 125, 210, 210, 0, 0, 270, 295};
  575. static const unsigned char stress_amps_pt[8] = {16,13, 19,19, 20,22, 22,21 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  576. tr = new Translator();
  577. SetupTranslator(tr,stress_lengths_pt,stress_amps_pt);
  578. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  579. tr->langopts.stress_rule = 3; // stress on final syllable
  580. tr->langopts.stress_flags = 0x6 | 0x10 | 0x20000;
  581. tr->langopts.numbers = 0x269 + 0x4000 + NUM_ROMAN;
  582. SetLetterVowel(tr,'y');
  583. ResetLetterBits(tr,0x2);
  584. SetLetterBits(tr,1,"bcdfgjkmnpqstvxz"); // B hard consonants, excluding h,l,r,w,y
  585. }
  586. break;
  587. case L('r','o'): // Romanian
  588. {
  589. static const short stress_lengths_ro[8] = {170, 170, 180, 180, 0, 0, 240, 260};
  590. static const unsigned char stress_amps_ro[8] = {15,13, 18,18, 20,22, 22,21 };
  591. tr = new Translator();
  592. SetupTranslator(tr,stress_lengths_ro,stress_amps_ro);
  593. tr->langopts.stress_rule = 2;
  594. tr->langopts.stress_flags = 0x100 + 0x6;
  595. tr->charset_a0 = charsets[2]; // ISO-8859-2
  596. tr->langopts.numbers = 0x1029+0x6000 + NUM_ROMAN;
  597. tr->langopts.numbers2 = 0x1e; // variant numbers before all thousandplex
  598. }
  599. break;
  600. case L('r','u'): // Russian
  601. tr = new Translator_Russian();
  602. break;
  603. case L('r','w'): // Kiryarwanda
  604. {
  605. tr = new Translator();
  606. tr->langopts.stress_rule = 2;
  607. tr->langopts.stress_flags = 0x16;
  608. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  609. tr->langopts.numbers = 0x61 + 0x100000 + 0x4000;
  610. tr->langopts.numbers2 = 0x200; // say "thousands" before its number
  611. }
  612. break;
  613. case L('s','k'): // Slovak
  614. case L('c','s'): // Czech
  615. {
  616. static const char *sk_voiced = "bdgjlmnrvwzaeiouy";
  617. tr = new Translator();
  618. SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
  619. tr->charset_a0 = charsets[2]; // ISO-8859-2
  620. tr->langopts.stress_rule = 0;
  621. tr->langopts.stress_flags = 0x16;
  622. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  623. tr->langopts.max_initial_consonants = 5;
  624. tr->langopts.spelling_stress = 1;
  625. tr->langopts.param[LOPT_COMBINE_WORDS] = 4; // combine some prepositions with the following word
  626. tr->langopts.numbers = 0x0401 + 0x4000 + NUM_ROMAN;
  627. tr->langopts.numbers2 = 0x40;
  628. tr->langopts.thousands_sep = 0; //no thousands separator
  629. tr->langopts.decimal_sep = ',';
  630. if(name2 == L('c','s'))
  631. {
  632. tr->langopts.numbers2 = 0x48; // variant numbers before milliards
  633. }
  634. SetLetterVowel(tr,'y');
  635. SetLetterVowel(tr,'r');
  636. ResetLetterBits(tr,0x20);
  637. SetLetterBits(tr,5,sk_voiced);
  638. }
  639. break;
  640. case L('s','q'): // Albanian
  641. {
  642. static const short stress_lengths_sq[8] = {150, 150, 180, 180, 0, 0, 300, 300};
  643. static const unsigned char stress_amps_sq[8] = {16,12, 16,16, 20,20, 21,19 };
  644. tr = new Translator();
  645. SetupTranslator(tr,stress_lengths_sq,stress_amps_sq);
  646. tr->langopts.stress_rule = 2;
  647. tr->langopts.stress_flags = 0x16 + 0x100;
  648. SetLetterVowel(tr,'y');
  649. tr->langopts.numbers = 0x69 + 0x8000;
  650. }
  651. break;
  652. case L('s','v'): // Swedish
  653. {
  654. static const unsigned char stress_amps_sv[] = {16,16, 20,20, 20,22, 22,21 };
  655. static const short stress_lengths_sv[8] = {160,135, 220,220, 0,0, 250,280};
  656. tr = new Translator();
  657. SetupTranslator(tr,stress_lengths_sv,stress_amps_sv);
  658. tr->langopts.stress_rule = 0;
  659. SetLetterVowel(tr,'y');
  660. // SetLetterBits(tr,6,"eiyäö"); // soft vowels NOTE accented letters don't work in SetLetterBits
  661. tr->langopts.numbers = 0x1909;
  662. tr->langopts.accents = 1;
  663. }
  664. break;
  665. case L('s','w'): // Swahili
  666. {
  667. static const short stress_lengths_sw[8] = {160, 170, 200, 200, 0, 0, 320, 340};
  668. static const unsigned char stress_amps_sw[] = {16,12, 19,19, 20,22, 22,21 };
  669. tr = new Translator();
  670. SetupTranslator(tr,stress_lengths_sw,stress_amps_sw);
  671. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  672. tr->langopts.vowel_pause = 1;
  673. tr->langopts.stress_rule = 2;
  674. tr->langopts.stress_flags = 0x6 | 0x10;
  675. tr->langopts.numbers = 0x4e1;
  676. tr->langopts.numbers2 = NUM2_100000a;
  677. }
  678. break;
  679. case L('t','a'): // Tamil
  680. case L('m','l'): // Malayalam
  681. case L('k','n'): // Kannada
  682. case L('m','r'): // Marathi
  683. {
  684. static const short stress_lengths_ta[8] = {200, 200, 210, 210, 0, 0, 230, 230};
  685. static const unsigned char stress_amps_ta[8] = {18,18, 18,18, 20,20, 22,22 };
  686. tr = new Translator();
  687. SetupTranslator(tr,stress_lengths_ta,stress_amps_ta);
  688. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  689. tr->langopts.stress_rule = 0;
  690. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  691. tr->letter_bits_offset = OFFSET_TAMIL;
  692. if(name2 == L('m','r'))
  693. {
  694. tr->letter_bits_offset = OFFSET_DEVANAGARI;
  695. }
  696. else
  697. if(name2 == L('m','l'))
  698. {
  699. tr->letter_bits_offset = OFFSET_MALAYALAM;
  700. }
  701. else
  702. if(name2 == L('k','n'))
  703. {
  704. tr->letter_bits_offset = OFFSET_KANNADA;
  705. tr->langopts.numbers = 0x1;
  706. tr->langopts.numbers2 = NUM2_100000;
  707. }
  708. tr->langopts.param[LOPT_WORD_MERGE] = 1; // don't break vowels betwen words
  709. SetIndicLetters(tr); // call this after setting OFFSET_
  710. }
  711. break;
  712. #ifdef deleted
  713. case L('t','h'): // Thai
  714. {
  715. static const short stress_lengths_th[8] = {230,150, 230,230, 230,0, 230,250};
  716. static const unsigned char stress_amps_th[] = {22,16, 22,22, 22,22, 22,22 };
  717. tr = new Translator;
  718. SetupTranslator(tr,stress_lengths_th,stress_amps_th);
  719. tr->langopts.stress_rule = 0; // stress on final syllable of a "word"
  720. tr->langopts.stress_flags = 1; // don't automatically set diminished stress (may be set in the intonation module)
  721. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  722. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  723. // tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  724. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  725. }
  726. break;
  727. #endif
  728. case L('t','r'): // Turkish
  729. {
  730. static const unsigned char stress_amps_tr[8] = {18,18, 20,20, 20,22, 22,21 };
  731. static const short stress_lengths_tr[8] = {190,190, 190,190, 0,0, 250,270};
  732. tr = new Translator();
  733. SetupTranslator(tr,stress_lengths_tr,stress_amps_tr);
  734. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  735. tr->langopts.stress_rule = 7; // stress on the last syllable, before any explicitly unstressed syllable
  736. tr->langopts.stress_flags = 0x20; //no automatic secondary stress
  737. tr->langopts.numbers = 0x1509 + 0x4000;
  738. tr->langopts.max_initial_consonants = 2;
  739. }
  740. break;
  741. case L('v','i'): // Vietnamese
  742. {
  743. static const short stress_lengths_vi[8] = {150, 150, 180, 180, 210, 230, 230, 240};
  744. static const unsigned char stress_amps_vi[] = {16,16, 16,16, 22,22, 22,22 };
  745. static wchar_t vowels_vi[] = {
  746. 0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a
  747. 0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă
  748. 0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â
  749. 0x65, 0xe8, 0xe9, 0x1ebb, 0x1ebd, 0x1eb9, // e
  750. 0xea, 0x1ec1, 0x1ebf, 0x1ec3, 0x1ec5, 0x1ec7, // i
  751. 0x69, 0xec, 0xed, 0x1ec9, 0x129, 0x1ecb, // i
  752. 0x6f, 0xf2, 0xf3, 0x1ecf, 0xf5, 0x1ecd, // o
  753. 0xf4, 0x1ed3, 0x1ed1, 0x1ed5, 0x1ed7, 0x1ed9, // ô
  754. 0x1a1, 0x1edd, 0x1edb, 0x1edf, 0x1ee1, 0x1ee3, // ơ
  755. 0x75, 0xf9, 0xfa, 0x1ee7, 0x169, 0x1ee5, // u
  756. 0x1b0, 0x1eeb, 0x1ee9, 0x1eed, 0x1eef, 0x1ef1, // ư
  757. 0x79, 0x1ef3, 0xfd, 0x1ef7, 0x1ef9, 0x1e, 0 }; // y
  758. tr = new Translator();
  759. SetupTranslator(tr,stress_lengths_vi,stress_amps_vi);
  760. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  761. tr->langopts.stress_rule = 0;
  762. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  763. // tr->langopts.vowel_pause = 4;
  764. tr->letter_groups[0] = vowels_vi;
  765. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  766. tr->langopts.unstressed_wd1 = 2;
  767. tr->langopts.numbers = 0x0049 + 0x8000;
  768. }
  769. break;
  770. case L('z','h'):
  771. case L_zhy:
  772. {
  773. 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
  774. static const unsigned char stress_amps_zh[] = {22,16, 22,22, 22,22, 22,22 };
  775. tr = new Translator;
  776. SetupTranslator(tr,stress_lengths_zh,stress_amps_zh);
  777. tr->langopts.stress_rule = 3; // stress on final syllable of a "word"
  778. tr->langopts.stress_flags = 1; // don't automatically set diminished stress (may be set in the intonation module)
  779. tr->langopts.vowel_pause = 0;
  780. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  781. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  782. tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  783. tr->langopts.ideographs = 1;
  784. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  785. if(name2 == L('z','h'))
  786. {
  787. tr->langopts.textmode = 1;
  788. tr->langopts.listx = 1; // compile zh_listx after zh_list
  789. }
  790. }
  791. break;
  792. default:
  793. tr = new Translator();
  794. break;
  795. }
  796. tr->translator_name = name2;
  797. if(tr->langopts.numbers & 0x8)
  798. {
  799. // use . and ; for thousands and decimal separators
  800. tr->langopts.thousands_sep = '.';
  801. tr->langopts.decimal_sep = ',';
  802. }
  803. if(tr->langopts.numbers & 0x4)
  804. {
  805. tr->langopts.thousands_sep = 0; // don't allow thousands separator, except space
  806. }
  807. return(tr);
  808. } // end of SelectTranslator
  809. //**********************************************************************************************************
  810. Translator_Russian::Translator_Russian() : Translator()
  811. {//===================================
  812. static const unsigned char stress_amps_ru[] = {16,16, 18,18, 20,24, 24,22 };
  813. static const short stress_lengths_ru[8] = {150,140, 220,220, 0,0, 260,280};
  814. // character codes offset by 0x420
  815. static const char ru_vowels[] = {0x10,0x15,0x31,0x18,0x1e,0x23,0x2b,0x2d,0x2e,0x2f,0};
  816. 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};
  817. static const char ru_soft[] = {0x2c,0x19,0x27,0x29,0}; // letter group B [k ts; s;]
  818. static const char ru_hard[] = {0x2a,0x16,0x26,0x28,0}; // letter group H [S Z ts]
  819. 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};
  820. static const char ru_voiced[] = {0x11,0x12,0x13,0x14,0x16,0x17,0}; // letter group G (voiced obstruents)
  821. static const char ru_ivowels[] = {0x2c,0x15,0x31,0x18,0x2e,0x2f,0}; // letter group Y (iotated vowels & soft-sign)
  822. SetupTranslator(this,stress_lengths_ru,stress_amps_ru);
  823. charset_a0 = charsets[18]; // KOI8-R
  824. transpose_offset = 0x42f; // convert cyrillic from unicode into range 0x01 to 0x22
  825. transpose_min = 0x430;
  826. transpose_max = 0x451;
  827. letter_bits_offset = OFFSET_CYRILLIC;
  828. memset(letter_bits,0,sizeof(letter_bits));
  829. SetLetterBits(this,0,ru_vowels);
  830. SetLetterBits(this,1,ru_soft);
  831. SetLetterBits(this,2,ru_consonants);
  832. SetLetterBits(this,3,ru_hard);
  833. SetLetterBits(this,4,ru_nothard);
  834. SetLetterBits(this,5,ru_voiced);
  835. SetLetterBits(this,6,ru_ivowels);
  836. SetLetterBits(this,7,ru_vowels);
  837. langopts.param[LOPT_UNPRONOUNCABLE] = 0x432; // [v] don't count this character at start of word
  838. langopts.param[LOPT_REGRESSIVE_VOICING] = 1;
  839. langopts.param[LOPT_REDUCE] = 2;
  840. langopts.stress_rule = 5;
  841. langopts.stress_flags = 0x0020; // waas 0x1010
  842. langopts.numbers = 0x0409;
  843. langopts.numbers2 = 0xc2; // variant numbers before thousands
  844. langopts.phoneme_change = 1;
  845. langopts.testing = 2;
  846. } // end of Translator_Russian
  847. #define PH(c1,c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name
  848. #define PY(c1,c2,c3) (c3<<16)+(c2<<8)+c1
  849. /*
  850. typedef struct {
  851. int flags;
  852. unsigned char stress; // stress level of this vowel
  853. unsigned char stress_highest; // the highest stress level of a vowel in this word
  854. unsigned char n_vowels; // number of vowels in the word
  855. unsigned char vowel_this; // syllable number of this vowel (counting from 1)
  856. unsigned char vowel_stressed; // syllable number of the highest stressed vowel
  857. } CHANGEPH;
  858. */
  859. #define RUSSIAN2
  860. #ifdef RUSSIAN2
  861. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  862. {//==============================================================================================================
  863. // Called for each phoneme in the phoneme list, to allow a language to make changes
  864. // ph The current phoneme
  865. int variant;
  866. int vowelix;
  867. PHONEME_TAB *prev, *next;
  868. if(ch->flags & 8)
  869. return(0); // full phoneme translation has already been given
  870. // Russian vowel softening and reduction rules
  871. if(ph->type == phVOWEL)
  872. {
  873. int prestressed = ch->vowel_stressed==ch->vowel_this+1; // the next vowel after this has the main stress
  874. #define N_VOWELS_RU 11
  875. static unsigned int vowels_ru[N_VOWELS_RU] = {'a','V','O','I',PH('I','#'),PH('E','#'),PH('E','2'),
  876. PH('V','#'),PH('I','3'),PH('I','2'),PH('E','3')};
  877. static unsigned int vowel_replace[N_VOWELS_RU][6] = {
  878. // stressed, soft, soft-stressed, j+stressed, j+soft, j+soft-stressed
  879. /*0*/ {'A', 'I', PH('j','a'), 'a', 'a', 'a'}, // a Uses 3,4,5 columns.
  880. /*1*/ {'A', 'V', PH('j','a'), 'a', 'V', 'a'}, // V Uses 3,4,5 columns.
  881. /*2*/ {'o', '8', '8', 'o', '8', '8'}, // O
  882. /*3*/ {'i', 'I', 'i', 'a', 'I', 'a'}, // I Uses 3,4,5 columns.
  883. /*4*/ {'i', PH('I','#'), 'i', 'i', PH('I','#'), 'i'}, // I#
  884. /*5*/ {'E', PH('E','#'), 'E', 'e', PH('E','#'), 'e'}, // E#
  885. /*6*/ {'E', PH('E','2'), 'E', 'e', PH('E','2'), 'e'}, // E2 Uses 3,4,5 columns.
  886. /*7*/ {PH('j','a'), 'V', PH('j','a'), 'A', 'V', 'A'}, // V#
  887. /*8*/ {PH('j','a'), 'I', PH('j','a'), 'e', 'I', 'e'}, // I3 Uses 3,4,5 columns.
  888. /*9*/ {'e', 'I', 'e', 'e', 'I', 'e'}, // I2
  889. /*10*/ {'e', PH('E', '2'), 'e', 'e', PH('E','2'), 'e'} // E3
  890. };
  891. prev = phoneme_tab[phlist[index-1].phcode];
  892. next = phoneme_tab[phlist[index+1].phcode];
  893. // lookup the vowel name to get an index into the vowel_replace[] table
  894. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  895. {
  896. if(vowels_ru[vowelix] == ph->mnemonic)
  897. break;
  898. }
  899. if(vowelix == N_VOWELS_RU)
  900. return(0);
  901. if(prestressed)
  902. {
  903. if((vowelix==6)&&(prev->mnemonic=='j'))
  904. vowelix=8;
  905. if(vowelix==1)
  906. vowelix=0;
  907. if(vowelix==4)
  908. vowelix=3;
  909. if(vowelix==6)
  910. vowelix=5;
  911. if(vowelix==7)
  912. vowelix=8;
  913. if(vowelix==10)
  914. vowelix=9;
  915. }
  916. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  917. variant = -1;
  918. int stressed = ch->flags & 2;
  919. int soft=prev->phflags & phPALATAL;
  920. if (soft && stressed)
  921. variant = 2; else
  922. if (stressed)
  923. variant = 0; else
  924. if (soft)
  925. variant = 1;
  926. if(variant >= 0)
  927. {
  928. if(prev->mnemonic == 'j')
  929. variant += 3;
  930. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  931. }
  932. else
  933. {
  934. phlist[index].phcode = PhonemeCode(vowels_ru[vowelix]);
  935. }
  936. }
  937. return(0);
  938. }
  939. #else
  940. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  941. {//===============================================================================================================
  942. // Called for each phoneme in the phoneme list, to allow a language to make changes
  943. // flags: bit 0=1 last phoneme in a word
  944. // bit 1=1 this is the highest stressed vowel in the current word
  945. // bit 2=1 after the highest stressed vowel in the current word
  946. // bit 3=1 the phonemes were specified explicitly, or found from an entry in the xx_list dictionary
  947. // ph The current phoneme
  948. int variant;
  949. int vowelix;
  950. PHONEME_TAB *prev, *next;
  951. if(ch->flags & 8)
  952. return(0); // full phoneme translation has already been given
  953. // Russian vowel softening and reduction rules
  954. if(ph->type == phVOWEL)
  955. {
  956. #define N_VOWELS_RU 7
  957. static unsigned char vowels_ru[N_VOWELS_RU] = {'a','A','o','E','i','u','y'};
  958. // each line gives: soft, reduced, soft-reduced, post-tonic
  959. static unsigned short vowel_replace[N_VOWELS_RU][4] = {
  960. {'&', 'V', 'I', 'V'}, // a
  961. {'&', 'V', 'I', 'V'}, // A
  962. {'8', 'V', 'I', 'V'}, // o
  963. {'e', 'I', 'I', 'I'}, // E
  964. {'i', 'I', 'I', 'I'}, // i
  965. {'u'+('"'<<8), 'U', 'U', 'U'}, // u
  966. {'y', 'Y', 'Y', 'Y'}}; // y
  967. prev = phoneme_tab[phlist[index-1].phcode];
  968. next = phoneme_tab[phlist[index+1].phcode];
  969. if(prev->mnemonic == 'j')
  970. return(0);
  971. // lookup the vowel name to get an index into the vowel_replace[] table
  972. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  973. {
  974. if(vowels_ru[vowelix] == ph->mnemonic)
  975. break;
  976. }
  977. if(vowelix == N_VOWELS_RU)
  978. return(0);
  979. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  980. variant = -1;
  981. if(ch->flags & 2)
  982. {
  983. // a stressed vowel
  984. if((prev->phflags & phPALATAL) && ((next->phflags & phPALATAL) || phoneme_tab[phlist[index+2].phcode]->mnemonic == ';'))
  985. {
  986. // between two palatal consonants, use the soft variant
  987. variant = 0;
  988. }
  989. }
  990. else
  991. {
  992. // an unstressed vowel
  993. if(prev->phflags & phPALATAL)
  994. {
  995. variant = 2; // unstressed soft
  996. }
  997. else
  998. if((ph->mnemonic == 'o') && ((prev->phflags & phPLACE) == phPLACE_pla))
  999. {
  1000. variant = 2; // unstressed soft ([o] vowel following: ш ж
  1001. }
  1002. else
  1003. if(ch->flags & 4)
  1004. {
  1005. variant = 3; // post tonic
  1006. }
  1007. else
  1008. {
  1009. variant = 1; // unstressed
  1010. }
  1011. }
  1012. if(variant >= 0)
  1013. {
  1014. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  1015. }
  1016. }
  1017. return(0);
  1018. }
  1019. #endif