Skip to content

Commit 26987ae

Browse files
authored
Check For and Eliminate Octal Literals (#3682)
* 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.
1 parent b879cdd commit 26987ae

File tree

12 files changed

+432
-407
lines changed

12 files changed

+432
-407
lines changed

.php-cs-fixer.dist.php

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
'not_operator_with_successor_space' => false, // idem
135135
'nullable_type_declaration_for_default_null_value' => true,
136136
'object_operator_without_whitespace' => true,
137+
'octal_notation' => true,
137138
'ordered_class_elements' => false, // We prefer to keep some freedom
138139
'ordered_imports' => true,
139140
'ordered_interfaces' => true,

infra/LocaleGenerator.php

+23-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class LocaleGenerator
2121

2222
private const ARGUMENT_SEPARATOR_ROW = 5;
2323
private const ERROR_CODES_FIRST_ROW = 8;
24+
private const CURRENCY_SYMBOL_ROW = 19;
2425

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

106107
$this->writeConfigArgumentSeparator($configFile, $column);
108+
$this->writeConfigCurrencySymbol($configFile, $column);
107109
$this->writeFileSectionHeader($configFile, 'Error Codes');
108110

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

139+
protected function writeConfigCurrencySymbol($configFile, $column): void
140+
{
141+
$translationCell = $this->localeTranslations->getCell($column . self::CURRENCY_SYMBOL_ROW);
142+
$localeValue = $translationCell->getValue();
143+
if (!empty($localeValue)) {
144+
$functionTranslation = "currencySymbol = {$localeValue}" . self::EOL;
145+
fwrite($configFile, '##' . self::EOL);
146+
fwrite($configFile, '## (For future use)' . self::EOL);
147+
fwrite($configFile, '##' . self::EOL);
148+
fwrite($configFile, $functionTranslation);
149+
} else {
150+
$this->log('No Currency Symbol defined');
151+
}
152+
}
153+
137154
protected function buildFunctionsFileForLocale($column, $locale): void
138155
{
139156
$language = $this->functionNameTranslations->getCell($column . self::ENGLISH_LANGUAGE_NAME_ROW)->getValue();
@@ -164,7 +181,7 @@ protected function openConfigFile(string $locale, string $language, string $loca
164181
$this->log("Building locale {$locale} ($language) configuration");
165182
$localeFolder = $this->getLocaleFolder($locale);
166183

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

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

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

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

190207
protected function getLocaleFolder(string $locale): string
191208
{
209+
$lastchar = substr($this->translationBaseFolder, -1);
210+
$dirsep = ($lastchar === '/' || $lastchar === '\\') ? '' : DIRECTORY_SEPARATOR;
192211
$localeFolder = $this->translationBaseFolder .
193-
DIRECTORY_SEPARATOR .
212+
$dirsep .
194213
str_replace('_', DIRECTORY_SEPARATOR, $locale);
195214
if (!file_exists($localeFolder) || !is_dir($localeFolder)) {
196-
mkdir($localeFolder, 0777, true);
215+
mkdir($localeFolder, 7 * 64 + 7 * 8 + 7, true); // octal 777
197216
}
198217

199218
return $localeFolder;
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1+
############################################################
12
##
2-
## PhpSpreadsheet
3+
## PhpSpreadsheet - locale settings
34
##
5+
## български (Bulgarian)
46
##
5-
##
6-
7-
8-
ArgumentSeparator = ;
9-
7+
############################################################
108

9+
ArgumentSeparator = ;
1110
##
12-
## (For future use)
11+
## (For future use)
1312
##
14-
currencySymbol = лв
15-
13+
currencySymbol = лв
1614

1715
##
18-
## Excel Error Codes (For future use)
19-
16+
## Error Codes
2017
##
21-
NULL = #ПРАЗНО!
22-
DIV0 = #ДЕЛ/0!
23-
VALUE = #СТОЙНОСТ!
24-
REF = #РЕФ!
25-
NAME = #ИМЕ?
26-
NUM = #ЧИСЛО!
27-
NA = #Н/Д
18+
NULL = #ПРАЗНО!
19+
DIV0 = #ДЕЛ/0!
20+
VALUE = #СТОЙНОСТ!
21+
REF = #РЕФ!
22+
NAME = #ИМЕ?
23+
NUM = #ЧИСЛО!
24+
NA = #Н/Д

0 commit comments

Comments
 (0)