method getTranslationsTable documentation in bbn\Appui\I18n

function($id_project, $id_option) { if (!empty($id_option) && ($o = $this->options->option($id_option)) ) { // @var $path_source_lang the property language of the id_option (the path) //on the option the property is language, on the project i18n $path_source_lang = $this->options->getProp($id_option, 'language'); // @var $to_explore the path to explore $to_explore = $this->getPathToExplore($id_option); //the path of the locale dirs $locale_dir = $this->getLocaleDirPath($id_option); $languages = array_map( function ($a) { return X::basename($a); }, bbn\File\Dir::getDirs($locale_dir) ) ?: []; $i = 0; $res = []; $project = new Project($this->db, $id_project); $errors = []; if (!empty($languages)) { $po_file = []; $success = false; foreach ($languages as $lng){ // the path of po and mo files $idx = is_file($locale_dir.'/index.txt') ? file_get_contents($locale_dir.'/index.txt') : ''; $po = $locale_dir.'/'.$lng.'/LC_MESSAGES/'.$o['text'].$idx.'.po'; $mo = $locale_dir.'/'.$lng.'/LC_MESSAGES/'.$o['text'].$idx.'.mo'; // if the file po exist takes its content if (file_exists($po)) { $fileHandler = new \Sepia\PoParser\SourceHandler\FileSystem($po); $poParser = new \Sepia\PoParser\Parser($fileHandler); $Catalog = \Sepia\PoParser\Parser::parseFile($po); if (!empty($translations = $Catalog->getEntries())) { foreach ($translations as $i => $t){ // @var $original the original expression $id = null; if ($original = stripslashes($t->getMsgId())) { $idx = \bbn\X::find($res, ['exp' => $original]); if ($idx !== null) { $todo = false; $row =& $res[$idx]; } else{ $todo = true; $row = []; } // the translation of the string found in the po file if (isset($row['id'])) { $id = $row['id']; } // @var $id takes the id of the original expression in db if (!isset($id) && !($id = $this->db->selectOne( 'bbn_i18n', 'id', [ 'exp' => $original, 'lang' => $path_source_lang ] )) ) { if (!$this->db->insertIgnore( 'bbn_i18n', [ 'exp' => $original, 'lang' => $path_source_lang ] ) ) { throw new \Exception( sprintf( _("Impossible to insert the original string %s in the original language %s"), $original, $path_source_lang ) ); } else { $id = $this->db->lastId(); } } if ($id) { $row[$lng.'_po'] = stripslashes($t->getMsgStr()); $row[$lng.'_db'] = $this->db->selectOne('bbn_i18n_exp', 'expression', ['id_exp' => $id, 'lang' => $lng]); if ($row[$lng.'_po'] && !$row[$lng.'_db']) { if ((($row[$lng.'_db'] === false) && $this->db->insert( 'bbn_i18n_exp', [ 'expression' => $row[$lng.'_po'], 'id_exp' => $id, 'lang' => $lng ] )) || $this->db->update( 'bbn_i18n_exp', [ 'expression' => $row[$lng.'_po'] ], [ 'id_exp' => $id, 'lang' => $lng ] ) ) { $row[$lng.'_db'] = $row[$lng.'_po']; } else{ throw new \Exception( sprintf( _("Impossible to insert or update the expression \"%s\" in %s"), $row[$lng.'_po'], $lng ) ); } } if (empty($row[$lng.'_db'])) { $row[$lng.'_db'] = ''; // die(var_dump($row[$lng.'_db'])); } if ($todo) { $row['id_exp'] = $id; $row['paths'] = []; $row['exp'] = $original; // @var (array) takes $paths of files in which the string was found from the file po $paths = $t->getReference(); // get the url to use it for the link to ide from the table foreach ($paths as $p) { $row['paths'][] = $project->realToUrl($p); } // the number of times the strings is found in the files of the path $row['occurrence'] = count($row['paths']); $res[] = $row; } } else{ die("Error 2"); } } } $success = true; } } } } return [ 'path_source_lang' => $path_source_lang, 'path' => $o['text'], 'success' => $success, 'languages' => $languages, 'total' => count(array_values($po_file)), 'strings' => $res, 'id_option' => $id_option, 'errors' => $errors ]; } }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.