Skip to content

Commit 7e9a1ac

Browse files
authored
Blueprints: Use the major WordPress version to download RC/beta translations (#2017)
Uses a major WordPress version to fetch the translations, e.g. `https://downloads.wordpress.org/translation/core/6.6-RC/en_US.zip` instead of `https://downloads.wordpress.org/translation/core/6.6.1-RC/en_US.zip` This fixes an issue introduced in #1987 that caused the E2E tests to fail on trunk: ``` ✘ 77 [chromium] › blueprints.spec.ts:438:6 › should translate WP-admin to Spanish for the beta WordPress build (retry #3) (30.2s) ``` The setSiteLanguage step would try to download the translations from https://downloads.wordpress.org/translation/core/6.7.1-RC/es_ES.zip which responded with a 404, instead of https://downloads.wordpress.org/translation/core/6.7-RC/es_ES.zip where the translations are actually available. ## Testing instructions * Confirm the E2E tests pass * Go here and confirm you can see a Spanish version of wp admin: http://localhost:5400/website-server/?language=es_ES&url=%2Fwp-admin%2F&wp=beta&modal=error-report
1 parent 782ffd3 commit 7e9a1ac

File tree

2 files changed

+62
-33
lines changed

2 files changed

+62
-33
lines changed
Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,73 @@
1-
import { MinifiedWordPressVersions } from '@wp-playground/wordpress-builds';
21
import { getWordPressTranslationUrl } from './set-site-language';
32

43
describe('getTranslationUrl()', () => {
5-
it('should return a major.minor translation URL for a major.minor version', () => {
6-
expect(getWordPressTranslationUrl('6.6', 'en_US')).toBe(
7-
'https://downloads.wordpress.org/translation/core/6.6/en_US.zip'
8-
);
9-
});
10-
11-
it('should return a major.minor.patch translation URL for a major.minor.patch version', () => {
12-
expect(getWordPressTranslationUrl('6.5.1', 'es_ES')).toBe(
13-
'https://downloads.wordpress.org/translation/core/6.5.1/es_ES.zip'
14-
);
15-
});
16-
174
[
185
{
19-
version: '6.6-RC1',
6+
versionString: '6.2',
7+
latestBetaVersion: '6.6-RC',
8+
latestMinifiedVersion: '6.5.2',
9+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.2/en_US.zip`,
10+
description:
11+
'should return a major.minor translation URL when the input version string is in a major.minor format',
12+
},
13+
{
14+
versionString: '6.2.1',
15+
latestBetaVersion: '6.3.1-RC',
16+
latestMinifiedVersion: '6.4.2',
17+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.2.1/en_US.zip`,
18+
description:
19+
'should return a major.minor.patch translation URL when the input version string is in a major.minor.patch format',
20+
},
21+
{
22+
versionString: '6.6-RC1',
23+
latestBetaVersion: '6.6-RC',
24+
latestMinifiedVersion: '6.5.2',
25+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.6-RC/en_US.zip`,
2026
description:
2127
'should return the latest RC translation URL for a RC version',
2228
},
2329
{
24-
version: '6.6-beta2',
30+
versionString: '6.6-beta2',
31+
latestBetaVersion: '6.6-RC',
32+
latestMinifiedVersion: '6.5.2',
33+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.6-RC/en_US.zip`,
2534
description:
2635
'should return the latest RC translation URL for a beta version',
2736
},
2837
{
29-
version: '6.6-nightly',
38+
versionString: '6.6-nightly',
39+
latestBetaVersion: '6.6-RC',
40+
latestMinifiedVersion: '6.5.2',
41+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.6-RC/en_US.zip`,
3042
description:
3143
'should return the latest RC translation URL for a nightly version',
3244
},
3345
{
34-
version: '6.8-alpha-59408',
46+
versionString: '6.8-alpha-59408',
47+
latestBetaVersion: '6.8-RC',
48+
latestMinifiedVersion: '6.7.2',
49+
expectedUrl: `https://downloads.wordpress.org/translation/core/6.8-RC/en_US.zip`,
3550
description:
3651
'should return the latest RC translation URL for an alpha version',
3752
},
38-
].forEach(({ version, description }) => {
39-
it(description, () => {
40-
const latestBetaVersion =
41-
MinifiedWordPressVersions['beta'].split('-')[0];
42-
expect(getWordPressTranslationUrl(version, 'en_US')).toBe(
43-
`https://downloads.wordpress.org/translation/core/${latestBetaVersion}-RC/en_US.zip`
44-
);
45-
});
46-
});
53+
].forEach(
54+
({
55+
versionString,
56+
latestBetaVersion,
57+
latestMinifiedVersion,
58+
expectedUrl,
59+
description,
60+
}) => {
61+
it(description, () => {
62+
expect(
63+
getWordPressTranslationUrl(
64+
versionString,
65+
'en_US',
66+
latestBetaVersion,
67+
latestMinifiedVersion
68+
)
69+
).toBe(expectedUrl);
70+
});
71+
}
72+
);
4773
});

packages/playground/blueprints/src/lib/steps/set-site-language.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export interface SetSiteLanguageStep {
3232
*/
3333
export const getWordPressTranslationUrl = (
3434
wpVersion: string,
35-
language: string
35+
language: string,
36+
latestBetaVersion: string = MinifiedWordPressVersions['beta'],
37+
latestMinifiedVersion: string = LatestMinifiedWordPressVersion
3638
) => {
3739
/**
3840
* The translation API provides translations for all WordPress releases
@@ -51,17 +53,18 @@ export const getWordPressTranslationUrl = (
5153
* For example translations for WordPress 6.6-BETA1 or 6.6-RC1 are found under
5254
* https://downloads.wordpress.org/translation/core/6.6-RC/en_GB.zip
5355
*/
54-
if (wpVersion.match(/(\d.\d(.\d)?)-(alpha|beta|nightly|rc).*$/i)) {
55-
wpVersion = MinifiedWordPressVersions['beta'].replace(
56-
/(rc|beta).*$/i,
57-
'RC'
58-
);
56+
if (wpVersion.match(/^(\d.\d(.\d)?)-(alpha|beta|nightly|rc).*$/i)) {
57+
wpVersion = latestBetaVersion
58+
// Remove the patch version, e.g. 6.6.1-RC1 -> 6.6-RC1
59+
.replace(/^(\d.\d)(.\d+)/i, '$1')
60+
// Replace "rc" and "beta" with "RC", e.g. 6.6-nightly -> 6.6-RC
61+
.replace(/(rc|beta).*$/i, 'RC');
5962
} else if (!wpVersion.match(/^(\d+\.\d+)(?:\.\d+)?$/)) {
6063
/**
6164
* If the WordPress version string isn't a major.minor or major.minor.patch,
6265
* the latest available WordPress build version will be used instead.
6366
*/
64-
wpVersion = LatestMinifiedWordPressVersion;
67+
wpVersion = latestMinifiedVersion;
6568
}
6669
return `https://downloads.wordpress.org/translation/core/${wpVersion}/${language}.zip`;
6770
};

0 commit comments

Comments
 (0)