Skip to content

Commit

Permalink
Launchpad: Add translation support (#36802)
Browse files Browse the repository at this point in the history
* Support the _locale param for Launchpad requests and switch to locale

* changelog

* Fix undefined var

* Fixup project versions
  • Loading branch information
sixhours authored Apr 9, 2024
1 parent b4cd9a2 commit 0094941
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fixed

Add translation support for the Launchpad API endpoint
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.23.x-dev"
"dev-trunk": "5.24.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.23.2",
"version": "5.24.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.23.2';
const PACKAGE_VERSION = '5.24.0-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,21 @@ public function can_access() {
* and `checklist`.
*/
public function get_data( $request ) {
// Handle translations for Atomic sites.
$switched_locale = false;
$locale = $request['_locale'] ? get_user_locale() : null;

if ( $locale ) {
$switched_locale = switch_to_locale( $locale );
}

$checklist_slug = isset( $request['checklist_slug'] ) ? $request['checklist_slug'] : get_option( 'site_intent' );

$launchpad_context = isset( $request['launchpad_context'] )
? $request['launchpad_context']
: null;

return array(
$response = array(
'site_intent' => get_option( 'site_intent' ),
'launchpad_screen' => get_option( 'launchpad_screen' ),
'checklist_statuses' => get_option( 'launchpad_checklist_tasks_statuses', array() ),
Expand All @@ -164,6 +172,12 @@ public function get_data( $request ) {
'is_dismissible' => wpcom_launchpad_is_task_list_dismissible( $checklist_slug ),
'title' => wpcom_get_launchpad_checklist_title_by_checklist_slug( $checklist_slug ),
);

if ( $switched_locale ) {
restore_previous_locale();
}

return $response;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0094941

Please sign in to comment.