Skip to content

Commit d200c53

Browse files
authored
Locale Generator - Change to Use Unix Line Endings Even on Windows (PHPOffice#2174)
See issue PHPOffice#2172. The locale files are regenerated whenever the test suite is run. The use of PHP_EOL in LocaleGenerator.php is awkward on Windows systems, since it causes git to think the file has changed. Change to use `"\n"` instead.
1 parent 33ef03d commit d200c53

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

infra/LocaleGenerator.php

+16-15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class LocaleGenerator
2525
private const FUNCTION_NAME_LIST_FIRST_ROW = 4;
2626
private const ENGLISH_FUNCTION_CATEGORIES_COLUMN = 'A';
2727
private const ENGLISH_REFERENCE_COLUMN = 'B';
28+
private const EOL = "\n"; // not PHP_EOL
2829

2930
/**
3031
* @var string
@@ -109,10 +110,10 @@ protected function buildConfigFileForLocale($column, $locale): void
109110
$translationCell = $this->localeTranslations->getCell($column . $row);
110111
$translationValue = $translationCell->getValue();
111112
if (!empty($translationValue)) {
112-
$errorCodeTranslation = "{$errorCode} = {$translationValue}" . PHP_EOL;
113+
$errorCodeTranslation = "{$errorCode} = {$translationValue}" . self::EOL;
113114
fwrite($configFile, $errorCodeTranslation);
114115
} else {
115-
$errorCodeTranslation = "{$errorCode}" . PHP_EOL;
116+
$errorCodeTranslation = "{$errorCode}" . self::EOL;
116117
fwrite($configFile, $errorCodeTranslation);
117118
$this->log("No {$language} translation available for error code {$errorCode}");
118119
}
@@ -126,7 +127,7 @@ protected function writeConfigArgumentSeparator($configFile, $column): void
126127
$translationCell = $this->localeTranslations->getCell($column . self::ARGUMENT_SEPARATOR_ROW);
127128
$localeValue = $translationCell->getValue();
128129
if (!empty($localeValue)) {
129-
$functionTranslation = "ArgumentSeparator = {$localeValue}" . PHP_EOL;
130+
$functionTranslation = "ArgumentSeparator = {$localeValue}" . self::EOL;
130131
fwrite($configFile, $functionTranslation);
131132
} else {
132133
$this->log('No Argument Separator defined');
@@ -148,7 +149,7 @@ protected function buildFunctionsFileForLocale($column, $locale): void
148149
} elseif (!array_key_exists($functionName, $this->phpSpreadsheetFunctions)) {
149150
$this->log("Function {$functionName} is not defined in PhpSpreadsheet");
150151
} elseif (!empty($translationValue)) {
151-
$functionTranslation = "{$functionName} = {$translationValue}" . PHP_EOL;
152+
$functionTranslation = "{$functionName} = {$translationValue}" . self::EOL;
152153
fwrite($functionFile, $functionTranslation);
153154
} else {
154155
$this->log("No {$language} translation available for function {$functionName}");
@@ -200,20 +201,20 @@ protected function getLocaleFolder(string $locale): string
200201

201202
protected function writeFileHeader($localeFile, string $localeLanguage, string $language, string $title): void
202203
{
203-
fwrite($localeFile, str_repeat('#', 60) . PHP_EOL);
204-
fwrite($localeFile, '##' . PHP_EOL);
205-
fwrite($localeFile, "## PhpSpreadsheet - {$title}" . PHP_EOL);
206-
fwrite($localeFile, '##' . PHP_EOL);
207-
fwrite($localeFile, "## {$localeLanguage} ({$language})" . PHP_EOL);
208-
fwrite($localeFile, '##' . PHP_EOL);
209-
fwrite($localeFile, str_repeat('#', 60) . PHP_EOL . PHP_EOL);
204+
fwrite($localeFile, str_repeat('#', 60) . self::EOL);
205+
fwrite($localeFile, '##' . self::EOL);
206+
fwrite($localeFile, "## PhpSpreadsheet - {$title}" . self::EOL);
207+
fwrite($localeFile, '##' . self::EOL);
208+
fwrite($localeFile, "## {$localeLanguage} ({$language})" . self::EOL);
209+
fwrite($localeFile, '##' . self::EOL);
210+
fwrite($localeFile, str_repeat('#', 60) . self::EOL . self::EOL);
210211
}
211212

212213
protected function writeFileSectionHeader($localeFile, string $header): void
213214
{
214-
fwrite($localeFile, PHP_EOL . '##' . PHP_EOL);
215-
fwrite($localeFile, "## {$header}" . PHP_EOL);
216-
fwrite($localeFile, '##' . PHP_EOL);
215+
fwrite($localeFile, self::EOL . '##' . self::EOL);
216+
fwrite($localeFile, "## {$header}" . self::EOL);
217+
fwrite($localeFile, '##' . self::EOL);
217218
}
218219

219220
protected function openTranslationWorkbook(): void
@@ -339,6 +340,6 @@ private function log(string $message): void
339340
return;
340341
}
341342

342-
echo $message, PHP_EOL;
343+
echo $message, self::EOL;
343344
}
344345
}

0 commit comments

Comments
 (0)