loadPo() public static method

Loads the text .po file and returns array of translations
public static loadPo ( string $filename ) : mixed
$filename string Text .po file to load
return mixed Array of translations on success or false on failure
 public function importPOFile($lang = 'ara')
 {
     $this->autoRender = false;
     $localDir = App::path('locales');
     $localDir = $localDir[0];
     $localeImportFile = $localDir . $this->convertLangCodeFromCoreToSchool($lang) . DS . 'LC_MESSAGES' . DS . 'update.po';
     if (is_file($localeImportFile)) {
         //echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type">';
         $translations = I18n::loadPo($localeImportFile);
         $saveData = array();
         $counter = 0;
         foreach ($translations as $tKey => $tValue) {
             if (!empty($tKey)) {
                 $saveData[$counter]['eng'] = $tKey;
                 $saveData[$counter][$lang] = $tValue;
                 $counter++;
             }
         }
         $data = $this->Translation->find('all');
         if (!empty($data)) {
             foreach ($saveData as $tKey => $tValue) {
                 $conditions = array('Translation.eng' => $tValue['eng']);
                 if ($this->Translation->hasAny($conditions)) {
                     $this->Translation->recursive = -1;
                     $transData = $this->Translation->findByEng($tValue['eng'], array('id'));
                     $saveData[$tKey]['id'] = $transData['Translation']['id'];
                 }
             }
         }
         if ($this->Translation->saveAll($saveData)) {
             return $this->redirect(array('action' => 'index', $lang));
         }
     }
 }
 public function beforeFilter()
 {
     $this->protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     $this->port = $_SERVER['SERVER_PORT'] == 80 ? false : ':' . $_SERVER['SERVER_PORT'];
     if (defined('PORTAL_DOMAIN')) {
         $pieces = parse_url(Router::url($this->here, true));
         if (defined('PK_DOMAIN') && $pieces['host'] == PK_DOMAIN) {
             $this->domainMode = 'PK';
             // only certain actions are allowed in this domain
             // for other actions we are immediatly redirecting to PORTAL_DOMAIN
             if (stripos($_SERVER['REQUEST_URI'], '/dane/gminy/903') === 0) {
                 $url = substr($_SERVER['REQUEST_URI'], 15);
                 if ($url[0] == ',') {
                     $p = strpos($url, '/');
                     $url = $p === false ? '' : substr($url, $p);
                 }
                 $this->redirect($this->protocol . PK_DOMAIN . $this->port . $url);
                 die;
             }
             if (preg_match('/^(.*?)\\,([a-z0-9\\-]+)$/', $this->here, $match)) {
                 $this->redirect($this->protocol . PK_DOMAIN . $this->port . $match[1]);
                 die;
             }
             $_id = strtolower($this->request->params['plugin'] . '.' . $this->request->params['controller']);
             $cross_domain = (stripos($_SERVER['REQUEST_URI'], '/cross-domain-') === 0 or stripos($_SERVER['REQUEST_URI'], '/login') === 0 or stripos($_SERVER['REQUEST_URI'], '/logout') === 0);
             if (!in_array($_id, array('dane.gminy', 'dane.highstock_browser', 'powiadomienia.powiadomienia', 'subscriptions.subscriptions', 'pisma.pisma', 'pisma.szablony', 'zamowieniapubliczne.zamowieniapubliczne', 'finanse.gminy')) && !$cross_domain) {
                 $url = $_SERVER['REQUEST_URI'];
                 if ($url[0] == ',') {
                     $p = strpos($url, '/');
                     $url = $p === false ? '' : substr($url, $p);
                 }
                 return $this->redirect($this->protocol . PORTAL_DOMAIN . $this->port . $url);
             }
         } elseif ($pieces['host'] != PORTAL_DOMAIN) {
             $this->redirect($this->protocol . PORTAL_DOMAIN . $this->port . $this->here, 301);
             die;
         }
     }
     $this->response->header('Access-Control-Allow-Origin', $this->request->header('Origin'));
     $this->response->header('Access-Control-Allow-Credentials', true);
     $redirect = false;
     if ($this->Session->read('Auth.User.id') && $this->Session->read('Pisma.transfer_anonymous')) {
         $this->loadModel('Pisma.Pismo');
         $this->Pismo->transfer_anonymous($this->Session->read('previous_id'));
         $this->Session->delete('Pisma.transfer_anonymous');
         $redirect = true;
     }
     if ($redirect) {
         return $this->redirect($this->request->here);
     }
     # assigning translations for javascript use
     if ($this->params->plugin) {
         $path = ROOT . DS . APP_DIR . DS . 'Plugin' . DS . Inflector::camelize($this->params->plugin) . DS . 'Locale' . DS . Configure::read('Config.language') . DS . 'LC_MESSAGES' . DS . Inflector::underscore($this->params->plugin) . '.po';
     } else {
         $path = ROOT . DS . APP_DIR . DS . 'Locale' . DS . Configure::read('Config.language') . DS . 'LC_MESSAGES' . DS . 'default.po';
     }
     if (file_exists($path)) {
         $translations = I18n::loadPo($path);
         foreach ($translations as &$item) {
             $item = stripslashes($item);
             $item = preg_replace('/"/', '&quot;', $item);
         }
     } else {
         $translations = array();
     }
     $this->set('translation', $translations);
     parent::beforeFilter();
     $this->Auth->allow();
     $this->set('statusbarCrumbs', $this->statusbarCrumbs);
     $this->set('statusbarMode', $this->statusbarMode);
     $this->set('_APPLICATIONS', $this->getApplications());
     $this->set('_APPLICATION', $this->getApplication());
     $this->set('domainMode', $this->domainMode);
     //		// remember path for redirect if necessary
     //		if ( Router::url( null ) != '/null' ) { // hack for bug
     //			$this->Session->write( 'Auth.loginRedirect', Router::url( null, true ) );
     //		}
     // cross domain login
     $this->set('current_host', $_SERVER['HTTP_HOST']);
     if ($this->Session->check('crossdomain_login_token')) {
         $this->set('crossdomain_login_token', $this->Session->read('crossdomain_login_token'));
         $this->Session->delete('crossdomain_login_token');
     }
     if ($this->Session->check('crossdomain_logout')) {
         $this->set('crossdomain_logout', $this->Session->read('crossdomain_logout'));
         $this->Session->delete('crossdomain_logout');
     }
     $this->set('isAdmin', $this->hasUserRole('2'));
 }