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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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 = 0x11c19 + 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 = 0xb09;
  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 = 0x1c09 + 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,22, 22,22 }; // '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 = 0x1009;
  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] = {16,14, 20,20, 20,24, 24,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 + 0x4000 + 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 = 0x811;
  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.numbers = 0x1c0d + 0x4000 + NUM_ROMAN_UC;
  272. tr->langopts.numbers2 = 0x4a; // variant numbers before thousands,milliards
  273. tr->langopts.replace_chars = replace_cyrillic_latin;
  274. SetLetterVowel(tr,'y');
  275. SetLetterVowel(tr,'r');
  276. }
  277. break;
  278. case L('h','u'): // Hungarian
  279. {
  280. static const unsigned char stress_amps_hu[8] = {17,17, 19,19, 20,24, 24,22 };
  281. static const short stress_lengths_hu[8] = {185,195, 195,190, 0,0, 210,220};
  282. tr = new Translator();
  283. SetupTranslator(tr,stress_lengths_hu,stress_amps_hu);
  284. tr->charset_a0 = charsets[2]; // ISO-8859-2
  285. tr->langopts.vowel_pause = 0x20;
  286. tr->langopts.stress_rule = 0;
  287. tr->langopts.stress_flags = 0x8036;
  288. tr->langopts.unstressed_wd1 = 2;
  289. // tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x4; // don't propagate over word boundaries
  290. tr->langopts.param[LOPT_IT_DOUBLING] = 1;
  291. tr->langopts.param[LOPT_COMBINE_WORDS] = 99; // combine some prepositions with the following word
  292. tr->langopts.numbers = 0x1809 + NUM_ROMAN;
  293. SetLetterVowel(tr,'y');
  294. tr->langopts.spelling_stress = 1;
  295. SetLengthMods(tr,3); // all equal
  296. }
  297. break;
  298. case L('i','d'): // Indonesian
  299. {
  300. static const short stress_lengths_id[8] = {160, 200, 180, 180, 0, 0, 220, 240};
  301. static const unsigned char stress_amps_id[8] = {16,18, 18,18, 20,22, 22,21 };
  302. tr = new Translator();
  303. SetupTranslator(tr,stress_lengths_id,stress_amps_id);
  304. tr->langopts.stress_rule = 2;
  305. tr->langopts.numbers = 0x1809 + NUM_ROMAN;
  306. tr->langopts.stress_flags = 0x6 | 0x10;
  307. }
  308. break;
  309. case L('i','s'): // Icelandic
  310. {
  311. static const unsigned char stress_amps_is[] = {16,16, 20,20, 20,24, 24,22 };
  312. static const short stress_lengths_is[8] = {180,160, 200,200, 0,0, 240,250};
  313. static const wchar_t is_lettergroup_B[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
  314. tr = new Translator();
  315. SetupTranslator(tr,stress_lengths_is,stress_amps_is);
  316. tr->langopts.stress_rule = 0;
  317. tr->langopts.stress_flags = 0x10;
  318. tr->langopts.param[LOPT_IT_LENGTHEN] = 0x11; // remove lengthen indicator from unstressed vowels
  319. tr->langopts.param[LOPT_REDUCE] = 2;
  320. ResetLetterBits(tr,0x18);
  321. SetLetterBits(tr,4,"kpst"); // Letter group F
  322. SetLetterBits(tr,3,"jvr"); // Letter group H
  323. tr->letter_groups[1] = is_lettergroup_B;
  324. SetLetterVowel(tr,'y');
  325. tr->langopts.numbers = 0xe9;
  326. tr->langopts.numbers2 = 0x2;
  327. }
  328. break;
  329. case L('i','t'): // Italian
  330. {
  331. static const short stress_lengths_it[8] = {150, 140, 180, 180, 0, 0, 270, 320};
  332. static const unsigned char stress_amps_it[8] = {15,14, 19,19, 20,24, 24,22 };
  333. tr = new Translator();
  334. SetupTranslator(tr,stress_lengths_it,stress_amps_it);
  335. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  336. tr->langopts.stress_rule = 2;
  337. tr->langopts.vowel_pause = 1;
  338. tr->langopts.unstressed_wd1 = 2;
  339. tr->langopts.unstressed_wd2 = 2;
  340. tr->langopts.param[LOPT_IT_LENGTHEN] = 2; // remove lengthen indicator from unstressed or non-penultimate syllables
  341. tr->langopts.param[LOPT_IT_DOUBLING] = 2; // double the first consonant if the previous word ends in a stressed vowel
  342. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  343. tr->langopts.param[LOPT_REDUCE] = 1; // reduce vowels even if phonemes are specified in it_list
  344. tr->langopts.numbers = 0x2709 + 0x800 + NUM_ROMAN;
  345. }
  346. break;
  347. case L_jbo: // Lojban
  348. {
  349. static const short stress_lengths_jbo[8] = {185,170, 200,200, 0,0, 290,300};
  350. static const wchar_t jbo_punct_within_word[] = {'.',',','\'',0x2c8,0}; // allow period and comma within a word, also stress marker (from LOPT_SYLLABLE_CAPS)
  351. tr = new Translator();
  352. SetupTranslator(tr,stress_lengths_jbo,NULL);
  353. tr->langopts.stress_rule = 2;
  354. tr->langopts.vowel_pause = 0x20c; // pause before a word which starts with a vowel, or after a word which ends in a consonant
  355. tr->punct_within_word = jbo_punct_within_word;
  356. tr->langopts.param[LOPT_SYLLABLE_CAPS] = 1; // capitals indicate stressed syllables
  357. SetLetterVowel(tr,'y');
  358. }
  359. break;
  360. case L('l','a'): //Latin
  361. {
  362. tr = new Translator();
  363. tr->charset_a0 = charsets[4]; // ISO-8859-4, includes a,e,i,o,u-macron
  364. tr->langopts.stress_rule = 2;
  365. tr->langopts.stress_flags = 0x20;
  366. tr->langopts.unstressed_wd1 = 0;
  367. tr->langopts.unstressed_wd2 = 2;
  368. tr->langopts.param[LOPT_DIERESES] = 1;
  369. tr->langopts.numbers = 0x1 + NUM_ROMAN;
  370. tr->langopts.max_roman = 5000;
  371. }
  372. break;
  373. case L('m','k'): // Macedonian
  374. {
  375. static wchar_t vowels_cyrillic[] = {0x440, // also include 'р' [R]
  376. 0x430,0x435,0x438,0x439,0x43e,0x443,0x44b,0x44d,0x44e,0x44f,0x450,0x451,0x456,0x457,0x45d,0x45e,0};
  377. static const unsigned char stress_amps_mk[8] = {16,16, 20,20, 20,24, 24,22 };
  378. static const short stress_lengths_mk[8] = {180,160, 200,200, 0,0, 220,230};
  379. tr = new Translator();
  380. SetupTranslator(tr,stress_lengths_mk,stress_amps_mk);
  381. tr->charset_a0 = charsets[5]; // ISO-8859-5
  382. tr->letter_groups[0] = vowels_cyrillic;
  383. tr->langopts.stress_rule = 4; // antipenultimate
  384. tr->langopts.numbers = 0x0c29 + 0x4000;
  385. tr->langopts.numbers2 = 0x8a; // variant numbers before thousands,milliards
  386. }
  387. break;
  388. case L('n','l'): // Dutch
  389. {
  390. static const short stress_lengths_nl[8] = {160,135, 210,210, 0, 0, 260,280};
  391. tr = new Translator();
  392. tr->langopts.stress_rule = 0;
  393. tr->langopts.vowel_pause = 1;
  394. tr->langopts.param[LOPT_DIERESES] = 1;
  395. tr->langopts.param[LOPT_PREFIXES] = 1;
  396. SetLetterVowel(tr,'y');
  397. tr->langopts.numbers = 0x11419;
  398. memcpy(tr->stress_lengths,stress_lengths_nl,sizeof(tr->stress_lengths));
  399. }
  400. break;
  401. case L('n','o'): // Norwegian
  402. {
  403. static const unsigned char stress_amps_no[] = {16,16, 20,20, 20,24, 24,22 };
  404. static const short stress_lengths_no[8] = {160,140, 200,200, 0,0, 220,210};
  405. tr = new Translator();
  406. SetupTranslator(tr,stress_lengths_no,stress_amps_no);
  407. tr->langopts.stress_rule = 0;
  408. SetLetterVowel(tr,'y');
  409. tr->langopts.numbers = 0x11049;
  410. }
  411. break;
  412. case L('p','l'): // Polish
  413. {
  414. static const short stress_lengths_pl[8] = {160, 180, 175, 175, 0, 0, 260, 290};
  415. 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
  416. tr = new Translator();
  417. SetupTranslator(tr,stress_lengths_pl,stress_amps_pl);
  418. tr->charset_a0 = charsets[2]; // ISO-8859-2
  419. tr->langopts.stress_rule = 2;
  420. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  421. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x8;
  422. tr->langopts.max_initial_consonants = 7; // for example: wchrzczony :)
  423. tr->langopts.numbers=0x1809 + 0x4000;
  424. tr->langopts.numbers2=0x40;
  425. tr->langopts.param[LOPT_COMBINE_WORDS] = 2 + 0x100; // combine 'nie' (marked with $alt2) with some 1-syllable words (marked with $alt)
  426. SetLetterVowel(tr,'y');
  427. }
  428. break;
  429. case L('p','t'): // Portuguese
  430. {
  431. static const short stress_lengths_pt[8] = {180, 125, 210, 210, 0, 0, 270, 295};
  432. 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
  433. tr = new Translator();
  434. SetupTranslator(tr,stress_lengths_pt,stress_amps_pt);
  435. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  436. // tr->langopts.vowel_pause = 1;
  437. tr->langopts.stress_rule = 3; // stress on final syllable
  438. tr->langopts.stress_flags = 0x6 | 0x10 | 0x20000;
  439. tr->langopts.numbers = 0xa69 + 0x2000 + NUM_ROMAN;
  440. SetLetterVowel(tr,'y');
  441. }
  442. break;
  443. case L('r','o'): // Romanian
  444. {
  445. static const short stress_lengths_ro[8] = {170, 170, 180, 180, 0, 0, 240, 260};
  446. static const unsigned char stress_amps_ro[8] = {15,13, 18,18, 20,22, 22,22 };
  447. tr = new Translator();
  448. SetupTranslator(tr,stress_lengths_ro,stress_amps_ro);
  449. tr->langopts.stress_rule = 2;
  450. tr->langopts.stress_flags = 0x100 + 0x6;
  451. tr->charset_a0 = charsets[2]; // ISO-8859-2
  452. tr->langopts.numbers = 0x1829+0x6000 + NUM_ROMAN;
  453. tr->langopts.numbers2 = 0x1e; // variant numbers before all thousandplex
  454. }
  455. break;
  456. case L('r','u'): // Russian
  457. tr = new Translator_Russian();
  458. break;
  459. case L('s','k'): // Slovak
  460. case L('c','s'): // Czech
  461. {
  462. static const unsigned char stress_amps_sk[8] = {16,16, 20,20, 20,24, 24,22 };
  463. static const short stress_lengths_sk[8] = {190,190, 210,210, 0,0, 210,210};
  464. static const char *sk_voiced = "bdgjlmnrvwzaeiouy";
  465. tr = new Translator();
  466. SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
  467. tr->charset_a0 = charsets[2]; // ISO-8859-2
  468. tr->langopts.stress_rule = 0;
  469. tr->langopts.stress_flags = 0x16;
  470. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  471. tr->langopts.max_initial_consonants = 5;
  472. tr->langopts.spelling_stress = 1;
  473. tr->langopts.param[LOPT_COMBINE_WORDS] = 4; // combine some prepositions with the following word
  474. tr->langopts.numbers = 0x0c01 + 0x4000 + NUM_ROMAN;
  475. tr->langopts.numbers2 = 0x40;
  476. tr->langopts.thousands_sep = 0; //no thousands separator
  477. tr->langopts.decimal_sep = ',';
  478. if(name2 == L('c','s'))
  479. {
  480. tr->langopts.numbers2 = 0x48; // variant numbers before milliards
  481. }
  482. SetLetterVowel(tr,'y');
  483. SetLetterVowel(tr,'r');
  484. ResetLetterBits(tr,0x2);
  485. SetLetterBits(tr,5,sk_voiced);
  486. }
  487. break;
  488. case L('s','v'): // Swedish
  489. {
  490. static const unsigned char stress_amps_sv[] = {16,16, 20,20, 20,24, 24,22 };
  491. static const short stress_lengths_sv[8] = {160,135, 220,220, 0,0, 250,280};
  492. tr = new Translator();
  493. SetupTranslator(tr,stress_lengths_sv,stress_amps_sv);
  494. tr->langopts.stress_rule = 0;
  495. SetLetterVowel(tr,'y');
  496. // SetLetterBits(tr,6,"eiyäö"); // soft vowels NOTE accented letters don't work in SetLetterBits
  497. tr->langopts.numbers = 0x1109;
  498. }
  499. break;
  500. case L('s','w'): // Swahili
  501. {
  502. static const short stress_lengths_sw[8] = {160, 170, 200, 200, 0, 0, 320, 340};
  503. static const unsigned char stress_amps_sw[] = {16,12, 19,19, 20,24, 24,22 };
  504. tr = new Translator();
  505. SetupTranslator(tr,stress_lengths_sw,stress_amps_sw);
  506. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  507. tr->langopts.vowel_pause = 1;
  508. tr->langopts.stress_rule = 2;
  509. tr->langopts.stress_flags = 0x6 | 0x10;
  510. tr->langopts.numbers = 0x8e1;
  511. tr->langopts.numbers2 = 0x100;
  512. }
  513. break;
  514. case L('t','a'):
  515. {
  516. static const short stress_lengths_ta[8] = {190, 190, 200, 200, 0, 0, 220, 220};
  517. static const unsigned char stress_amps_ta[8] = {18,18, 18,18, 20,20, 22,22 };
  518. tr = new Translator();
  519. SetupTranslator(tr,stress_lengths_ta,stress_amps_ta);
  520. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  521. tr->langopts.stress_rule = 1;
  522. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  523. tr->letter_bits_offset = OFFSET_TAMIL;
  524. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  525. SetLetterBitsRange(tr,LETTERGP_A,0x05,0x14); // vowel letters
  526. SetLetterBitsRange(tr,LETTERGP_A,0x3e,0x4c); // vowel signs
  527. SetLetterBitsRange(tr,LETTERGP_B,0x3e,0x4d); // vowel signs, and virama
  528. SetLetterBitsRange(tr,LETTERGP_C,0x15,0x39); // the main consonant range
  529. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  530. }
  531. break;
  532. case L('t','h'): // Thai
  533. {
  534. static const short stress_lengths_th[8] = {230,150, 230,230, 230,0, 230,250};
  535. static const unsigned char stress_amps_th[] = {22,16, 22,22, 22,22, 22,22 };
  536. tr = new Translator;
  537. SetupTranslator(tr,stress_lengths_th,stress_amps_th);
  538. tr->langopts.stress_rule = 0; // stress on final syllable of a "word"
  539. tr->langopts.stress_flags = 1; // don't automatically set diminished stress (may be set in the intonation module)
  540. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  541. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  542. // tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  543. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  544. }
  545. break;
  546. case L('t','r'): // Turkish
  547. {
  548. static const unsigned char stress_amps_tr[8] = {16,16, 20,20, 20,24, 24,22 };
  549. static const short stress_lengths_tr[8] = {180,150, 200,180, 0,0, 230,270};
  550. tr = new Translator();
  551. SetupTranslator(tr,stress_lengths_tr,stress_amps_tr);
  552. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  553. tr->langopts.stress_rule = 3; // stress on the last syllable
  554. tr->langopts.numbers = 0x1009;
  555. tr->langopts.max_initial_consonants = 2;
  556. }
  557. break;
  558. case L('v','i'): // Vietnamese
  559. {
  560. static const short stress_lengths_vi[8] = {150, 150, 180, 180, 210, 220, 220, 280};
  561. static const unsigned char stress_amps_vi[] = {16,16, 16,16, 24,24, 24,22 };
  562. static wchar_t vowels_vi[] = {
  563. 0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a
  564. 0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă
  565. 0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â
  566. 0x65, 0xe8, 0xe9, 0x1ebb, 0x1ebd, 0x1eb9, // e
  567. 0xea, 0x1ec1, 0x1ebf, 0x1ec3, 0x1ec5, 0x1ec7, // i
  568. 0x69, 0xec, 0xed, 0x1ec9, 0x129, 0x1ecb, // i
  569. 0x6f, 0xf2, 0xf3, 0x1ecf, 0xf5, 0x1ecd, // o
  570. 0xf4, 0x1ed3, 0x1ed1, 0x1ed5, 0x1ed7, 0x1ed9, // ô
  571. 0x1a1, 0x1edd, 0x1edb, 0x1edf, 0x1ee1, 0x1ee3, // ơ
  572. 0x75, 0xf9, 0xfa, 0x1ee7, 0x169, 0x1ee5, // u
  573. 0x1b0, 0x1eeb, 0x1ee9, 0x1eed, 0x1eef, 0x1ef1, // ư
  574. 0x79, 0x1ef3, 0xfd, 0x1ef7, 0x1ef9, 0x1e, 0 }; // y
  575. tr = new Translator();
  576. SetupTranslator(tr,stress_lengths_vi,stress_amps_vi);
  577. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  578. tr->langopts.stress_rule = 0;
  579. tr->langopts.word_gap = 0x20; // length of a final vowel is less dependent on the next consonant
  580. tr->langopts.vowel_pause = 4;
  581. tr->letter_groups[0] = vowels_vi;
  582. // tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  583. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  584. tr->langopts.unstressed_wd1 = 2;
  585. }
  586. break;
  587. case L('z','h'):
  588. case L_zhy:
  589. {
  590. static const short stress_lengths_zh[8] = {230,150, 230,230, 230,0, 230,250};
  591. static const unsigned char stress_amps_zh[] = {22,16, 22,22, 22,22, 22,22 };
  592. tr = new Translator;
  593. SetupTranslator(tr,stress_lengths_zh,stress_amps_zh);
  594. tr->langopts.stress_rule = 3; // stress on final syllable of a "word"
  595. tr->langopts.stress_flags = 1; // don't automatically set diminished stress (may be set in the intonation module)
  596. tr->langopts.vowel_pause = 0;
  597. tr->langopts.tone_language = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  598. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  599. tr->langopts.tone_numbers = 1; // a number after letters indicates a tone number (eg. pinyin or jyutping)
  600. tr->langopts.ideographs = 1;
  601. tr->langopts.word_gap = 0x21; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  602. if(name2 == L('z','h'))
  603. {
  604. tr->langopts.textmode = 1;
  605. }
  606. }
  607. break;
  608. default:
  609. tr = new Translator();
  610. break;
  611. }
  612. tr->translator_name = name2;
  613. if(tr->langopts.numbers & 0x8)
  614. {
  615. // use . and ; for thousands and decimal separators
  616. tr->langopts.thousands_sep = '.';
  617. tr->langopts.decimal_sep = ',';
  618. }
  619. if(tr->langopts.numbers & 0x4)
  620. {
  621. tr->langopts.thousands_sep = 0; // don't allow thousands separator, except space
  622. }
  623. return(tr);
  624. } // end of SelectTranslator
  625. //**********************************************************************************************************
  626. Translator_Russian::Translator_Russian() : Translator()
  627. {//===================================
  628. static const unsigned char stress_amps_ru[] = {16,16, 18,18, 20,24, 24,22 };
  629. static const short stress_lengths_ru[8] = {150,140, 220,220, 0,0, 260,280};
  630. // character codes offset by 0x420
  631. static const char ru_vowels[] = {0x10,0x15,0x31,0x18,0x1e,0x23,0x2b,0x2d,0x2e,0x2f,0};
  632. 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};
  633. static const char ru_soft[] = {0x2c,0x19,0x27,0x29,0}; // letter group B [k ts; s;]
  634. static const char ru_hard[] = {0x2a,0x16,0x26,0x28,0}; // letter group H [S Z ts]
  635. 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};
  636. static const char ru_voiced[] = {0x11,0x12,0x13,0x14,0x16,0x17,0}; // letter group G (voiced obstruents)
  637. static const char ru_ivowels[] = {0x2c,0x15,0x31,0x18,0x2e,0x2f,0}; // letter group Y (iotated vowels & soft-sign)
  638. SetupTranslator(this,stress_lengths_ru,stress_amps_ru);
  639. charset_a0 = charsets[18]; // KOI8-R
  640. transpose_offset = 0x42f; // convert cyrillic from unicode into range 0x01 to 0x22
  641. transpose_min = 0x430;
  642. transpose_max = 0x451;
  643. letter_bits_offset = OFFSET_CYRILLIC;
  644. memset(letter_bits,0,sizeof(letter_bits));
  645. SetLetterBits(this,0,ru_vowels);
  646. SetLetterBits(this,1,ru_soft);
  647. SetLetterBits(this,2,ru_consonants);
  648. SetLetterBits(this,3,ru_hard);
  649. SetLetterBits(this,4,ru_nothard);
  650. SetLetterBits(this,5,ru_voiced);
  651. SetLetterBits(this,6,ru_ivowels);
  652. SetLetterBits(this,7,ru_vowels);
  653. langopts.param[LOPT_UNPRONOUNCABLE] = 0x432; // [v] don't count this character at start of word
  654. langopts.param[LOPT_REGRESSIVE_VOICING] = 1;
  655. langopts.param[LOPT_REDUCE] = 2;
  656. langopts.stress_rule = 5;
  657. langopts.stress_flags = 0x0020; // waas 0x1010
  658. langopts.numbers = 0x0409;
  659. langopts.numbers2 = 0xc2; // variant numbers before thousands
  660. langopts.phoneme_change = 1;
  661. langopts.testing = 2;
  662. } // end of Translator_Russian
  663. #define PH(c1,c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name
  664. #define PY(c1,c2,c3) (c3<<16)+(c2<<8)+c1
  665. /*
  666. typedef struct {
  667. int flags;
  668. unsigned char stress; // stress level of this vowel
  669. unsigned char stress_highest; // the highest stress level of a vowel in this word
  670. unsigned char n_vowels; // number of vowels in the word
  671. unsigned char vowel_this; // syllable number of this vowel (counting from 1)
  672. unsigned char vowel_stressed; // syllable number of the highest stressed vowel
  673. } CHANGEPH;
  674. */
  675. #define RUSSIAN2
  676. #ifdef RUSSIAN2
  677. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  678. {//==============================================================================================================
  679. // Called for each phoneme in the phoneme list, to allow a language to make changes
  680. // ph The current phoneme
  681. int variant;
  682. int vowelix;
  683. PHONEME_TAB *prev, *next;
  684. if(ch->flags & 8)
  685. return(0); // full phoneme translation has already been given
  686. // Russian vowel softening and reduction rules
  687. if(ph->type == phVOWEL)
  688. {
  689. int prestressed = ch->vowel_stressed==ch->vowel_this+1; // the next vowel after this has the main stress
  690. #define N_VOWELS_RU 11
  691. static unsigned int vowels_ru[N_VOWELS_RU] = {'a','V','O','I',PH('I','#'),PH('E','#'),PH('E','2'),
  692. PH('V','#'),PH('I','3'),PH('I','2'),PH('E','3')};
  693. static unsigned int vowel_replace[N_VOWELS_RU][6] = {
  694. // stressed, soft, soft-stressed, j+stressed, j+soft, j+soft-stressed
  695. /*0*/ {'A', 'I', PH('j','a'), 'a', 'a', 'a'}, // a Uses 3,4,5 columns.
  696. /*1*/ {'A', 'V', PH('j','a'), 'a', 'V', 'a'}, // V Uses 3,4,5 columns.
  697. /*2*/ {'o', '8', '8', 'o', '8', '8'}, // O
  698. /*3*/ {'i', 'I', 'i', 'a', 'I', 'a'}, // I Uses 3,4,5 columns.
  699. /*4*/ {'i', PH('I','#'), 'i', 'i', PH('I','#'), 'i'}, // I#
  700. /*5*/ {'E', PH('E','#'), 'E', 'e', PH('E','#'), 'e'}, // E#
  701. /*6*/ {'E', PH('E','2'), 'E', 'e', PH('E','2'), 'e'}, // E2 Uses 3,4,5 columns.
  702. /*7*/ {PH('j','a'), 'V', PH('j','a'), 'A', 'V', 'A'}, // V#
  703. /*8*/ {PH('j','a'), 'I', PH('j','a'), 'e', 'I', 'e'}, // I3 Uses 3,4,5 columns.
  704. /*9*/ {'e', 'I', 'e', 'e', 'I', 'e'}, // I2
  705. /*10*/ {'e', PH('E', '2'), 'e', 'e', PH('E','2'), 'e'} // E3
  706. };
  707. prev = phoneme_tab[phlist[index-1].phcode];
  708. next = phoneme_tab[phlist[index+1].phcode];
  709. // lookup the vowel name to get an index into the vowel_replace[] table
  710. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  711. {
  712. if(vowels_ru[vowelix] == ph->mnemonic)
  713. break;
  714. }
  715. if(vowelix == N_VOWELS_RU)
  716. return(0);
  717. if(prestressed)
  718. {
  719. if((vowelix==6)&&(prev->mnemonic=='j'))
  720. vowelix=8;
  721. if(vowelix==1)
  722. vowelix=0;
  723. if(vowelix==4)
  724. vowelix=3;
  725. if(vowelix==6)
  726. vowelix=5;
  727. if(vowelix==7)
  728. vowelix=8;
  729. if(vowelix==10)
  730. vowelix=9;
  731. }
  732. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  733. variant = -1;
  734. int stressed = ch->flags & 2;
  735. int soft=prev->phflags & phPALATAL;
  736. if (soft && stressed)
  737. variant = 2; else
  738. if (stressed)
  739. variant = 0; else
  740. if (soft)
  741. variant = 1;
  742. if(variant >= 0)
  743. {
  744. if(prev->mnemonic == 'j')
  745. variant += 3;
  746. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  747. }
  748. else
  749. {
  750. phlist[index].phcode = PhonemeCode(vowels_ru[vowelix]);
  751. }
  752. }
  753. return(0);
  754. }
  755. #else
  756. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  757. {//===============================================================================================================
  758. // Called for each phoneme in the phoneme list, to allow a language to make changes
  759. // flags: bit 0=1 last phoneme in a word
  760. // bit 1=1 this is the highest stressed vowel in the current word
  761. // bit 2=1 after the highest stressed vowel in the current word
  762. // bit 3=1 the phonemes were specified explicitly, or found from an entry in the xx_list dictionary
  763. // ph The current phoneme
  764. int variant;
  765. int vowelix;
  766. PHONEME_TAB *prev, *next;
  767. if(ch->flags & 8)
  768. return(0); // full phoneme translation has already been given
  769. // Russian vowel softening and reduction rules
  770. if(ph->type == phVOWEL)
  771. {
  772. #define N_VOWELS_RU 7
  773. static unsigned char vowels_ru[N_VOWELS_RU] = {'a','A','o','E','i','u','y'};
  774. // each line gives: soft, reduced, soft-reduced, post-tonic
  775. static unsigned short vowel_replace[N_VOWELS_RU][4] = {
  776. {'&', 'V', 'I', 'V'}, // a
  777. {'&', 'V', 'I', 'V'}, // A
  778. {'8', 'V', 'I', 'V'}, // o
  779. {'e', 'I', 'I', 'I'}, // E
  780. {'i', 'I', 'I', 'I'}, // i
  781. {'u'+('"'<<8), 'U', 'U', 'U'}, // u
  782. {'y', 'Y', 'Y', 'Y'}}; // y
  783. prev = phoneme_tab[phlist[index-1].phcode];
  784. next = phoneme_tab[phlist[index+1].phcode];
  785. if(prev->mnemonic == 'j')
  786. return(0);
  787. // lookup the vowel name to get an index into the vowel_replace[] table
  788. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  789. {
  790. if(vowels_ru[vowelix] == ph->mnemonic)
  791. break;
  792. }
  793. if(vowelix == N_VOWELS_RU)
  794. return(0);
  795. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  796. variant = -1;
  797. if(ch->flags & 2)
  798. {
  799. // a stressed vowel
  800. if((prev->phflags & phPALATAL) && ((next->phflags & phPALATAL) || phoneme_tab[phlist[index+2].phcode]->mnemonic == ';'))
  801. {
  802. // between two palatal consonants, use the soft variant
  803. variant = 0;
  804. }
  805. }
  806. else
  807. {
  808. // an unstressed vowel
  809. if(prev->phflags & phPALATAL)
  810. {
  811. variant = 2; // unstressed soft
  812. }
  813. else
  814. if((ph->mnemonic == 'o') && ((prev->phflags & phPLACE) == phPLACE_pla))
  815. {
  816. variant = 2; // unstressed soft ([o] vowel following: ш ж
  817. }
  818. else
  819. if(ch->flags & 4)
  820. {
  821. variant = 3; // post tonic
  822. }
  823. else
  824. {
  825. variant = 1; // unstressed
  826. }
  827. }
  828. if(variant >= 0)
  829. {
  830. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  831. }
  832. }
  833. return(0);
  834. }
  835. #endif
  836. //**********************************************************************************************************
  837. Translator_Afrikaans::Translator_Afrikaans() : Translator()
  838. {//=========================================
  839. // Initialise options for this language
  840. static const short stress_lengths2[8] = {170,140, 220,220, 0, 0, 250,270};
  841. langopts.stress_rule = 0;
  842. langopts.vowel_pause = 0x30;
  843. langopts.param[LOPT_DIERESES] = 1;
  844. langopts.param[LOPT_PREFIXES] = 1;
  845. SetLetterVowel(this,'y'); // add 'y' to vowels
  846. langopts.numbers = 0x0d1 + NUM_ROMAN;
  847. memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
  848. }
  849. int Translator_Afrikaans::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  850. {//===============================================================================================================
  851. // look for 'n and replace by a special character (unicode: schwa)
  852. if(!iswalpha(prev_in))
  853. {
  854. if((c == '\'') && (next_in == 'n'))
  855. {
  856. // n preceded by either apostrophe or U2019 "right single quotation mark"
  857. ptr[0] = ' '; // delete the n
  858. return(0x0259); // replace ' by unicode schwa character
  859. }
  860. }
  861. return(c);
  862. }