/**
     * Builds human readable locale name in "<Native name> (<code>)" format.
     *
     * @param string $locale Locale code according to RFC 5646.
     * @return string Human readable locale name.
     */
    protected function getLocaleName($locale)
    {
        $locale_info = get_locale_info($locale);

        return $locale_info
            ? sprintf('%s (%s)', $locale_info['name'], $locale)
            : $locale;
    }
示例#2
0
 /**
  * Renders template file to HTML.
  *
  * @param string $template_name Name of the template file with neither path
  *   nor extension.
  * @param array $data Associative array of values that should be used for
  *   substitutions in a template.
  * @return string Rendered template.
  */
 public function render($template_name, $data = array())
 {
     // Pass additional variables to template
     $data['mibewVersion'] = MIBEW_VERSION;
     $data['currentLocale'] = get_current_locale();
     $locale_info = get_locale_info(get_current_locale());
     $data['rtl'] = $locale_info && $locale_info['rtl'];
     $data['stylePath'] = $this->getFilesPath();
     $data['styleName'] = $this->getName();
     return $this->getHandlebars()->render($template_name, $data);
 }
 /**
  * Generates list of available canned messages.
  *
  * @param Request $request
  * @return string Rendered page content
  */
 public function indexAction(Request $request)
 {
     $operator = $this->getOperator();
     $page = array('errors' => array());
     // Build list of available locales
     $all_locales = get_available_locales();
     $locales_with_label = array();
     foreach ($all_locales as $id) {
         $locale_info = get_locale_info($id);
         $locales_with_label[] = array('id' => $id, 'name' => $locale_info ? $locale_info['name'] : $id);
     }
     $page['locales'] = $locales_with_label;
     // Get selected locale, if any.
     $lang = $this->extractLocale($request);
     if (!$lang) {
         $lang = in_array(get_current_locale(), $all_locales) ? get_current_locale() : $all_locales[0];
     }
     // Get selected group ID, if any.
     $group_id = $this->extractGroupId($request);
     if ($group_id) {
         $group = group_by_id($group_id);
         if (!$group) {
             $page['errors'][] = getlocal('No such group');
             $group_id = false;
         }
     }
     // Build list of available groups
     $all_groups = in_isolation($operator) ? get_groups_for_operator($operator) : get_all_groups();
     $page['groups'] = array();
     $page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal('-all operators-'), 'level' => 0);
     foreach ($all_groups as $g) {
         $page['groups'][] = $g;
     }
     // Get messages and setup pagination
     $canned_messages = load_canned_messages($lang, $group_id);
     foreach ($canned_messages as &$message) {
         $message['vctitle'] = $message['vctitle'];
         $message['vcvalue'] = $message['vcvalue'];
     }
     unset($message);
     $pagination = setup_pagination($canned_messages);
     $page['pagination'] = $pagination['info'];
     $page['pagination.items'] = $pagination['items'];
     // Buil form values
     $page['formlang'] = $lang;
     $page['formgroup'] = $group_id;
     // Set other needed page values and render the response
     $page['title'] = getlocal('Canned Messages');
     $page['menuid'] = 'canned';
     $page = array_merge($page, prepare_menu($operator));
     return $this->render('canned_messages', $page);
 }
 /**
  * Renders list a of all mail templates which are available in the system.
  *
  * @param Request $request Incoming request.
  * @return Rendered page content.
  */
 public function indexAction(Request $request)
 {
     $operator = $this->getOperator();
     $page = array();
     // Build list of available locales
     $all_locales = get_available_locales();
     $locales_with_label = array();
     foreach ($all_locales as $id) {
         $locale_info = get_locale_info($id);
         $locales_with_label[] = array('id' => $id, 'name' => $locale_info ? $locale_info['name'] : $id);
     }
     $page['locales'] = $locales_with_label;
     // Get selected locale.
     $lang = $this->extractLocale($request);
     $page['stored'] = $request->query->has('stored');
     $page['formaction'] = $this->generateUrl('mail_templates');
     $page['mailTemplates'] = $this->getMailTemplatesList($lang);
     $page['formlang'] = $lang;
     $page['title'] = getlocal('Mail templates');
     $page['menuid'] = 'mail_templates';
     $page = array_merge($page, prepare_menu($operator));
     return $this->render('mail_templates', $page);
 }
示例#5
0
function get_locale_links()
{
    // Get list of available locales
    $locale_links = array();
    $all_locales = get_available_locales();
    if (count($all_locales) < 2) {
        return null;
    }
    // Attache locale names
    foreach ($all_locales as $k) {
        $locale_info = get_locale_info($k);
        $locale_links[$k] = $locale_info ? $locale_info['name'] : $k;
    }
    return $locale_links;
}
示例#6
0
/**
 * Format date according to passed in type and locale.
 *
 * @param int $timestamp Unix timestamp
 * @param string $format Format name. Can be one of "full", "date", "time".
 * @param string|null $locale Locale code. If null is passed in the current
 *   locale will be used.
 * @return string Formatted date.
 * @throws \InvalidArgumentException If $type argument has wrong value.
 */
function format_date($timestamp, $format, $locale = null)
{
    if (is_null($locale)) {
        $locale = get_current_locale();
    }
    // Get locale info
    $locale_info = get_locale_info($locale);
    $date_format = $locale_info['date_format'];
    if (!isset($date_format[$format])) {
        throw new \InvalidArgumentException('Wrong value of the $format argument.');
    }
    // Use correct months names and over translatable date/time strings.
    setlocale(LC_TIME, $locale_info['time_locale']);
    return strftime($date_format[$format], $timestamp);
}
示例#7
0
 /**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\Localization\LocaleController::showEditFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  * @throws NotFoundException If the locale with specified code is not found
  *   in the system.
  */
 public function submitEditFormAction(Request $request)
 {
     csrf_check_token($request);
     $errors = array();
     $locale = $request->attributes->get('locale');
     $time_locale = $request->request->get('timelocale');
     $date_format_full = $request->request->get('dateformatfull');
     $date_format_date = $request->request->get('dateformatdate');
     $date_format_time = $request->request->get('dateformattime');
     if (!$locale) {
         throw new NotFoundException();
     }
     if (!$time_locale) {
         $errors[] = no_field('Time locale');
     }
     if (!$date_format_full) {
         $errors[] = no_field('Date format (full)');
     }
     if (!$date_format_date) {
         $errors[] = no_field('Date format (date)');
     }
     if (!$date_format_time) {
         $errors[] = no_field('Date format (time)');
     }
     if (count($errors) != 0) {
         $request->attributes->set('errors', $errors);
         // The form should be rebuild. Invoke appropriate action.
         return $this->showEditFormAction($request);
     }
     $locale_info = get_locale_info($locale);
     $locale_info['time_locale'] = $time_locale;
     $locale_info['date_format'] = array('full' => $date_format_full, 'date' => $date_format_date, 'time' => $date_format_time);
     // Save the locale
     set_locale_info($locale, $locale_info);
     // Redirect the user to edit page again to use GET method instead of
     // POST.
     $redirect_to = $this->generateUrl('locale_edit', array('locale' => $locale, 'stored' => true));
     return $this->redirect($redirect_to);
 }