diff --git a/app/sprinkles/core/src/Bakery/LocaleFixKeysCommand.php b/app/sprinkles/core/src/Bakery/LocaleFixKeysCommand.php
index 94e4659d6..cb9fcc209 100644
--- a/app/sprinkles/core/src/Bakery/LocaleFixKeysCommand.php
+++ b/app/sprinkles/core/src/Bakery/LocaleFixKeysCommand.php
@@ -24,37 +24,17 @@
*/
class LocaleFixKeysCommand extends LocaleMissingKeysCommand
{
- /**
- * @var string
- */
- protected static $baseLocale;
-
- /**
- * @var string
- */
- protected static $locales;
-
- /**
- * @var array
- */
- protected $filesFixed = [];
-
- /**
- * @var array
- */
- protected static $table = [];
-
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('locale:fix-keys')
- ->setHelp("This command generates missing keys for locale translation files. E.g. running 'locale:fix-keys -b en_US -f es_ES' will compare all es_ES and en_US locale files and populate es_ES with any missing keys from en_US.")
- ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale used to generate values for any keys that are fixed. ', 'en_US')
- ->addOption('fix', 'f', InputOption::VALUE_REQUIRED, 'One or more specific locales to fix. E.g. "fr_FR,es_ES" ', null);
-
- $this->setDescription('Fix locale missing files and key values');
+ ->setHelp("This command generates missing keys for locale translation files. E.g. running 'locale:fix-keys -b en_US -f es_ES' will compare all es_ES and en_US locale files and populate es_ES with any missing keys from en_US.")
+ ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale used to generate values for any keys that are fixed. ', 'en_US')
+ ->addOption('locale', 'l', InputOption::VALUE_REQUIRED, 'One or more specific locales to fix. E.g. "fr_FR,es_ES" ', null)
+ ->addOption('force', 'f', InputOption::VALUE_NONE, 'Do not display confirmation.')
+ ->setDescription('Fix locale missing files and key values');
}
/**
@@ -65,18 +45,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->io->title('Fixing Locale Keys');
// The "base" locale to compare other locales against. Defaults to en_US if not set.
- $this->baseLocale = $input->getOption('base');
+ $baseLocale = $input->getOption('base');
+ $baseLocaleFileNames = $this->getFilenames($baseLocale);
// Option -c. Set to compare one or more specific locales.
- $this->locales = $input->getOption('fix');
-
- $baseLocaleFileNames = $this->getFilenames($this->baseLocale);
+ $locales = $input->getOption('locale');
- $localesToFix = $this->getLocales($this->baseLocale);
+ // Get locales to fix
+ $localesToFix = $this->getLocales($baseLocale, $locales);
$this->io->note('Locales to be fixed: |' . implode('|', $localesToFix) . '|');
- if (!$this->io->confirm("All translation files for the locales above will be populated using key|values from | $this->baseLocale |. Continue?", false)) {
+ if (!$input->getOption('force') && !$this->io->confirm("All translation files for the locales above will be populated using key|values from | $baseLocale |. Continue?", false)) {
exit;
}
@@ -85,35 +65,45 @@ protected function execute(InputInterface $input, OutputInterface $output)
$progressBar = new ProgressBar($output);
$progressBar->start(count($localesToFix));
- foreach ($localesToFix as $key => $altLocale) {
- $fixed[$altLocale] = $this->fixFiles($this->baseLocale, $altLocale, $baseLocaleFileNames);
+ foreach ($localesToFix as $locale) {
+ $fixed[$locale] = $this->fixFiles($baseLocale, $locale, $baseLocaleFileNames);
$progressBar->advance();
}
- $this->io->newLine(2);
- $this->io->section('Files fixed');
- $this->getListValues($fixed);
+ $this->io->newLine(2);
- return $this->io->listing($this->filesFixed);
+ $filesFixed = $this->getListValues($fixed);
+ if (empty($filesFixed)) {
+ $this->io->success('No file need fixing');
+ } else {
+ $this->io->section('Files fixed');
+ $this->io->listing($filesFixed);
+ $this->io->success('Files fixed successfully');
+ }
}
/**
* Build a list of files that were fixed.
*
* @param array $array File paths and missing keys.
- * @param int $level Nested array depth.
+ *
+ * @return array A list of fixed files
*/
- protected function getListValues(array $array)
+ protected function getListValues(array $array): array
{
+ $fixed = [];
+
foreach ($array as $key => $value) {
if (is_array($value)) {
//We need to loop through it.
- $this->getListValues($value);
+ $fixed = array_merge($fixed, $this->getListValues($value));
} elseif ($value != '0') {
//It is not an array and not '0', so add it to the list.
- $this->filesFixed[] = $value;
+ $fixed[] = $value;
}
}
+
+ return $fixed;
}
/**
@@ -125,14 +115,17 @@ protected function getListValues(array $array)
*
* @return array Filepaths that were fixed.
*/
- protected function fixFiles($baseLocale, $altLocale, $filenames)
+ protected function fixFiles(string $baseLocale, string $altLocale, array $filenames): array
{
+ $fixed = [];
+
foreach ($filenames as $sprinklePath => $files) {
foreach ($files as $key => $file) {
- $base = $this->parseFile("$sprinklePath/locale/{$baseLocale}/{$file}");
- $alt = $this->parseFile("$sprinklePath/locale/{$altLocale}/{$file}");
- $filePath = "$sprinklePath/locale/{$altLocale}/{$file}";
- $missing = $this->arrayFlatten($this->getDifference($base, $alt));
+ $base = $this->parseFile("$sprinklePath/locale/$baseLocale/$file");
+ $alt = $this->parseFile("$sprinklePath/locale/$altLocale/$file");
+ $filePath = "$sprinklePath/locale/$altLocale/$file";
+ $diff = $this->getDifference($base, $alt);
+ $missing = $this->arrayFlatten($diff);
// The files with missing keys.
if (!empty($missing)) {
@@ -150,10 +143,11 @@ protected function fixFiles($baseLocale, $altLocale, $filenames)
* @param array $base
* @param array $alt
* @param string $filePath The path of fixed file.
+ * @param array $missing
*
- * @return string
+ * @return string The path of the fixed file
*/
- protected function fix($base, $alt, $filePath, $missing)
+ protected function fix(array $base, array $alt, string $filePath, array $missing): string
{
//If the directory does not exist we need to create it recursively.
if (!file_exists(dirname($filePath))) {
@@ -164,11 +158,7 @@ protected function fix($base, $alt, $filePath, $missing)
// Any keys not in the $alt locale will be the original left from the $base locales value.
$repository = new Repository();
$repository->mergeItems(null, $base);
-
- // If $alt is something other than string and we try to merge it in, $repository will become null.
- if (is_array($alt)) {
- $repository->mergeItems(null, $alt);
- }
+ $repository->mergeItems(null, $alt);
foreach ($missing as $key => $value) {
if (!$repository->has($key)) {
@@ -220,22 +210,22 @@ protected function fix($base, $alt, $filePath, $missing)
*
* @param string $file path of file to fix
*/
- public function fixFileWithPhpCs($file)
+ public function fixFileWithPhpCs(string $file): void
{
// Fix the file with php-cs-fixer
passthru("php ./app/vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix $file --quiet --using-cache no --config ./.php_cs");
}
/**
- * @return array Locales to check for missing keys.
+ * {@inheritdoc}
*/
- protected function getLocales($baseLocale)
+ protected function getLocales(string $baseLocale, ?string $localesToCheck): array
{
$configuredLocales = array_diff(array_keys($this->ci->config['site']['locales']['available']), [$baseLocale]);
// If set, use the locale(s) from the -f option.
- if ($this->locales) {
- $locales = explode(',', $this->locales);
+ if ($localesToCheck) {
+ $locales = explode(',', $localesToCheck);
foreach ($locales as $key => $value) {
if (!in_array($value, $configuredLocales)) {
$this->io->warning("The |$value| locale was not found in your current configuration. Proceeding may results in a large number of files being created. Are you sure you want to continue?");
@@ -245,7 +235,7 @@ protected function getLocales($baseLocale)
}
}
- return$locales;
+ return $locales;
} else {
return $configuredLocales;
}
diff --git a/app/sprinkles/core/src/Bakery/LocaleMissingKeysCommand.php b/app/sprinkles/core/src/Bakery/LocaleMissingKeysCommand.php
index ea2365171..d473eeeec 100644
--- a/app/sprinkles/core/src/Bakery/LocaleMissingKeysCommand.php
+++ b/app/sprinkles/core/src/Bakery/LocaleMissingKeysCommand.php
@@ -28,17 +28,12 @@ class LocaleMissingKeysCommand extends BaseCommand
/**
* @var string
*/
- protected $localesToCheck;
-
- /**
- * @var string
- */
- protected static $path;
+ protected $path;
/**
* @var array
*/
- protected static $table = [];
+ protected $table = [];
/**
* {@inheritdoc}
@@ -46,11 +41,10 @@ class LocaleMissingKeysCommand extends BaseCommand
protected function configure()
{
$this->setName('locale:missing-keys')
- ->setHelp("This command provides a summary of missing keys for locale translation files. E.g. running 'locale:missing-keys -b en_US -c es_ES' will compare all es_ES and en_US locale files and generate a table listing the filepath and missing keys found from the `-c` locale.")
- ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale to compare against.', 'en_US')
- ->addOption('check', 'c', InputOption::VALUE_REQUIRED, 'One or more specific locales to check. E.g. "fr_FR,es_ES"', null);
-
- $this->setDescription('Generate a table of missing locale keys.');
+ ->setHelp("This command provides a summary of missing keys for locale translation files. E.g. running 'locale:missing-keys -b en_US -c es_ES' will compare all es_ES and en_US locale files and generate a table listing the filepath and missing keys found from the `-c` locale.")
+ ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale to compare against.', 'en_US')
+ ->addOption('check', 'c', InputOption::VALUE_REQUIRED, 'One or more specific locales to check. E.g. "fr_FR,es_ES"', null)
+ ->setDescription('Generate a table of missing locale keys.');
}
/**
@@ -62,30 +56,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
// The "base" locale to compare other locales against. Defaults to en_US if not set.
$baseLocale = $input->getOption('base');
+ $baseLocaleFileNames = $this->getFilenames($baseLocale);
// Option -c. Set to compare one or more specific locales.
- $this->localesToCheck = $input->getOption('check');
+ $localesToCheck = $input->getOption('check');
- $baseLocaleFileNames = $this->getFilenames($baseLocale);
-
- $locales = $this->getLocales($baseLocale);
+ // Get locales to check
+ $locales = $this->getLocales($baseLocale, $localesToCheck);
$this->io->writeln('Locales to check: |' . implode('|', $locales) . '|');
-
$this->io->section("Searching for missing keys using $baseLocale for comparison.");
- foreach ($locales as $key => $altLocale) {
- $difference[] = $this->compareFiles($baseLocale, $altLocale, $baseLocaleFileNames);
+ foreach ($locales as $locale) {
+
+ // Make sure locale exist
+ if (!in_array($locale, array_keys($this->ci->config['site']['locales']['available']))) {
+ $this->io->warning("Locale '$locale' is not available in config.");
+ } else {
+ $difference[] = $this->compareFiles($baseLocale, $locale, $baseLocaleFileNames);
+ }
}
// Build the table.
if (!empty($difference[0])) {
$this->newTable($output);
-
$this->table->setHeaders(['File path', 'Missing key']);
-
$this->buildTable($difference);
-
$this->table->render();
} else {
$this->io->writeln('No missing keys found!');
@@ -95,14 +91,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* Flattens a nested array into dot syntax.
*
- * @param array $array The array to flatten.
+ * @param array $array The array to flatten.
+ * @param string $prefix (Default '')
*
* @return array Keys with missing values.
*/
- protected function arrayFlatten($array, $prefix = '')
+ protected function arrayFlatten(array $array, string $prefix = ''): array
{
$result = [];
- foreach ($array as $key=>$value) {
+ foreach ($array as $key => $value) {
if (is_array($value)) {
$result = $result + $this->arrayFlatten($value, $prefix . $key . '.');
} else {
@@ -119,7 +116,7 @@ protected function arrayFlatten($array, $prefix = '')
* @param array $array File paths and missing keys.
* @param int $level Nested array depth.
*/
- protected function buildTable(array $array, $level = 1)
+ protected function buildTable(array $array, int $level = 1): void
{
foreach ($array as $key => $value) {
//Level 2 has the filepath.
@@ -146,13 +143,14 @@ protected function buildTable(array $array, $level = 1)
*
* @return array The keys in $baseLocale that do not exist in $altLocale.
*/
- protected function compareFiles($baseLocale, $altLocale, $filenames)
+ protected function compareFiles(string $baseLocale, string $altLocale, array $filenames): array
{
foreach ($filenames as $sprinklePath => $files) {
foreach ($files as $key => $file) {
$base = $this->parseFile("$sprinklePath/locale/{$baseLocale}/{$file}");
$alt = $this->parseFile("$sprinklePath/locale/{$altLocale}/{$file}");
- $difference[$sprinklePath . '/locale' . '/' . $altLocale . '/' . $file] = $this->arrayFlatten($this->getDifference($base, $alt));
+ $diff = $this->getDifference($base, $alt);
+ $difference[$sprinklePath . '/locale' . '/' . $altLocale . '/' . $file] = $this->arrayFlatten($diff);
}
}
@@ -167,16 +165,21 @@ protected function compareFiles($baseLocale, $altLocale, $filenames)
*
* @return array
*/
- protected function getDifference($array1, $array2)
+ protected function getDifference(array $array1, array $array2): array
{
+ $difference = [];
+
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!isset($array2[$key])) {
$difference[$key] = $value;
} else {
- $new_diff = $this->getDifference($value, $array2[$key]);
- if ($new_diff != false) {
- $difference[$key] = $new_diff;
+ if (is_array($array2[$key])) {
+ $difference[$key] = $this->getDifference($value, $array2[$key]);
+ } else {
+ // If the second array returns a string for a key while
+ // the first is an array, the whole first array is considered missing
+ $difference[$key] = $value;
}
}
} elseif (!isset($array2[$key])) {
@@ -184,7 +187,7 @@ protected function getDifference($array1, $array2)
}
}
- return !isset($difference) ? 0 : $difference;
+ return $difference;
}
/**
@@ -194,9 +197,9 @@ protected function getDifference($array1, $array2)
*
* @return array Locale files and locations for the locale being compared against.
*/
- public function getFilenames($locale)
+ public function getFilenames(string $locale): array
{
- $file = ($this->ci->locator->listResources("locale://{$locale}", true));
+ $file = ($this->ci->locator->listResources("locale://$locale", true));
foreach ($file as $filename => $path) {
$files[$path->getLocation()->getPath()][] = $path->getBaseName();
}
@@ -205,13 +208,16 @@ public function getFilenames($locale)
}
/**
- * @return array Locales to check.
+ * @param string $baseLocale The "base" locale to compare to
+ * @param string|null $localesToCheck Comma delimited list of locales to check
+ *
+ * @return array Locales to check.
*/
- protected function getLocales($baseLocale)
+ protected function getLocales(string $baseLocale, ?string $localesToCheck): array
{
// If set, use the locale from the -c option.
- if ($this->localesToCheck) {
- return explode(',', $this->localesToCheck);
+ if ($localesToCheck) {
+ return explode(',', $localesToCheck);
} else {
//Need to filter the base locale to prevent false positive.
return array_diff(array_keys($this->ci->config['site']['locales']['available']), [$baseLocale]);
@@ -223,13 +229,12 @@ protected function getLocales($baseLocale)
*
* @param OutputInterface $output
*/
- protected function newTable($output)
+ protected function newTable(OutputInterface $output): void
{
$tableStyle = new TableStyle();
- $tableStyle
- ->setVerticalBorderChars(' ')
- ->setDefaultCrossingChar(' ')
- ->setCellHeaderFormat('%s');
+ $tableStyle->setVerticalBorderChars(' ')
+ ->setDefaultCrossingChar(' ')
+ ->setCellHeaderFormat('%s');
$this->table = new Table($output);
$this->table->setStyle($tableStyle);
@@ -239,9 +244,18 @@ protected function newTable($output)
* Access file contents through inclusion.
*
* @param string $path The path of file to be included.
+ *
+ * @return array The array returned in the included locale file
*/
- protected function parseFile($path)
+ protected function parseFile(string $path): array
{
- return include "$path";
+ $content = include "$path";
+
+ // Consider not found file returns an empty array
+ if ($content === false) {
+ return [];
+ }
+
+ return $content;
}
}
diff --git a/app/sprinkles/core/src/Bakery/LocaleMissingValuesCommand.php b/app/sprinkles/core/src/Bakery/LocaleMissingValuesCommand.php
index 4d1fcd374..27d64d699 100644
--- a/app/sprinkles/core/src/Bakery/LocaleMissingValuesCommand.php
+++ b/app/sprinkles/core/src/Bakery/LocaleMissingValuesCommand.php
@@ -10,8 +10,6 @@
namespace UserFrosting\Sprinkle\Core\Bakery;
-use Symfony\Component\Console\Helper\Table;
-use Symfony\Component\Console\Helper\TableStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,9 +26,9 @@
class LocaleMissingValuesCommand extends LocaleMissingKeysCommand
{
/**
- * @var string
+ * @var MessageTranslator
*/
- protected $localesToCheck;
+ protected $translator;
/**
* {@inheritdoc}
@@ -38,14 +36,13 @@ class LocaleMissingValuesCommand extends LocaleMissingKeysCommand
protected function configure()
{
$this->setName('locale:missing-values')
- ->setHelp("This command provides a summary of missing values for locale translation files. Missing keys are found by searching for empty and/or duplicate values. Either option can be turned off - see options for this command. E.g. running 'locale:missing-values -b en_US -c es_ES' will compare all es_ES and en_US locale files and find any values that are identical between the two locales, as well as searching all es_ES locale files for empty ('') values.")
- ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale used for comparison and translation preview.', 'en_US')
- ->addOption('check', 'c', InputOption::VALUE_REQUIRED, 'One or more specific locales to check. E.g. "fr_FR,es_ES"', null)
- ->addOption('length', 'l', InputOption::VALUE_REQUIRED, 'Set the length for preview column text.', 50)
- ->addOption('empty', 'e', InputOption::VALUE_NONE, 'Setting this will skip check for empty strings.')
- ->addOption('duplicates', 'd', InputOption::VALUE_NONE, 'Setting this will skip comparison check.');
-
- $this->setDescription('Generate a table of keys with missing values.');
+ ->setHelp("This command provides a summary of missing values for locale translation files. Missing keys are found by searching for empty and/or duplicate values. Either option can be turned off - see options for this command. E.g. running 'locale:missing-values -b en_US -c es_ES' will compare all es_ES and en_US locale files and find any values that are identical between the two locales, as well as searching all es_ES locale files for empty ('') values. This can be helpful to list all values in a specific languages that are present, but might need translation. For example, listing all English strings found in the French locale.")
+ ->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'The base locale used for comparison and translation preview.', 'en_US')
+ ->addOption('check', 'c', InputOption::VALUE_REQUIRED, 'One or more specific locales to check. E.g. "fr_FR,es_ES"', null)
+ ->addOption('length', 'l', InputOption::VALUE_REQUIRED, 'Set the length for preview column text.', 50)
+ ->addOption('empty', 'e', InputOption::VALUE_NONE, 'Setting this will skip check for empty strings.')
+ ->addOption('duplicates', 'd', InputOption::VALUE_NONE, 'Setting this will skip comparison check.')
+ ->setDescription('Generate a table of keys with missing values.');
}
/**
@@ -56,34 +53,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->io->title('Missing Locale Values');
// Option -c. The locales to be checked.
- $this->localesToCheck = $input->getOption('check');
+ $localesToCheck = $input->getOption('check');
// The locale for the 'preview' column. Defaults to en_US if not set.
$baseLocale = $input->getOption('base');
+ $baseLocaleFileNames = $this->getFilenames($baseLocale);
- $this->length = $input->getOption('length');
+ // Get `length` option
+ $length = $input->getOption('length');
+ // Set translator to base locale
$this->setTranslation($baseLocale);
- $locales = $this->getLocales($baseLocale);
-
+ // Get locales and files for said locales
+ $locales = $this->getLocales($baseLocale, $localesToCheck);
$files = $this->getFilePaths($locales);
- $baseLocaleFileNames = $this->getFilenames($baseLocale);
-
$this->io->writeln(['Locales to check: |' . implode('|', $locales) . '|']);
- if ($input->getOption('empty') != true) {
+ // Proccess empty
+ if ($input->getOption('empty') === false) {
$this->io->section('Searching for empty values.');
$missing[] = $this->searchFilesForNull($files);
if (!empty($missing[0])) {
- $this->newTable($output);
+ $this->newTable($output, $length);
$this->table->setHeaders([
- ['File path', 'Key', 'Translation preview'],
- ]);
+ ['File path', 'Key', 'Translation preview'],
+ ]);
// Build the table.
$this->buildTable($missing);
@@ -95,24 +94,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
- if ($input->getOption('duplicates') != true) {
+ if ($input->getOption('duplicates') === false) {
$this->io->section('Searching for duplicate values.');
- foreach ($locales as $key => $altLocale) {
- $duplicates[] = $this->compareFiles($baseLocale, $altLocale, $baseLocaleFileNames);
+ foreach ($locales as $locale) {
+ $duplicates[] = $this->compareFiles($baseLocale, $locale, $baseLocaleFileNames);
}
if (!empty($duplicates[0])) {
- $this->newTable($output);
+ $this->newTable($output, $length);
$this->table->setHeaders([
- ['File path', 'Key', 'Translation preview'],
- ]);
+ ['File path', 'Key', 'Translation preview'],
+ ]);
- $this->newTable($output);
+ $this->newTable($output, $length);
$this->table->setHeaders([
- ['File path', 'Key', 'Duplicate value'],
- ]);
+ ['File path', 'Key', 'Duplicate value'],
+ ]);
$this->buildTable($duplicates);
$this->table->render();
} else {
@@ -129,12 +128,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
*
* @return array Matching keys and values that are found in both arrays.
*/
- protected function arrayIntersect($primary_array, $secondary_array)
+ protected function arrayIntersect(array $primary_array, array $secondary_array): array
{
- if (!is_array($primary_array) || !is_array($secondary_array)) {
- return false;
- }
-
if (!empty($primary_array)) {
foreach ($primary_array as $key => $value) {
if (!isset($secondary_array[$key])) {
@@ -160,7 +155,7 @@ protected function arrayIntersect($primary_array, $secondary_array)
* @param array $array File paths and missing keys.
* @param int $level Nested array depth.
*/
- protected function buildTable(array $array, $level = 1)
+ protected function buildTable(array $array, int $level = 1): void
{
foreach ($array as $key => $value) {
//Level 2 has the filepath.
@@ -178,20 +173,14 @@ protected function buildTable(array $array, $level = 1)
}
/**
- * Iterate over sprinkle locale files and find duplicates.
- *
- * @param string $baseLocale Locale being compared against.
- * @param string $altLocale Locale to find missing values for.
- * @param array $filenames Sprinkle locale files that will be compared.
- *
- * @return array Intersect of keys with identical values.
+ * {@inheritdoc}
*/
- protected function compareFiles($baseLocale, $altLocale, $filenames)
+ protected function compareFiles(string $baseLocale, string $altLocale, array $filenames): array
{
foreach ($filenames as $sprinklePath => $files) {
foreach ($files as $key => $file) {
- $base = $this->arrayFlatten($this->parseFile("$sprinklePath/locale/{$baseLocale}/{$file}"));
- $alt = $this->arrayFlatten($this->parseFile("$sprinklePath/locale/{$altLocale}/{$file}"));
+ $base = $this->arrayFlatten($this->parseFile("$sprinklePath/locale/$baseLocale/$file"));
+ $alt = $this->arrayFlatten($this->parseFile("$sprinklePath/locale/$altLocale/$file"));
$missing[$sprinklePath . '/locale' . '/' . $altLocale . '/' . $file] = $this->arrayIntersect($base, $alt);
}
@@ -207,14 +196,15 @@ protected function compareFiles($baseLocale, $altLocale, $filenames)
*
* @see https://www.php.net/manual/en/function.empty.php#refsect1-function.empty-returnvalues
*
- * @param array $array Locale translation file.
+ * @param array $array Locale translation file.
+ * @param string $prefix
*
* @return array Keys with missing values.
*/
- protected function findMissing($array, $prefix = '')
+ protected function findMissing(array $array, string $prefix = ''): array
{
$result = [];
- foreach ($array as $key=>$value) {
+ foreach ($array as $key => $value) {
if (is_array($value)) {
$result = $result + $this->findMissing($value, $prefix . $key . '.');
} else {
@@ -225,8 +215,7 @@ protected function findMissing($array, $prefix = '')
// We only want empty values.
return array_filter($result, function ($val, $key) {
return empty($val) && strpos($key, '@') === false;
- },
- ARRAY_FILTER_USE_BOTH);
+ }, ARRAY_FILTER_USE_BOTH);
}
/**
@@ -236,7 +225,7 @@ protected function findMissing($array, $prefix = '')
*
* @return array
*/
- protected function getFilePaths($locale)
+ protected function getFilePaths(array $locale): array
{
// Set up a locator class
$locator = $this->ci->locator;
@@ -248,21 +237,12 @@ protected function getFilePaths($locale)
}
/**
- * Set up new table with Bakery formatting.
- *
- * @param OutputInterface $output
+ * {@inheritdoc}
*/
- protected function newTable($output)
+ protected function newTable(OutputInterface $output, int $length): void
{
- $tableStyle = new TableStyle();
- $tableStyle
- ->setVerticalBorderChars(' ')
- ->setDefaultCrossingChar(' ')
- ->setCellHeaderFormat('%s');
-
- $this->table = new Table($output);
- $this->table->setStyle($tableStyle);
- $this->table->setColumnMaxWidth(2, $this->length);
+ parent::newTable($output);
+ $this->table->setColumnMaxWidth(2, $length);
}
/**
@@ -272,9 +252,9 @@ protected function newTable($output)
*
* @return array
*/
- protected function searchFilesForNull($files)
+ protected function searchFilesForNull(array $files): array
{
- foreach ($files as $key => $file) {
+ foreach ($files as $file) {
$missing[$file] = $this->findMissing($this->parseFile($file));
if (empty($missing[$file])) {
@@ -290,7 +270,7 @@ protected function searchFilesForNull($files)
*
* @param string $locale Locale to be used for translation.
*/
- protected function setTranslation(string $locale)
+ protected function setTranslation(string $locale): void
{
// Setup the translator. Set with -b or defaults to en_US
$locator = $this->ci->locator;