Commit Graph

248 Commits

Author SHA1 Message Date
Pascal Birchler
72fda0359f I18N: Ensure determine_locale() does not potentially return an empty string.
Call `get_locale()` as a last resort in case the sanitized locale is an empty string.

Also swaps conditionals to cater for more typical use case and adds tests.

Follow-up to [55862]

Props Cybr, swissspidy.
Fixes #58317.
Built from https://develop.svn.wordpress.org/trunk@56003


git-svn-id: http://core.svn.wordpress.org/trunk@55515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-23 16:03:25 +00:00
Sergey Biryukov
84e9601e5a Code Modernization: Replace usage of substr() with str_starts_with() and str_ends_with().
`str_starts_with()` and `str_ends_with()` were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle).

WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9.

This commit uses `str_starts_with()` and `str_ends_with()` in core files where appropriate:
* `$needle === substr( $string, 0, $length )`, where `$length` is the length of `$needle`, is replaced with `str_starts_with( $haystack, $needle )`.
* `$needle === substr( $string, $offset )`, where `$offset` is negative and the absolute value of `$offset` is the length of `$needle`, is replaced with `str_ends_with( $haystack, $needle )`.

This aims to make the code more readable and consistent, as well as better aligned with modern development practices.

Follow-up to [52039], [52040], [52326], [55703], [55710], [55987], [55988].

Props Soean, spacedmonkey, Clorith, ocean90, azaozz, sabernhardt, SergeyBiryukov.
Fixes #58220.
Built from https://develop.svn.wordpress.org/trunk@55990


git-svn-id: http://core.svn.wordpress.org/trunk@55502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 14:57:24 +00:00
Pascal Birchler
c251d2f8bf I18N: Allow to short-circuit load_textdomain().
Introduces a new `pre_load_textdomain` filter, which is useful for plugins to develop and test alternative loading/caching strategies for translations. This brings consistency with the existing `pre_load_script_translations` filter for JavaScript translations.

Props ocean90, swissspidy.
Fixes #58035.
Built from https://develop.svn.wordpress.org/trunk@55928


git-svn-id: http://core.svn.wordpress.org/trunk@55440 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-16 12:58:24 +00:00
Pascal Birchler
30593b01b4 I18N: Improve _load_textdomain_just_in_time() logic when there are no translation files.
Fixes a performance issue where the JIT logic is invoked for every translation call if the there are no translations in the current locale. With this change, the information is cached by adding `Noop_Translations` instances to the global `$l10n` array. This way, `get_translations_for_domain()` returns earlier, thus avoiding subsequent `_load_textdomain_just_in_time()` calls.

Props swissspidy, johnbillion, ocean90.
Fixes #58321.
Built from https://develop.svn.wordpress.org/trunk@55865


git-svn-id: http://core.svn.wordpress.org/trunk@55377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-29 08:36:23 +00:00
Pascal Birchler
afd88c4ac7 I18N: Refactor determine_locale() for performance and readability.
Refactors the function to avoid unnecessary `get_locale()` calls and slightly improve performance, while keeping it readable.

Adds tests.

Props Cybr, spacedmonkey, swissspidy.
Fixes #58317.
Built from https://develop.svn.wordpress.org/trunk@55862


git-svn-id: http://core.svn.wordpress.org/trunk@55374 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-26 17:57:23 +00:00
audrasjb
02a131ec30 I18N: Introduce sanitization function for locale.
Introduce the `sanitize_locale_name()` for sanitizing user input of locales.

Props xknown, timothyblynjacobs, ocean90, peterwilsoncc.


Built from https://develop.svn.wordpress.org/trunk@55760


git-svn-id: http://core.svn.wordpress.org/trunk@55272 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-16 14:18:20 +00:00
Sergey Biryukov
2ec23a82ed Code Modernization: Replace usage of strpos() with str_starts_with().
`str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle).

WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.

This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance.

While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle.

Follow-up to [52039], [52040], [52326].

Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov.
Fixes #58012.
Built from https://develop.svn.wordpress.org/trunk@55703


git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-02 15:45:22 +00:00
Sergey Biryukov
f8dd6946fc I18N: Check that $wp_locale global is set before calling its methods.
This avoids a fatal error if these functions are called in a mu-plugin before `$wp_locale` is set:
* `wp_get_list_item_separator()`
* `wp_get_word_count_type()`

Follow-up to [52929], [52933], [55279], [55295].

Props kraftbj.
Fixes #56698.
Built from https://develop.svn.wordpress.org/trunk@55351


git-svn-id: http://core.svn.wordpress.org/trunk@54884 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-15 23:37:17 +00:00
Sergey Biryukov
e841840662 Docs: Document possible return values for wp_get_word_count_type().
Follow-up to [55279].

See #56698.
Built from https://develop.svn.wordpress.org/trunk@55295


git-svn-id: http://core.svn.wordpress.org/trunk@54828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-08 10:17:23 +00:00
audrasjb
3223743a6a I18N: Introduce word_count_type property to WP_Locale.
This changesets adds a `word_count_type` property, so that it does not need to be translated separately across multiple projects.

List of changes:
- New property: `WP_Locale::word_count_type`.
- New method: `WP_Locale::get_word_count_type()`.
- New function: `wp_get_word_count_type()` as a wrapper for `WP_Locale::get_word_count_type()`.
- All `_x( 'words', 'Word count type. Do not translate!' )` strings have been replaced with a call to `wp_get_word_count_type()`.

Props pedromendonca, desrosj, costdev, mukesh27, johnbillion.
Fixes #56698.

Built from https://develop.svn.wordpress.org/trunk@55279


git-svn-id: http://core.svn.wordpress.org/trunk@54812 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 17:28:18 +00:00
audrasjb
09d26de216 I18N: Pass $locale parameter to override_load_textdomain filter.
In [53874] the `$locale` parameter was added to `load_textdomain()` so it can be used to properly fill `WP_Textdomain_Registry`. Since `$locale` may not be the same value as `determine_locale()` returns (e.g. when filtered by `plugin_locale` in `load_plugin_textdomain()`) this changeset also passes the `$locale` parameter to the filter so custom file loading implementations are using the same locale as `load_textdomain()` got.

Follow-up to [53874].

Props ocean90, cadic, SergeyBiryukov, swissspidy, costdev.
Fixes #57056.

Built from https://develop.svn.wordpress.org/trunk@55196


git-svn-id: http://core.svn.wordpress.org/trunk@54729 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-02 21:31:18 +00:00
Pascal Birchler
5edb22187d I18N: Introduce switch_to_user_locale().
This new function makes it easier to switch to a specific user’s locale by reducing duplicate code and storing the user’s ID as additional context for plugins to consume. Existing usage of `switch_to_locale()` in core has been replaced with `switch_to_user_locale()` where appropriate.

Also, this change ensures `WP_Locale_Switcher` properly filters `determine_locale` so that anyyone using the `determine_locale()` function will get the correct locale information when switching is in effect.

Props costdev.
Fixes #57123.
See #26511.
Built from https://develop.svn.wordpress.org/trunk@55161


git-svn-id: http://core.svn.wordpress.org/trunk@54694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-30 10:27:16 +00:00
Sergey Biryukov
a6da3647c8 Code Modernization: Rename parameters that use reserved keywords in wp-includes/l10n.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the `$string` parameter to `$text` in `before_last_bar()`.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54938


git-svn-id: http://core.svn.wordpress.org/trunk@54490 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 13:03:18 +00:00
Sergey Biryukov
3ba44120d0 Coding Standards: Always use parentheses when instantiating an object.
Note: This will be enforced by WPCS 3.0.0.

Props jrf.
See #56791.
Built from https://develop.svn.wordpress.org/trunk@54891


git-svn-id: http://core.svn.wordpress.org/trunk@54443 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-29 15:51:14 +00:00
Sergey Biryukov
25ea9680ae Docs: Update various DocBlocks and inline comments per the documentation standards.
Includes minor formatting edits for consistency.

Follow-up to [53/tests], [12179], [12946], [35288], [37884], [38810], [38928], [46596], [48131], [52955], [53548], [53813], [53873], [54118], [54316], [54420], [54421], [54803].

See #56792.
Built from https://develop.svn.wordpress.org/trunk@54855


git-svn-id: http://core.svn.wordpress.org/trunk@54407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-17 18:15:19 +00:00
Pascal Birchler
ba19b8412d I18N: Change how WP_Textdomain_Registry stores the default languages path.
`WP_Textdomain_Registry` was introduced in [53874] to store text domains and their language directory paths, addressing issues with just-in-time loading of textdomains when using locale switching and when using`load_*_textdomain()` functions.

Said change has inadvertently caused a performance regression exactly when using`load_*_textdomain()`, which still often is the case, where the cached information was not further used or even overridden.

This change addresses that issue by storing the default languages paths in a separate way, while at the same time making `WP_Textdomain_Registry` easier to maintain and adding new tests to catch future regressions.

Props flixos90, spacedmonkey, ocean90, SergeyBiryukov, costdev.
Fixes #39210.
Built from https://develop.svn.wordpress.org/trunk@54669


git-svn-id: http://core.svn.wordpress.org/trunk@54221 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-24 10:02:16 +00:00
Sergey Biryukov
70f3a062db I18N: Use correct default value for JavaScript translations path.
The `$path` parameter of some script translation functions had a default value of `null`, even though the parameter is documented as a string.

This commit corrects the default value for `$path` in:
* `WP_Dependency::set_translations()`
* `WP_Scripts::set_translations()`
* `wp_set_script_translations()`

Additionally, this commit removes an `is_string()` check for `$path` in `load_script_textdomain()`. Now that the default value for `$path` in that function has also been corrected to an empty string instead of `null`, that check is no longer necessary, as it would ''hide'' an error which should be ''fixed'' (at the source of the problem) instead.

Follow-up to [54349].

Props jrf, johnjamesjacoby.
See #55967, #55656.
Built from https://develop.svn.wordpress.org/trunk@54351


git-svn-id: http://core.svn.wordpress.org/trunk@53910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-28 22:19:10 +00:00
Sergey Biryukov
d3006e8a16 Code Modernization: Use correct default value for JavaScript translations path.
The `$path` parameter of `load_script_textdomain()` had a default value of `null`, but would be passed onto the `untrailingslashit()` function without any input validation, even though the latter explicitly only expects/supports a string input.

This commit changes the default value for `$path` to an empty string, and adds an `is_string()` check before passing the value to `untrailingslashit()` to fix the issue at the point where the invalid input is incorrectly (not) validated.

Note: Changing the `untrailingslashit()` function is outside the scope of this commit.

Includes:
* Adding a dedicated unit test for this issue.
* Correcting the default value for `$path` from `null` to an empty string in a few related methods and functions:
 * `WP_Dependency::set_translations()`
 * `WP_Scripts::set_translations()`
 * `wp_set_script_translations()`
 * `load_script_textdomain()`

This fix also allows to remove a couple of calls to `expectDeprecation()` in unrelated tests.

Fixes an error when running the test suite:
{{{
4) Tests_Dependencies_Scripts::test_wp_external_wp_i18n_print_order
rtrim(): Passing null to parameter #1 ($string) of type string is deprecated

/var/www/src/wp-includes/formatting.php:2782
/var/www/src/wp-includes/l10n.php:1068
/var/www/src/wp-includes/class.wp-scripts.php:605
/var/www/src/wp-includes/class.wp-scripts.php:320
/var/www/src/wp-includes/class.wp-dependencies.php:136
/var/www/src/wp-includes/functions.wp-scripts.php:109
/var/www/tests/phpunit/tests/dependencies/scripts.php:1505
/var/www/tests/phpunit/includes/utils.php:436
/var/www/tests/phpunit/tests/dependencies/scripts.php:1507
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [44169], [44607], [51968].

Props jrf, ocean90, Chouby, swissspidy, lovor, iviweb, meysamnorouzi, DarkoG, oneearth27, SergeyBiryukov.
Fixes #55967. See #55656.
Built from https://develop.svn.wordpress.org/trunk@54349


git-svn-id: http://core.svn.wordpress.org/trunk@53908 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-28 17:33:18 +00:00
desrosj
1966addc05 Coding Standards: Various alignment fixes from composer format.
Follow up to [53874], [54097], [54110], [54155], [54162], [54184].

See #39210, #55443, #56288, #56092, #56408, #56467, #55881.
Built from https://develop.svn.wordpress.org/trunk@54210


git-svn-id: http://core.svn.wordpress.org/trunk@53769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-19 19:51:09 +00:00
audrasjb
c279ba3edb Docs: Typo correction in _load_textdomain_just_in_time() docblock.
Props kebbet.
See #55646.

Built from https://develop.svn.wordpress.org/trunk@54199


git-svn-id: http://core.svn.wordpress.org/trunk@53758 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-19 08:44:10 +00:00
Pascal Birchler
bb9f57429a I18N: Introduce WP_Textdomain_Registry to store text domains and their language directory paths.
Previously, when using `switch_to_locale()` all current loaded text domains were unloaded and added to the `$l10n_unloaded` global. This prevented the just-in-time loading for text domains after a switch. The just-in-time loading was also only possible if the translations were stored in `WP_LANG_DIR`. Both issues have been fixed.

* Adds `WP_Textdomain_Registry` to keep track of the language directory paths for all plugins and themes.
* Updates all `load_*_textdomain()`  functions to store the path in `WP_Textdomain_Registry`.
* Adds `$locale` parameter to `load_textdomain()` to specify the locale the translation file is for.
* Adds `$reloadable` parameter to `unload_textdomain()` to define whether a text domain can be loaded just-in-time again. This is used by `WP_Locale_Switcher::load_translations()`.
* Extends `_load_textdomain_just_in_time()` to also support text domains of plugins and themes with custom language directories.
* Fixes the incorrect `test_plugin_translation_after_switching_locale_twice()` test which should have caught this issue earlier.
* Adds a new test plugin and theme to test the loading of translations with a custom language directory.
* Deprecates the now unused and private `_get_path_to_translation()` and `_get_path_to_translation_from_lang_dir()` functions.

Previously added in [49236] and reverted in [49236] to investigate concerns which are now addressed here.

Props yoavf, swissspidy, dd32, ocean90.
See #26511.
Fixes #39210.
Built from https://develop.svn.wordpress.org/trunk@53874


git-svn-id: http://core.svn.wordpress.org/trunk@53433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-08-11 12:39:12 +00:00
Sergey Biryukov
0eb9abd1fe Coding Standards: Rename the $user_id parameter of get_user_locale() to $user for accuracy.
Since the parameter accepts not only a user's ID, but also a `WP_User` object, `$user` is a more appropriate name, which better aligns with the `$post` parameter of functions that accept a post ID or a `WP_Post` object.

The pre-existing internal `$user` variable which contained a `WP_User` object is renamed to `$user_object` for clarity.

Follow-up to [38955].

Props aristath, poena, afercia, SergeyBiryukov.
See #55647.
Built from https://develop.svn.wordpress.org/trunk@53702


git-svn-id: http://core.svn.wordpress.org/trunk@53261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-15 13:45:11 +00:00
Sergey Biryukov
a5cc224b3c Docs: Correct the type of the $number parameter in ngettext* filters.
This applies to:
* `ngettext`
* `ngettext_{$domain}`
* `ngettext_with_context`
* `ngettext_with_context_{$domain}`

Follow-up to [25565], [48136].

Props cyrillbolliger.
Fixes #56187.
Built from https://develop.svn.wordpress.org/trunk@53691


git-svn-id: http://core.svn.wordpress.org/trunk@53250 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-10 00:07:16 +00:00
John Blackbourn
721877d3d2 I18N: Correct and improve inline docs and tests for functionality related to nooped plurals.
See #55646, #55652

Built from https://develop.svn.wordpress.org/trunk@53543


git-svn-id: http://core.svn.wordpress.org/trunk@53132 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-06-20 22:57:16 +00:00
audrasjb
20c003e842 Docs: Use third-person singular verbs for function descriptions in the Core Translation API.
See #55646.

Built from https://develop.svn.wordpress.org/trunk@53474


git-svn-id: http://core.svn.wordpress.org/trunk@53063 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-06-07 05:18:13 +00:00
Sergey Biryukov
9fb5112732 Docs: Add missing description for $pagenow global in various functions.
See #54729, #55499.
Built from https://develop.svn.wordpress.org/trunk@53060


git-svn-id: http://core.svn.wordpress.org/trunk@52649 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-04 18:26:06 +00:00
Sergey Biryukov
0d747500ba I18N: Move wp_get_list_item_separator() to a more appropriate place.
Follow-up to [52929].

See #39733.
Built from https://develop.svn.wordpress.org/trunk@52933


git-svn-id: http://core.svn.wordpress.org/trunk@52522 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-14 18:01:02 +00:00
audrasjb
ea138fdcb9 Docs: Typo correction in wp_dropdown_languages() DocBlock.
Follow-up to [52058].

See #53399.

Built from https://develop.svn.wordpress.org/trunk@52394


git-svn-id: http://core.svn.wordpress.org/trunk@51986 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-20 22:26:02 +00:00
John Blackbourn
39bff93b6b Docs: Various inline documentation corrections and improvements.
See #53399

Built from https://develop.svn.wordpress.org/trunk@52332


git-svn-id: http://core.svn.wordpress.org/trunk@51924 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-07 12:20:02 +00:00
desrosj
c86f41d98b Coding Standards: Minor alignment fix after [52058].
See #52058.
Built from https://develop.svn.wordpress.org/trunk@52078


git-svn-id: http://core.svn.wordpress.org/trunk@51670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-09 18:51:02 +00:00
joedolson
d00b86ff06 I18N: Add language switcher on login/registration screens.
Load a language switcher on the login and registration screens that allows users to choose any already-installed language. Set user locale on registration.

Props johnbillion, Nikschavan, afercia, sabernhardt, garrett-eclipse, keyur5, paaljoachim, Clorith, tobifjellner.
Fixes #43700.
Built from https://develop.svn.wordpress.org/trunk@52058


git-svn-id: http://core.svn.wordpress.org/trunk@51650 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-08 22:37:59 +00:00
John Blackbourn
ae9eae8f64 Docs: Document some more common names for dynamic hooks and standardise the phrasing used.
Fixes #53581

Built from https://develop.svn.wordpress.org/trunk@51837


git-svn-id: http://core.svn.wordpress.org/trunk@51444 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-21 18:21:00 +00:00
gziolo
2f6eb9d25e Blocks: Add support for variations in block.json` file
We integrated variations with block types and the corresponding REST API endpoint in #52688. It's a follow-up patch to add missing support to the `block.json` metadata file when using `register_block_type`.

