Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blueprints] setSiteLanguage step – download the latest RC translations for Nightly and Beta builds of WordPress #1987

Merged
merged 14 commits into from
Nov 19, 2024

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Nov 7, 2024

This PR enables using setSiteLanguage with beta and nightly WordPress versions:

{
	"preferredVersions": {
		"php": "8.0",
		"wp": "beta"
	},
	"steps": [
		{
			"step": "setSiteLanguage",
			"language": "en_GB"
		}
	]
}

Before this PR, the above Blueprint would fetch translations from https://downloads.wordpress.org/translation/core/6.7-RC2/es_ES.zip and fail after a 404 API response from the WordPress.org translations API. The 6.7-RC2 version string in the URL came directly from WordPress's version.php.

The WordPress translations API only offers translations for full, official WordPress releases (e.g. 6.6, 6.6.1)
plus RC translations for each major WordPress version (e.g. 6.6-RC, 6.7-RC). Note that beta and RC versions use the same translations bundle. Also, there is no translation bundle for the development versions so the best we can do is download the latest RC translations.

This PR transforms the raw version string, such as 6.7-RC2 or 6.8-alpha-59341, into one recognized by the API, such as 6.7-RC or 6.8-RC. As a result, the above Blueprint now fetches the translations from https://downloads.wordpress.org/translation/core/6.7-RC/es_ES.zip.

Testing Instructions (or ideally a Blueprint)

  • CI

Manual testing instructions

@bgrgicak bgrgicak self-assigned this Nov 7, 2024
@bgrgicak bgrgicak added [Type] Bug An existing feature does not function as intended [Package][@wp-playground] Blueprints labels Nov 7, 2024
@bgrgicak bgrgicak requested a review from a team November 7, 2024 12:05
Comment on lines 21 to 34
/**
* Returns a WordPress build version string known to Playground
* for a given WordPress version string.
*
* Each released version will be converted to the major.minor format.
* For example 6.6.1 will be converted to 6.6.
*
* Release candidates (RC) and beta releases are converted to the "beta"
*
* Nightly releases are converted to "nightly".
*
* @param wpVersionString - A WordPress version string.
* @returns A Playground WordPress build version.
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I documented this function as it wasn't fully clear to me what it does.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thank you! Let's explain what's "known to Playground" in "build version string known to Playground". Also, the downloads.wordpress.org aspect of this function is relevant – the returned identifier can be interpolated into a URL to download a WordPress release – let's cover that as well similarly to how the docstring inside getWordPressTranslationUrl explains it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a change to explain "build version string known to Playground".

Also, the downloads.wordpress.org aspect of this function is relevant – the returned identifier can be interpolated into a URL to download a WordPress release – let's cover that as well similarly to how the docstring inside getWordPressTranslationUrl explains it.

I'm not sure I understand what you would like to document here.

If we are talking about WordPress releases from wordpress.org.
This function output can't be interpolated to a URL to download a WordPress release.
This is exactly why we had to implement getWordPressTranslationUrl.
WordPress ZIP download URLs are even more different, for example:

Copy link
Member

@brandonpayton brandonpayton Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I documented this function as it wasn't fully clear to me what it does.

That function definitely deserved documentation. I'm sorry for not providing it initially. Thank you for catching and fixing it, @bgrgicak!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related thought: I wonder if there would be value in exposing a WP version parsing lib from WP core.

The scheme may be well-documented someplace, but the way I wrote the initial code was simply by sampling version strings from different revisions of wp-includes/versions.php at different points in the release cycle.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

* for a given WordPress version string.
*
* Playground supports the last 4 major.minor versions of WordPress,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, though. There's nothing in this function that limits the returned version to the last 4 major releases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I wanted to explain what supported means with that sentence, but it's actually not relevant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the mention of support in 0d062ea because it's not relevant.

* For example translations for WordPress 6.6-BETA1 or 6.6-RC1 are found under
* https://downloads.wordpress.org/translation/core/6.6-RC/en_GB.zip
*/
const wpVersionString = versionStringToLoadedWordPressVersion(wpVersion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if wpVersion is "woah-this-is-cool" then wpVersionString will also be "woah-this-is-cool". What would be a sensible fallback here? Perhaps a dedicated version conversion logic would make more sense here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8cf6394 will default translations to the latest WP version to ensure we can always have a valid URL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this already uses involved patterns, calling versionStringToLoadedWordPressVersion seem to add complexity. What would this look like without that call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would look something like this f1f5842

I like this approach more, relying on versionStringToLoadedWordPressVersion could lead to issues if the function is changed, especially without tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, looking good. Thank you!

@bgrgicak bgrgicak requested a review from adamziel November 18, 2024 07:28
@adamziel adamziel changed the title [Blueprints] Download the latest RC translations for Nightly and Beta builds of WordPress [Blueprints] setSiteLanguage step – download the latest RC translations for Nightly and Beta builds of WordPress Nov 19, 2024
@adamziel adamziel merged commit 3a3f2b6 into trunk Nov 19, 2024
10 checks passed
@adamziel adamziel deleted the fix/rc-and-nigtly-translation-fetching branch November 19, 2024 13:03
adamziel added a commit that referenced this pull request Nov 22, 2024
…lations

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
adamziel added a commit that referenced this pull request Nov 22, 2024
…lations (#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
@adamziel
Copy link
Collaborator

This PR created a dependency between the Blueprints package and the WordPress builds package. @bgrgicak let's pull the WordPress version details from api.wordpress.org/core/version-check/1.7?channel=beta instead of using the version of the latest minified web build the web as a proxy for the latest WordPress version.

@adamziel
Copy link
Collaborator

The resolveWPRelease CLI function might be ripe for reuse in the Blueprints library. That's one less Playground CLI-specific code path.

adamziel added a commit that referenced this pull request Dec 1, 2024
… of assuming it's the same as the last minified build (#2027)

#1987 created a
dependency between the `@wp-playground/blueprints` package and the
`@wp-playground/wordpress-builds` package breaking `@wp-playground/cli`
– see #2026

This PR updates the setSiteLanguage step to pull the latest/best
WordPress version details from
api.wordpress.org/core/version-check/1.7?channel=beta instead of
implicitly assuming the latest version is the same as that of the latest
minified web build. It reuses the Playground CLI resolveWordPressRelease
function, bringing us closer to having zero CLI-specific logic.

## Follow-up work

Invent an ESLint rule to prevent further dependencies on
`@wp-playground/wordpress-builds`

 ## Testing instructions

* CI tests
* Run Playground CLI via `bun packages/playground/cli/src/cli.ts server`
and confirm WordPress is still being downloaded without errors.

cc @swissspidy @bgrgicak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] Blueprints [Type] Bug An existing feature does not function as intended
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants