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

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