Some fields for variations are translatable.Therefore, i18n schema was copied over from Gutenberg: https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/i18n-block.json. The accompanying implementation was adapted as `translate_settings_using_i18n_schema`.

Props: gwwar, swissspidy, schlessera, jorgefilipecosta.
Fixes #53238.


Built from https://develop.svn.wordpress.org/trunk@51599


git-svn-id: http://core.svn.wordpress.org/trunk@51210 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-11 09:08:01 +00:00
John Blackbourn
79685db062 Docs: Corrections and improvements to types used in docblocks for symbols, properties, and filters.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51298


git-svn-id: http://core.svn.wordpress.org/trunk@50907 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:02:57 +00:00
Sergey Biryukov
5c663524c2 Docs: In various @return tags, list the expected type first, instead of false.
Follow-up to [46696], [47060], [49926], [49927], [49929].

See #51800.
Built from https://develop.svn.wordpress.org/trunk@49963


git-svn-id: http://core.svn.wordpress.org/trunk@49664 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-15 20:08:07 +00:00
John Blackbourn
b59c0f307b Docs: Corrections and improvements to types used in various docblocks.
See #51800, #52217

Built from https://develop.svn.wordpress.org/trunk@49936


git-svn-id: http://core.svn.wordpress.org/trunk@49635 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-05 17:16:11 +00:00
Sergey Biryukov
1d3fd41977 Docs: Move locale filter documentation to the canonical place.
See #51800.
Built from https://develop.svn.wordpress.org/trunk@49859


