Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 64 additions & 31 deletions build/helpTOC.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,61 +87,73 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in

$io->comment('Fetching data from docs wiki');

// Get the category members (local hack)
$categoryMembers = $mediawiki->categories->getCategoryMembers(
sprintf('Category:Help_screen_%s.%s', Version::MAJOR_VERSION, Version::MINOR_VERSION),
null,
'max'
);

$members = [];

// Loop through the result objects to get every document
foreach ($categoryMembers->query->categorymembers as $catmembers) {
foreach ($catmembers as $member) {
$members[] = (string) $member['title'];
}
}
$cleanMembers = [];

// Get the language object
$language = Factory::getLanguage();
$io->comment(sprintf('Loop through docs wiki categories since Joomla Version %d.0 - Takes a while ...', Version::MAJOR_VERSION));

/*
* Now we start fancy processing so we can get the language key for the titles
*/
// Loop through the Versions since 5.0 to get all HelpTocs - Temporary fix
for ($helpScreenMinor=Version::MINOR_VERSION; $helpScreenMinor >= 0; $helpScreenMinor--) {

$cleanMembers = [];
// Get the category members (local hack)
$categoryMembers = $mediawiki->categories->getCategoryMembers(
sprintf('Category:Help_screen_%s.%s', Version::MAJOR_VERSION, $helpScreenMinor),
null,
'max'
);

// Strip the namespace prefix off the titles and replace spaces with underscores
$namespace = sprintf('Help%d.x:', Version::MAJOR_VERSION);
$members = [];

foreach ($members as $member) {
$cleanMembers[] = str_replace([$namespace, ' '], ['', '_'], $member);
// Loop through the result objects to get every document
foreach ($categoryMembers->query->categorymembers as $catmembers) {
foreach ($catmembers as $member) {
$members[] = (string) $member['title'];
}
}

/*
* Now we start fancy processing so we can get the language key for the titles
*/

// Strip the namespace prefix off the titles and replace spaces with underscores
$namespace = sprintf('Help%d.x:', Version::MAJOR_VERSION);

foreach ($members as $member) {
$cleanMembers[str_replace([$namespace, ' '], ['', '_'], $member)] = trim(str_replace($namespace, ' ', $member));
}
}

// Make sure we only have an array of unique values before continuing

$cleanMembers = array_unique($cleanMembers);

// Get the language object
$language = Factory::getLanguage();

// Load the admin com_admin language file
$language->load('com_admin', JPATH_ADMINISTRATOR);

$toc = [];
$toc = [];
$missing = [];

// filter for translated Media-Wiki articles
$translationLanguages = ['/de', '/en', '/fr', '/nl', '/pt-br', '/es', '/pt', '/it'];

foreach ($cleanMembers as $key => $value) {
$string = strtoupper($value);
$string = strtoupper($key);

// Validate the key exists
$io->comment(sprintf('Validating key COM_ADMIN_HELP_%s', $string));

if ($language->hasKey('COM_ADMIN_HELP_' . $string)) {
$io->comment(sprintf('Adding %s', $string));

$toc[$value] = $string;
$toc[$key] = $string;
} else {
// We check the string for words in singular/plural form and check again
$io->comment(sprintf('Inflecting %s', $string));

$inflected = '';

if (strpos($string, '_CATEGORIES') !== false) {
$inflected = str_replace('_CATEGORIES', '_CATEGORY', $string);
} elseif (strpos($string, '_USERS') !== false) {
Expand All @@ -150,8 +162,10 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
$inflected = str_replace('_CATEGORY', '_CATEGORIES', $string);
} elseif (strpos($string, '_USER') !== false) {
$inflected = str_replace('_USER', '_USERS', $string);
} else {
$inflected = '';
}

if ($inflected === '' && !\in_array(substr($value, strrpos($value, '/')), $translationLanguages)) {
$missing[$string] = $value;
}

// Now try to validate the key
Expand All @@ -161,7 +175,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
if ($language->hasKey('COM_ADMIN_HELP_' . $inflected)) {
$io->comment(sprintf('Adding %s', $inflected));

$toc[$value] = $inflected;
$toc[$key] = $inflected;
}
}
}
Expand All @@ -172,6 +186,25 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
// JSON encode the file and write it to JPATH_ADMINISTRATOR/help/en-GB/toc.json
file_put_contents(JPATH_ADMINISTRATOR . '/help/en-GB/toc.json', json_encode($toc));

if (\count($missing)) {

$str_missing = '';

foreach ($missing as $string => $value) {
$str_missing .= 'COM_ADMIN_HELP_' . $string . '="' . $value . '"'. PHP_EOL;
}

// write missing strings to JPATH_BASE/tmp/missing-helptoc.txt
file_put_contents(JPATH_BASE . '/tmp/missing-helptoc.txt', $str_missing);

$io->caution(sprintf('Number of media-wiki articles without string: %d', \count($missing)));

$io->note(sprintf('Missing strings are saved in: %s and should be revised and added to %s', 'tmp/missing-helptoc.txt', 'administrator/language/en-GB/com_admin.ini'));

$io->caution('TODO: For a complete TOC, please run this script again after adding the missing language strings!');

}

$io->success('Help Screen TOC written');

return 0;
Expand Down