Skip to content

Commit 4d82df2

Browse files
author
Mark Baker
authored
Add unit test for erroneous translations from Russian to English, and a quick/dirty fix (#2534)
* Add unit test for erroneous translations from Russian to English, and a quick/dirty fix * Additional translation unit tests with accented characters from Spanish, Bulgarian, Czech and Turkish * Update Change Log
1 parent 6b746dc commit 4d82df2

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
4444

4545
### Fixed
4646

47+
- Fix partial function name matching when translating formulae from Russian to English [Issue #2533](https://github.com/PHPOffice/PhpSpreadsheet/issues/2533) [PR #2534](https://github.com/PHPOffice/PhpSpreadsheet/pull/2534)
4748
- Various bugs related to Conditional Formatting Rules, and errors in the Xlsx Writer for Conditional Formatting [PR #2491](https://github.com/PHPOffice/PhpSpreadsheet/pull/2491)
4849
- Xlsx Reader merge range fixes.
4950
[Issue #2501](https://github.com/PHPOffice/PhpSpreadsheet/issues/2501)

src/PhpSpreadsheet/Calculation/Calculation.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -3161,10 +3161,10 @@ public function _translateFormulaToLocale($formula)
31613161
if (self::$functionReplaceFromExcel === null) {
31623162
self::$functionReplaceFromExcel = [];
31633163
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
3164-
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/Ui';
3164+
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/ui';
31653165
}
31663166
foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
3167-
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
3167+
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/ui';
31683168
}
31693169
}
31703170

@@ -3178,7 +3178,13 @@ public function _translateFormulaToLocale($formula)
31783178
}
31793179
}
31803180

3181-
return self::translateFormula(self::$functionReplaceFromExcel, self::$functionReplaceToLocale, $formula, ',', self::$localeArgumentSeparator);
3181+
return self::translateFormula(
3182+
self::$functionReplaceFromExcel,
3183+
self::$functionReplaceToLocale,
3184+
$formula,
3185+
',',
3186+
self::$localeArgumentSeparator
3187+
);
31823188
}
31833189

31843190
private static $functionReplaceFromLocale;
@@ -3190,10 +3196,10 @@ public function _translateFormulaToEnglish($formula)
31903196
if (self::$functionReplaceFromLocale === null) {
31913197
self::$functionReplaceFromLocale = [];
31923198
foreach (self::$localeFunctions as $localeFunctionName) {
3193-
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/Ui';
3199+
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/ui';
31943200
}
31953201
foreach (self::$localeBoolean as $excelBoolean) {
3196-
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
3202+
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/ui';
31973203
}
31983204
}
31993205

tests/data/Calculation/Translations.php

+30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
'nl',
2727
'=CONCATENATE("""Hello ", B1, """,", " I said.")',
2828
],
29+
[
30+
'=ЕСЛИ(1;1;1)',
31+
'ru',
32+
'=IF(1,1,1)',
33+
],
34+
[
35+
'=ИСКЛИЛИ(1;1)',
36+
'ru',
37+
'=XOR(1,1)',
38+
],
2939
[
3040
'=TEKST.SAMENVOEGEN(JAAR(VANDAAG());
3141
" is ";
@@ -45,4 +55,24 @@
4555
)
4656
)',
4757
],
58+
'Spanish with accented character' => [
59+
'=AÑO(B1)',
60+
'es',
61+
'=YEAR(B1)',
62+
],
63+
'Bulgarian with accent and period' => [
64+
'=ПОЛУЧИТЬ.ДАННЫЕ.СВОДНОЙ.ТАБЛИЦЫ(B1)',
65+
'bg',
66+
'=GETPIVOTDATA(B1)',
67+
],
68+
'Czech with accent and period' => [
69+
'=DSMODCH.VÝBĚR(B1)',
70+
'cs',
71+
'=DSTDEV(B1)',
72+
],
73+
'Turkish with accent and period' => [
74+
'=İŞGÜNÜ.ULUSL(B1)',
75+
'tr',
76+
'=WORKDAY.INTL(B1)',
77+
],
4878
];

0 commit comments

Comments
 (0)