git-svn-id: http://core.svn.wordpress.org/trunk@49578 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-21 18:27:04 +00:00
Sergey Biryukov
700c9455ab I18N: Avoid PHP notices for relative URLs in load_script_textdomain().
Props hellofromTonya, SeBsZ, archon810, nourma, justinahinon, SergeyBiryukov.
Fixes #49145.
Built from https://develop.svn.wordpress.org/trunk@49639


git-svn-id: http://core.svn.wordpress.org/trunk@49377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-17 20:52:09 +00:00
Dominik Schilling
abc9d961d5 I18N: Revert [49236] for now to investigate alternative implementations.
See #39210, #51678, #26511.
Built from https://develop.svn.wordpress.org/trunk@49566


git-svn-id: http://core.svn.wordpress.org/trunk@49304 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-12 14:43:09 +00:00
Dominik Schilling
173b9aa122 I18N: Introduce WP_Textdomain_Registry to store text domains and their language directory paths.
Previously, when using `switch_to_locale()` all current loaded text domains were unloaded and added to the `$l10n_unloaded` global. This prevented the just-in-time loading for text domains after a switch. The just-in-time loading was also only possible if the translations were stored in `WP_LANG_DIR`. Both issues have been fixed.

* Adds `WP_Textdomain_Registry` to keep track of the language directory paths for all plugins and themes.
* Updates all `load_*_textdomain()`  functions to store the path in `WP_Textdomain_Registry`.
* Adds `$reloadable` parameter to `unload_textdomain()` to define whether a text domain can be loaded just-in-time again. This is used by `WP_Locale_Switcher::load_translations()`.
* Extends `_load_textdomain_just_in_time()` to also support text domains of plugins and themes with custom language directories.
* Fixes the incorrect `test_plugin_translation_after_switching_locale_twice()` test which should have catch this issue earlier.
* Adds a new test plugin/theme to test the loading of translations with a custom language directory.
* Deprecates the now unused and private `_get_path_to_translation()` and `_get_path_to_translation_from_lang_dir()` functions.

