How to localize the date pickers in back-end
From TomatoCMS Documentation
What's problem
How to localize the date pickers in back-end like this:
It's simple because the jQuery UI Datepicker already supports many languages. You can check the demo here.
Back to TomatoCMS, it's easy to make our datepickers localized, all we have to do is put the following line to the top of view script:
<?php $this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/i18n/ui.datepicker-ru.js'); ?>
If you don't want to add this line to separate scripts, well, we can add this line to the admin layout:
<?php $this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/i18n/ui.datepicker-ru.js'); ... ?> <?php echo $this->compressor('css'); ?> <?php echo $this->compressor('js'); ?> ...
This is not good solution due to three reasons:
- The website's language might be changed later
- It changed the code from TomatoCMS core and you may forget it when you upgrade TomatoCMS to newer version
- It's not easy for user to use, especially for normal users who are not programmers.
Therefore, we need to have general, better solution.
How to make it
If you are developer, we can create a plugin for this:
class Plugins_Localizer_Plugin extends Tomato_Controller_Plugin { public function postDispatch(Zend_Controller_Request_Abstract $request) { // ... Our code will go here ... } }
The purpose of this plugin is append the language data to head script, like what we did at the top of this post exactly. Well, it's easy:
1) First, we get the language and country code setting
$config = Tomato_Config::getConfig(); $lang = $config->web->lang;
2) Use Zend_Locale to get the language:
$locale = new Zend_Locale($lang); $language = $locale->getLanguage();
3) Check:
- if the language is one of jQuery UI supported languages
- we are in back-end section
then append the script to head section:
$file = '/js/jquery.ui/i18n/ui.datepicker-' . $language . '.js'; if (file_exists(TOMATO_ROOT_DIR . $file) && Zend_Layout::getMvcInstance() != null && 'admin' == Zend_Layout::getMvcInstance()->getLayout()) { /** * Get view instance */ $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $view = $viewRenderer->view; $view->headScript()->appendFile($config->web->static_server . $file); }
How to use it
I package this plugin, and attach to this post. To use it:
- Download the plugin and upload it to the plugin directory on your server
- Go to System > Extend > Plugin menu (I assume that you are already in the back-end section).
- Looking for a plugin named localizer and click on Install button.
That's all.
Now, come back to any page use datepicker (adding banner, for example), you will see that our datepickers now has been localized!


