Skip to main content

mod_translate

About

This module was created to format numbers into a specified format (preferably e.164) for doing ENUM or LCR lookups, based on a set of regular expressions listed in translate.conf.xml. When used as a dialplan module, it can rewrite both the caller id number and destination number of the call before it reaches the XML dialplan, considerably simplifying dialplan and xml_curl configuration which in turn translates the values used in the CDR.

Click here to expand Table of Contents

Configuration

The configuration file allows for a number of profiles, each listing a number of regex rules which are processed in order. It appears that the first match is used. Here is an example configuration for translating numbers in the United Kingdom to E.164 format.

<include>
<configuration name="translate.conf" description="Number Translation Rules">
<profiles>
<profile name="GB">
<rule regex="^\+(\d+)$" replace="$1"/>
<rule regex="^00(\d+)$" replace="$1"/>
<rule regex="^0([1-9]\d+)$" replace="44$1"/>
<rule regex="^(\d+)$" replace="$1"/>
</profile>
</profiles>
</configuration>
</include>

API

from the cli:

translate <number> [<profile>]

If profile is not specified, it defaults to US

APP

The following will translate the destination number using the US profile defined in the translate.conf.xml

<action application="translate" data="${destination_number} US"/>

The result is stored in a new channel variable called translated which you can then use to transfer the call back to the dialplan

<action application="transfer" data="${translated}" />

It can also be used as part of a variable

<action application="set" data="effective_caller_id_number=${translate(${destination_number})}" />

Dialplan

The following example will translate the destination_number and caller_id_number from a call coming in on a sofia profile before it goes to the XML dialplan

<param name="dialplan" value="translate,XML"/>

Profile Resolution

The order the profiles are resolved in is as follows:

  1. Checks the following channel variables in this order:
    1. translate_profile
    2. country
    3. default_country
  2. Fall back to US