Props yoavf, swissspidy, dd32, ocean90.
See #26511.
Fixes #39210.
Built from https://develop.svn.wordpress.org/trunk@49236


git-svn-id: http://core.svn.wordpress.org/trunk@48998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-20 16:05:07 +00:00
Sergey Biryukov
0e3147c40e Coding Standards: Replace alias PHP functions with the canonical names.
Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.

This replaces all uses of the following:
* `join()` with `implode()`
* `sizeof()` with `count()`
* `is_writeable()` with `is_writable()`
* `doubleval()` with a `(float)` cast

In part, this is a follow-up to #47746.

Props jrf.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@49193


git-svn-id: http://core.svn.wordpress.org/trunk@48955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-18 17:27:06 +00:00
Sergey Biryukov
69d46b2003 I18N: Use underscores instead of dashes and interpolation instead of concatenation in domain-specific gettext hooks, per the coding standards:
* `gettext_{$domain}`
* `gettext_with_context_{$domain}`
* `ngettext_{$domain}`
* `ngettext_with_context_{$domain}`

Additionally:
* Pass `$domain` parameter to the new hooks, for consistency with their pre-existing counterparts.
* Update documentation to explain the dynamic portion of the filter, for consistency with other dynamic hooks in core.

Follow-up to [48131].

Props swissspidy, knutsp, TimothyBlynJacobs, SergeyBiryukov.
Fixes #49518.
Built from https://develop.svn.wordpress.org/trunk@48136


