<?php
/**
 * Url decorator for application language.
 *
 * @package MKLib
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * Adds language from the application into url. Url is mostly from application
 * router.
 *
 * @package MKLib
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class MKLib_UrlLangDecorator
{
    /**
     * default language identifier in an url
     */
    const DEFAULT_LANG = "cs";

    /**
     * Gets url decorated by current application language
     * @param string $url url which will be decorated (mostly from application router)
     * @param string $lang language identifier e.g. 'en'
     * @return string
     */
    public static function getUrl($url, $lang = self::DEFAULT_LANG)
    {
        if ($lang == self::DEFAULT_LANG) return $url;

        $baseUrl = MKLib_AppBaseUrl::getBaseUrl();
        if ($baseUrl == "/" || $baseUrl == "") return "/".$lang.$url;
        return str_replace($baseUrl, $baseUrl."/".$lang, $url);
    }
}
