Skip to content

Commit

Permalink
Check For and Eliminate Octal Literals (#3682)
Browse files Browse the repository at this point in the history
* Check For and Eliminate Octal Literals

Php8.1 introduced a new form of octal literal (0o123); the old form (0123) continues to be supported, but can certainly be misleading. There are exactly 6 uses of the old form in the code base (5 in tests, 1 in infra). 4 of these are clearly unintended (02 or 03), and the leading 0 should just be dropped for those. The other 2 are for file permissions and are easily replaced.

* Minor Changes to LocaleGenerator

Testing the permissions change exposed some problems when the locale files don't exist. This never shows up as an issue when the files do exist, which is pretty much all the time, but correct the theoretical exposures anyhow.

* Populate bg and en_uk Locale Files from Spreadsheet

Also rename locale generator so that it is executed first. This is when it should happen because other tests depend on its results.

* Some Bulgarian Function Omissions

Figured out a reasonable way to compare old Bulgarian function file to new; this identified a handful of now-corrected omissions and errors. Note that JIS function, in old list, is not on spreadsheet, but the Bulgarian translation is the same as English (so the translation isn't needed), and the function has been replaced by DBCS, which is also not on the spreadsheet.
  • Loading branch information
oleibman authored Aug 23, 2023
1 parent b879cdd commit 26987ae
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 407 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
'not_operator_with_successor_space' => false, // idem
'nullable_type_declaration_for_default_null_value' => true,
'object_operator_without_whitespace' => true,
'octal_notation' => true,
'ordered_class_elements' => false, // We prefer to keep some freedom
'ordered_imports' => true,
'ordered_interfaces' => true,
Expand Down
27 changes: 23 additions & 4 deletions infra/LocaleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LocaleGenerator

private const ARGUMENT_SEPARATOR_ROW = 5;
private const ERROR_CODES_FIRST_ROW = 8;
private const CURRENCY_SYMBOL_ROW = 19;

private const FUNCTION_NAME_LIST_FIRST_ROW = 4;
private const ENGLISH_FUNCTION_CATEGORIES_COLUMN = 'A';
Expand Down Expand Up @@ -104,6 +105,7 @@ protected function buildConfigFileForLocale($column, $locale): void
$configFile = $this->openConfigFile($locale, $language, $localeLanguage);

$this->writeConfigArgumentSeparator($configFile, $column);
$this->writeConfigCurrencySymbol($configFile, $column);
$this->writeFileSectionHeader($configFile, 'Error Codes');

foreach ($this->errorCodeMap as $errorCode => $row) {
Expand Down Expand Up @@ -134,6 +136,21 @@ protected function writeConfigArgumentSeparator($configFile, $column): void
}
}

protected function writeConfigCurrencySymbol($configFile, $column): void
{
$translationCell = $this->localeTranslations->getCell($column . self::CURRENCY_SYMBOL_ROW);
$localeValue = $translationCell->getValue();
if (!empty($localeValue)) {
$functionTranslation = "currencySymbol = {$localeValue}" . self::EOL;
fwrite($configFile, '##' . self::EOL);
fwrite($configFile, '## (For future use)' . self::EOL);
fwrite($configFile, '##' . self::EOL);
fwrite($configFile, $functionTranslation);
} else {
$this->log('No Currency Symbol defined');
}
}

protected function buildFunctionsFileForLocale($column, $locale): void
{
$language = $this->functionNameTranslations->getCell($column . self::ENGLISH_LANGUAGE_NAME_ROW)->getValue();
Expand Down Expand Up @@ -164,7 +181,7 @@ protected function openConfigFile(string $locale, string $language, string $loca
$this->log("Building locale {$locale} ($language) configuration");
$localeFolder = $this->getLocaleFolder($locale);

$configFileName = realpath($localeFolder . DIRECTORY_SEPARATOR . 'config');
$configFileName = realpath($localeFolder) . DIRECTORY_SEPARATOR . 'config';
$this->log("Writing locale configuration to {$configFileName}");

$configFile = fopen($configFileName, 'wb');
Expand All @@ -178,7 +195,7 @@ protected function openFunctionNameFile(string $locale, string $language, string
$this->log("Building locale {$locale} ($language) function names");
$localeFolder = $this->getLocaleFolder($locale);

$functionFileName = realpath($localeFolder . DIRECTORY_SEPARATOR . 'functions');
$functionFileName = realpath($localeFolder) . DIRECTORY_SEPARATOR . 'functions';
$this->log("Writing local function names to {$functionFileName}");

$functionFile = fopen($functionFileName, 'wb');
Expand All @@ -189,11 +206,13 @@ protected function openFunctionNameFile(string $locale, string $language, string

protected function getLocaleFolder(string $locale): string
{
$lastchar = substr($this->translationBaseFolder, -1);
$dirsep = ($lastchar === '/' || $lastchar === '\\') ? '' : DIRECTORY_SEPARATOR;
$localeFolder = $this->translationBaseFolder .
DIRECTORY_SEPARATOR .
$dirsep .
str_replace('_', DIRECTORY_SEPARATOR, $locale);
if (!file_exists($localeFolder) || !is_dir($localeFolder)) {
mkdir($localeFolder, 0777, true);
mkdir($localeFolder, 7 * 64 + 7 * 8 + 7, true); // octal 777
}

return $localeFolder;
Expand Down
Binary file modified src/PhpSpreadsheet/Calculation/locale/Translations.xlsx
Binary file not shown.
33 changes: 15 additions & 18 deletions src/PhpSpreadsheet/Calculation/locale/bg/config
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
############################################################
##
## PhpSpreadsheet
## PhpSpreadsheet - locale settings
##
## български (Bulgarian)
##
##


ArgumentSeparator = ;

############################################################

ArgumentSeparator = ;
##
## (For future use)
## (For future use)
##
currencySymbol = лв

currencySymbol = лв

##
## Excel Error Codes (For future use)

## Error Codes
##
NULL = #ПРАЗНО!
DIV0 = #ДЕЛ/0!
VALUE = #СТОЙНОСТ!
REF = #РЕФ!
NAME = #ИМЕ?
NUM = #ЧИСЛО!
NA = #Н/Д
NULL = #ПРАЗНО!
DIV0 = #ДЕЛ/0!
VALUE = #СТОЙНОСТ!
REF = #РЕФ!
NAME = #ИМЕ?
NUM = #ЧИСЛО!
NA = #Н/Д
Loading

0 comments on commit 26987ae

Please sign in to comment.