method getTranslationsTableComplete documentation in bbn\Appui\I18n
Returns the informations relative to traslation of the given $id_option of a $id_project. The data is formatted to be shown in a table
function($id_project, $id_option)
{
if (!empty($id_option)
&& ($o = $this->options->option($id_option))
&& ($parent = $this->options->parent($id_option))
&& defined($parent['code'])
) {
// @var $path_source_lang the property language of the id_option (the path)
$path_source_lang = $this->options->getProp($id_option, 'language');
// @var $to_explore the path to explore
$to_explore = $this->getPathToExplore($id_option);
$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 bbn\Appui\Project($this->db, $id_project);
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
$original = $t->getMsgId();
$po_file[$i][$lng]['original'] = $original;
// the translation of the string found in the po file
$po_file[$i][$lng]['translations_po'] = $t->getMsgStr();
// @var $id takes the id of the original expression in db
if ($id = $this->db->selectOne(
'bbn_i18n',
'id',
[
'exp' => $original,
'lang' => $path_source_lang
]
)
) {
$po_file[$i][$lng]['translations_db'] = $this->db->selectOne('bbn_i18n_exp', 'expression', ['id_exp' => $id, 'lang' => $lng]);
// the id of the string
$po_file[$i][$lng]['id_exp'] = $id;
// @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){
$po_file[$i][$lng]['paths'][] = $project->real_to_url_i18n($p);
}
// the number of times the strings is found in the files of the path
$po_file[$i][$lng]['occurrence'] = !empty($po_file[$i][$path_source_lang]) ? count($po_file[$i][$path_source_lang]['paths']) : 0;
};
}
$success = true;
}
}
}
}
return [
'path_source_lang' => $path_source_lang,
'path' => $o['text'],
'success' => $success,
'languages' => $languages,
'total' => count(array_values($po_file)),
'strings' => array_values($po_file),
'id_option' => $id_option,
];
}
}
Returns the informations relative to traslation of the given $id_option of a $id_project. The data is formatted to be shown in a table 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.
© 2011-2023
BBN Solutions