/**
 * This function get the URL of the translation of an URL. It retrieve the URL from the mapping saved in the options page.
 *
 * @param $url string URL of the page to get the translation.
 * @param $language string language of translation. If it is null or invalid, current language loaded in the page is used.
 *
 * @return string it returns the URL of the translation or false if the URL isn't contained in the mapping.
 */
function uls_get_url_map_translation($url, $language = null)
{
    //get language
    if (!uls_valid_language($language)) {
        $language = uls_get_user_language();
    }
    //get the mappging
    $options = get_option('uls_settings');
    if (isset($options['translation_mapping'][$language][$url])) {
        return $options['translation_mapping'][$language][$url];
    }
    return false;
}
/**
 * Get the language of a post.
 *
 * @param $id integer id of the post.
 *
 * @return string the code of the language or an empty string if the post doesn't have a language.
 */
function uls_get_post_language($id)
{
    $postLanguage = get_post_meta($id, 'uls_language', true);
    if ("" == $postLanguage) {
        return "";
    }
    //format the language code
    $p = strpos($postLanguage, "_");
    if ($p !== false) {
        $postLanguage = substr($postLanguage, 0, $p) . strtoupper(substr($postLanguage, $p));
    }
    //validate the language
    if (uls_valid_language($postLanguage)) {
        return $postLanguage;
    }
    return "";
}