diff --git a/src/switch_xml.c b/src/switch_xml.c index 26e4481b53..95c01bc10d 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -3213,7 +3213,7 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offse return time_match; } -SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { +SWITCH_DECLARE(switch_status_t) switch_xml_locate_language_ex(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { switch_status_t status = SWITCH_STATUS_FALSE; if (switch_xml_locate("languages", NULL, NULL, NULL, root, node, params, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { @@ -3270,6 +3270,24 @@ done: return status; } +SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { + switch_status_t status; + + if ((status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language)) != SWITCH_STATUS_SUCCESS) { + const char *str_language_dup = strdup(str_language); + char *secondary; + if ((secondary=strchr(str_language_dup, '-')) != NULL) { + *secondary++ = '\0'; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "language %s not found. trying %s by removing %s\n", str_language, str_language_dup, secondary); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "lang", str_language_dup); + status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language_dup); + } + switch_safe_free(str_language_dup); + } + + return status; +} + #ifdef WIN32 /* * globbing functions for windows, part of libc on unix, this code was cut and paste from