fix and add support multy currency <action application=set data=currency=rubl/> dollar or other

This commit is contained in:
Buklov Boris 2011-04-04 17:56:58 +04:00
parent 6eba56d2cb
commit 6fb73a4c31
3 changed files with 71 additions and 29 deletions

View File

@ -316,6 +316,7 @@
<currency>
<prompt phrase="и" filename="and.wav"/>
<prompt phrase="Цент" filename="cent.wav"/>
<prompt phrase="Цента" filename="centa.wav"/>
<prompt phrase="центральный" filename="central.wav"/>
<prompt phrase="Центов в минуту" filename="cents-per-minute.wav"/>
<prompt phrase="Центов" filename="centov.wav"/>
@ -326,9 +327,9 @@
<prompt phrase="Доллары" filename="dollari.wav"/>
<prompt phrase="Минус" filename="minus.wav"/>
<prompt phrase="Отрицательный" filename="negative.wav"/>
<prompt phrase="Копеек" filename="kopeck-i.wav"/>
<prompt phrase="Копейки" filename="kopeck-i.wav"/>
<prompt phrase="Копейка" filename="kopeck.wav"/>
<prompt phrase="Копейки" filename="kopecks.wav"/>
<prompt phrase="Копеек" filename="kopecks.wav"/>
<prompt phrase="Рубль" filename="ruble.wav"/>
<prompt phrase="Рубля" filename="ruble-a.wav"/>
<prompt phrase="Рублей" filename="rubles.wav"/>

View File

@ -58,6 +58,10 @@ struct say_t matrix[7][8] = { {m_00, m_01, m_02, m_03, m_04, m_05, m_06, m_07},
{m_60, m_61, m_62, m_63, m_64, m_65, m_66, m_67}
};
struct say_cur_t matrix_currency[3] = {c_0, c_1, c_2};
SWITCH_MODULE_LOAD_FUNCTION(mod_say_ru_load);
SWITCH_MODULE_DEFINITION(mod_say_ru, mod_say_ru_load, NULL, NULL);
@ -253,8 +257,7 @@ static switch_status_t ru_say_money(switch_say_file_handle_t *sh, char *tosay, s
int iruble = 0;
int ikopecks = 0;
int ikopeck = 0;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n", tosay);
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s say_opt->currency=%d\n", tosay,say_opt->currency);
if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1))) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
@ -278,40 +281,48 @@ static switch_status_t ru_say_money(switch_say_file_handle_t *sh, char *tosay, s
rubles++;
}
ru_say_count(sh, rubles, male, nominativus);
ru_say_count(sh, rubles, matrix_currency[say_opt->currency].first_gender,matrix_currency[say_opt->currency].first_cases);
if (rubles) {
irubles = atoi(rubles) % 100;
iruble = atoi(rubles) % 10;
}
if (irubles == 1 || (irubles > 20 && iruble == 1)) { /* рубль */
switch_say_file(sh, "currency/ruble");
} else if ((irubles > 1 && irubles < 5) || (irubles > 20 && iruble > 1 && iruble < 5)) { /*рубля */
switch_say_file(sh, "currency/ruble-a");
} else { /*рублей */
switch_say_file(sh, "currency/rubles");
if (iruble<5) {
if ((irubles>10)&&(irubles<15)) {
switch_say_file(sh, "currency/%s",matrix_currency->first[5]);
}
else {
switch_say_file(sh, "currency/%s",matrix_currency->first[iruble]);
}
}
else {
switch_say_file(sh, "currency/%s",matrix_currency->first[5]);
}
/* Say kopecks */
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %s\n", kopecks);
ru_say_count(sh, kopecks, female, nominativus);
ru_say_count(sh, kopecks, matrix_currency[say_opt->currency].second_gender,matrix_currency[say_opt->currency].second_cases);
if (kopecks) {
ikopecks = atoi(kopecks) % 100;
ikopeck = atoi(kopecks) % 10;
}
if (ikopecks == 1 || (ikopecks > 20 && ikopeck == 1)) {
/* копейка */
switch_say_file(sh, "currency/kopeck");
} else if ((ikopecks > 1 && ikopecks < 5) || (ikopecks > 20 && ikopeck > 1 && ikopeck < 5)) {
/* копейки */
switch_say_file(sh, "currency/kopeck-i");
} else {
/* копеек */
switch_say_file(sh, "currency/kopecks");
if (ikopeck<5) {
if ((ikopecks>10)&&(ikopecks<15)) {
switch_say_file(sh, "currency/%s",matrix_currency->second[5]);
}
else {
switch_say_file(sh, "currency/%s",matrix_currency->second[ikopeck]);
}
}
else {
switch_say_file(sh, "currency/%s",matrix_currency->second[5]);
}
return SWITCH_STATUS_SUCCESS;
}
@ -628,7 +639,9 @@ static switch_status_t run_callback(switch_new_say_callback_ru_t say_cb, char *t
const char *gender=NULL;
const char *currency=NULL;
say_opt_t say_opt;
say_opt.cases=0;
say_opt.gender=0;
say_opt.currency=0;
if (session) {
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_get_variables(channel, &var_event);
@ -692,12 +705,15 @@ static switch_status_t run_callback(switch_new_say_callback_ru_t say_cb, char *t
}
if (currency) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!! %s!\n", currency);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!! %s!\n", currency);
if (strcmp(currency,"rubl") || strcmp(currency,"рубль")) {
if ((strcmp(currency,"ruble")==0) || (strcmp(currency,"рубль")==0)) {
say_opt.currency=(currency_t)0;
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "rul!!! \n");
}
if (strcmp(gender,"dollar") || strcmp(gender,"доллар")) {
if ((strcmp(currency,"dollar")==0) || (strcmp(currency,"доллар")==0)) {
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "dollar!!! !\n");
say_opt.currency=(currency_t)1;
}
}

View File

@ -49,10 +49,12 @@ typedef enum {
typedef enum {
ruble,
dollar
dollar,
euro
} currency_t;
typedef struct {
say_gender_t gender;
cases_t cases;
@ -66,6 +68,29 @@ struct say_t {
char *million[14];
int all;
};
struct say_cur_t {
char *first[6];
say_gender_t first_gender;
cases_t first_cases;
char *second[6];
say_gender_t second_gender;
cases_t second_cases;
};
// описываем как произносить валяюты от 0 до 5 дальше идёт номер рода и падежа (с нуля)
//рубли
#define c_0 {{"rubles","ruble","ruble-a","ruble-a","ruble-a","rubles"},male,nominativus,\
{"kopecks","kopeck","kopeck-i","kopeck-i","kopeck-i","kopecks"},female,nominativus}
#define c_1 {{"dollars","dollar","dollara","dollara","dollara","dollars"},male,nominativus,\
{"centov","cent","centa","centa","centa","centov"},male,nominativus}
#define c_2 {{"rubles","ruble","ruble-a","ruble-a","ruble-a","rubles"},male,nominativus,\
{"kopecks","kopeck","kopeck-i","kopeck-i","kopeck-i","kopecks"},female,nominativus}
typedef switch_status_t (*switch_new_say_callback_ru_t) (switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args,say_opt_t *say_opt);