Commit graph

9 commits

Author SHA1 Message Date
Abijeet
8ddc4ee2ef Add TranslationAliasesDirs to specify special page aliases in JSON
The TranslationAliasesDirs configuration allows defining translatable
aliases in JSON files. The value should be a name or names of folders
that contains files that have localized aliases. Each language should
have a separate file.

Currently, it supports defining special page aliases but in the
future can be extended to support magic words and namespace aliases.

The patch adds a script: ConvertExtensionsMessagesToTranslationAlias
that can be used to convert existing ExtensionMessagesFiles to the new
format.

Bug: T89947
Change-Id: Ief16a48a8dc8742854f67301791aa2a0b0531116
2024-03-06 18:13:28 +05:30
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Lucas Werkmeister
3bf5cfc347 LocalisationCache: Load only core data if possible (v2)
This reverts change I6490ffba96 (commit e4e613b0d1), restoring
change I7ec2d87c0f (commit cf8e22e1e4). The issues with the last version
should be fixed by the parent change (Icc3324aca7), and we also have
some tests for these issues now (change Iee11cb5c52).

Bug: T342418
Bug: T343343
Bug: T343375
Change-Id: Id9e718f1791c937f53195613a7b76c23d3376a13
2023-08-08 13:10:18 +02:00
Lucas Werkmeister
fee22e61d8 LocalisationCache: Add tests for preload behavior
The new block in testRecacheExtensionMessagesFiles() covers the
underlying issue of T343343 and T343375; see change Icc3324aca7 for an
explanation of the issue.

In order for this test to not crash, we also need to adjust some of the
other tests and data. MessagesEn.php defines $preloadedMessages, and
LocalisationCache assumes (quite rightly so, really) that all of these
messages will be found in the configured MessagesDirs. But in the test,
we override MessagesDirs to point at the test’s JSON files, while still
using the original MessagesEn.php with its $preloadedMessages. Now that
we are triggering the preload mechanism (I think it wasn’t reached by
the tests previously?), it triggers a PHP deprecation (since PHP 8) on
the missing messages, which makes the test fail:

> explode(): Passing null to parameter #2 ($string) of type string is deprecated

I decided to fix this by adding fake entries for all $preloadedMessages
to the test en.json file. This makes the other tests that compare the
entire messages array fail, so instead only compare the three messages
those tests care about ("present-*"). I don’t like this very much, but I
dislike the other two approaches I can think of even more: check
defined( 'MW_PHPUNIT_TEST' ) in the original MessagesEn.php file, or add
a test-specific MessagesEn.php using the Language::getMessagesFileName
hook.

Bug: T342418
Bug: T343343
Bug: T343375
Change-Id: Iee11cb5c52cb9dd777b70a1daa06f41f2c3ca187
2023-08-08 13:09:34 +02:00
Ahmon Dancy
e4e613b0d1 Revert "LocalisationCache: Load only core data if possible"
This reverts commit cf8e22e1e4.

Bug: T342418
Bug: T343375
Change-Id: I6490ffba96b4f2d65d9206a4942f29d24d8bbecb
2023-08-02 19:18:21 +00:00
Lucas Werkmeister
cf8e22e1e4 LocalisationCache: Load only core data if possible
Extract loadCoreData(), which loads only the core, non-mergeable keys
from the core messages files, not the extension messages files or the
JSON files. Have loadItem() call this method, skipping the full
initLanguage() + recache(), if possible.

Because compiling the plural rules takes up a significant amount of
loading the core-only data (see discussion on Gerrit), extract
readPluralFilesAndRegisterDeps() from readSourceFilesAndRegisterDeps(),
and only call the latter in loadCoreData() (while recache() calls both).
Also remove a comment about readSourceFilesAndRegisterDeps() returning
false if the localisation doesn’t exist, which AFAICT hasn’t been true
since change I35bbb3a7a1 (commit 8e0c0a9fc9) in 2014.

Note that the new “core-only data” path in loadItem() bypasses the
underlying LCStore even if the core data (or indeed all data) happens to
be present in it. Some investigation and benchmarks (see the discussion
on this change on Gerrit) indicate that this is usually a performance
win; in particular, unless manualRecache is set, just checking whether
the LCStore is expired is relatively expensive.

[For further discussion, see also changes I00f2018400 and I64822e050e on
Gerrit, which were later squashed into this change.]

Bug: T342418
Change-Id: I7ec2d87c0f864c7dbfd629f0b47f22dc8a6fa552
2023-07-31 12:33:13 +02:00
Lucas Werkmeister
368881a277 LocalisationCache: Add CORE_ONLY_KEYS, ALL_EXCEPT_CORE_ONLY_KEYS
Previously, it was technically possible to set some keys in extension
messages files that didn’t make much sense (e.g. $rtl['en'] = true;).
This prevents optimizing language creation, so going forward, we will no
longer support that; ALL_KEYS is now split into CORE_ONLY_KEYS and
ALL_EXCEPT_CORE_ONLY_KEYS (with a test verifying that no key is missing
or overlapping or anything), and ALL_EXCEPT_CORE_ONLY_KEYS are silently
skipped when loading extension messages files.

To demonstrate that it’s okay to silently skip these keys, patch set 1
of this change on Gerrit instead raised a deprecation warning; CI
indicated that this warning was never hit. Codesearch [1] also suggests
that no known extension was actually using any of these keys. (The
DonationInterface [2] and LandingCheck [3] codesearch results can be
ignored: both of these define es-419 as a new language, using the
Language::getMessagesFileName hook to register their MessagesEs_419.php
as a “core” message file, not an extension message file.)

[1]: https://codesearch.wmcloud.org/search/?q=^\%24(fallback|rtl|(digit|separator)TransformTable|fallback8bitEncoding|link(PrefixExtension|Trail|PrefixCharset)|date(Formats|Preferences|PreferenceMigrationMap)|defaultDateFormat|digitGroupingPattern).*%3D&files=\.php%24
[2]: f8b5fe95f7/gateway_common/messages/MessagesEs_419.php (11)
[3]: 2537439aee/messages/MessagesEs_419.php (11)

Bug: T342418
Change-Id: Ia3dffea390d4efdfa3a3cea549d079507718ef48
2023-07-28 16:32:59 +02:00
Lucas Werkmeister
274fd222df LocalisationCache: Expand tests
To ensure that Ia3dffea390 and I7ec2d87c0f don’t change this behavior.

Bug: T342418
Change-Id: I4646b1c84116f51b6c2a826a41dc5c975d3d205c
2023-07-28 16:30:52 +02:00
Lucas Werkmeister
7b8859c70c language: Move tests from /cache to /language
The classes were already moved in change I62c701d574 (commit
051e127bdb).

Ideally, the tests should have a namespace, but the other tests in
/language are also unnamespaced, so let’s not do that yet.

Change-Id: Ieef8728a1f474ce6b16fa534c9697e1e89a4a36d
2023-07-28 15:23:06 +02:00
Renamed from tests/phpunit/includes/cache/LocalisationCacheTest.php (Browse further)