Commit Graph

8 Commits

Author SHA1 Message Date
Sergey Biryukov
dd6d4e74c1 Code Modernization: Fix implicit nullable parameter type deprecation on PHP 8.4.
In PHP 8.4, declaring function or method parameters with a default value of `null` is deprecated if the type is not nullable.

PHP applications are recommended to ''explicitly'' declare the type as nullable. All type declarations that have a default value of `null`, but without declaring `null` in the type declaration, will emit a deprecation notice:
{{{
function test( array $value = null ) {}
}}}
`Deprecated: Implicitly marking parameter $value as nullable is deprecated, the explicit nullable type must be used instead`

**Recommended Changes**

Change the implicit nullable type declaration to a nullable type declaration, available since PHP 7.1:
{{{#!diff
- function test( string $test = null ) {}
+ function test( ?string $test = null ) {}
}}}

This commit updates the affected instances in core to use a nullable type declaration.

References:
* [https://wiki.php.net/rfc/deprecate-implicitly-nullable-types PHP RFC: Deprecate implicitly nullable parameter types]
* [https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated PHP.Watch: PHP 8.4: Implicitly nullable parameter declarations deprecated]

Follow-up to [28731], [50552], [57337], [57985].

Props ayeshrajans, jrf, audrasjb, jorbin.
Fixes #60786.
Built from https://develop.svn.wordpress.org/trunk@58009


git-svn-id: http://core.svn.wordpress.org/trunk@57480 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-04-15 20:03:09 +00:00
Pascal Birchler
4c37cdc1a4 I18N: Add type declaration to new method missed in [57518].
See #59656.
Built from https://develop.svn.wordpress.org/trunk@57519


git-svn-id: http://core.svn.wordpress.org/trunk@57020 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-02 09:07:14 +00:00
Pascal Birchler
953e148764 I18N: Fix plural forms parsing in WP_Translation_File.
Ensures the plural expression from the translation file header is correctly parsed.
Prevents silent failures in the attempt to create the plural form function.

Adds additional tests.

Props Chouby.
See #59656.
Built from https://develop.svn.wordpress.org/trunk@57518


git-svn-id: http://core.svn.wordpress.org/trunk@57019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-02-01 20:59:14 +00:00
Pascal Birchler
ec68b4743e I18N: Revert [57386] pending further investigation.
Reverts the change for fallback string lookup due to a performance regression in the bad case scenario.

See #59656.
Built from https://develop.svn.wordpress.org/trunk@57505


git-svn-id: http://core.svn.wordpress.org/trunk@57006 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-31 21:51:14 +00:00
Pascal Birchler
fac1c328d8 I18N: Add missing space after foreach keyword.
Follow-up to [57386].

See #59656.
Built from https://develop.svn.wordpress.org/trunk@57387


git-svn-id: http://core.svn.wordpress.org/trunk@56893 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-30 14:10:10 +00:00
Pascal Birchler
b7aadef64d I18N: Improve singular lookup of pluralized strings.
Ensures that looking up a singular that is also used as a pluralized string works as expected.
This improves compatibility for cases where for example both `__( 'Product' )` and `_n( 'Product', 'Products’, num )` are used in a project, where both will use the same translation for the singular version.

Although such usage is not really recommended nor documented, it must continue to work in the new i18n library in order to maintain backward compatibility and maintain expected behavior.

See #59656.
Built from https://develop.svn.wordpress.org/trunk@57386


git-svn-id: http://core.svn.wordpress.org/trunk@56892 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-30 14:01:11 +00:00
Pascal Birchler
417bf8d365 I18N: Improve docblocks after [57337].
Props mukesh27.
See #59656.
Built from https://develop.svn.wordpress.org/trunk@57344


git-svn-id: http://core.svn.wordpress.org/trunk@56850 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-24 07:57:14 +00:00
Pascal Birchler
c6ccfb1242 I18N: Introduce a more performant localization library.
This introduces a more lightweight library for loading `.mo` translation files which offers increased speed and lower memory usage.
It also supports loading multiple locales at the same time, which makes locale switching faster too.

For plugins interacting with the `$l10n` global variable in core, a shim is added to retain backward compatibility with the existing `pomo` library.

In addition to that, this library supports translations contained in PHP files, avoiding a binary file format and leveraging OPCache if available.
If an `.mo` translation file has a corresponding `.l10n.php` file, the latter will be loaded instead.
This behavior can be adjusted using the new `translation_file_format` and `load_translation_file` filters.

PHP translation files will be typically created by downloading language packs, but can also be generated by plugins.
See https://make.wordpress.org/core/2023/11/08/merging-performant-translations-into-core/ for more context.

Props dd32, swissspidy, flixos90, joemcgill, westonruter, akirk, SergeyBiryukov.
Fixes #59656.
Built from https://develop.svn.wordpress.org/trunk@57337


git-svn-id: http://core.svn.wordpress.org/trunk@56843 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-23 13:34:11 +00:00