git-svn-id: http://core.svn.wordpress.org/trunk@47905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-23 10:02:10 +00:00
whyisjake
98fc60aabe I18N: Introduce domain specific i18n gettext hooks.
Adding context to allow for more specific targeting. New hooks:

* `gettext-{$domain}`
* `gettext_with_context-{$domain}`
* `ngettext-{$domain}`
* `ngettext_with_context-{$domain}`

Fixes #49518.

Props geminilabs, garrett-eclipse, davidbaumwald, johnbillion, whyisjake.



Built from https://develop.svn.wordpress.org/trunk@48131


git-svn-id: http://core.svn.wordpress.org/trunk@47900 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-23 04:43:10 +00:00
Sergey Biryukov
b16368c268 Docs: Remove @staticvar tags from core.
The tag was supported in phpDocumentor 1.x, but is no longer supported in 2.x and 3.x.

Usage of static variables is considered an internal implementation detail and has no information value for someone reading the docs.

Props alishanvr, jrf.
Fixes #50426.
Built from https://develop.svn.wordpress.org/trunk@48109


git-svn-id: http://core.svn.wordpress.org/trunk@47878 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-20 12:40:12 +00:00
Sergey Biryukov
38676936ba Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.
This reduces the number of `WordPress.PHP.StrictInArray.MissingTrueStrict` issues from 486 to 50.

Includes minor code layout fixes for better readability.

See #49542.
Built from https://develop.svn.wordpress.org/trunk@47550


git-svn-id: http://core.svn.wordpress.org/trunk@47325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-04-05 03:02:11 +00:00
Sergey Biryukov
32edd58e4c Docs: Add descriptions for some globals:
* `$wp_version`
* `$wp_local_package`
* `$required_php_version`
* `$required_mysql_version`

See #48303.
Built from https://develop.svn.wordpress.org/trunk@47230


git-svn-id: http://core.svn.wordpress.org/trunk@47030 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-10 03:30:06 +00:00
Sergey Biryukov
641c632b0c Coding Standards: Use Yoda conditions where appropriate.
See #49222.
Built from https://develop.svn.wordpress.org/trunk@47219


git-svn-id: http://core.svn.wordpress.org/trunk@47019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-09 16:55:09 +00:00
Sergey Biryukov
47ed56f38f Code Modernization: Replace dirname( __FILE__ ) calls with __DIR__ magic constant.
This avoids the performance overhead of the function call every time `dirname( __FILE__ )` was used instead of `__DIR__`.

This commit also includes:

* Removing unnecessary parentheses from `include`/`require` statements. These are language constructs, not function calls.
* Replacing `include` statements for several files with `require_once`, for consistency:
 * `wp-admin/admin-header.php`
 * `wp-admin/admin-footer.php`
 * `wp-includes/version.php`

Props ayeshrajans, desrosj, valentinbora, jrf, joostdevalk, netweb.
Fixes #48082.
Built from https://develop.svn.wordpress.org/trunk@47198


git-svn-id: http://core.svn.wordpress.org/trunk@46998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-06 06:33:11 +00:00
Sergey Biryukov
c289bb59ac Docs: Improve documentation for WP_Dependencies, WP_Scripts, and WP_Styles methods.
See #48303.
Built from https://develop.svn.wordpress.org/trunk@47170


git-svn-id: http://core.svn.wordpress.org/trunk@46970 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-03 00:19:03 +00:00
Sergey Biryukov
dd4d98a368 Docs: In various @return tags, list the expected type first, instead of false.
Follow-up to [46696].

See #48303.
Built from https://develop.svn.wordpress.org/trunk@47060


git-svn-id: http://core.svn.wordpress.org/trunk@46860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-11 18:32:05 +00:00