Created
October 30, 2020 15:02
-
-
Save adamsilverstein/3eee29ea1370d0e119bb929a331e9f50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Ensures Site Kit loads languages correctly. | |
* | |
* @author Adam Silverstein, Google | |
* @license Apache 2.0 | |
* @copyright 2020 Google Inc. | |
* | |
* @wordpress-plugin | |
* Plugin Name: Site Kit Language Loader | |
* Description: Ensures Site Kit loads languages correctly. | |
* Version: 1.0.0 | |
* Author: Adam Silverstein, Google | |
* License: Apache License 2.0 | |
* License URI: https://www.apache.org/licenses/LICENSE-2.0 | |
*/ | |
add_action( 'plugins_loaded' , function() { | |
add_filter( | |
'load_script_textdomain_relative_path', | |
function( $relative, $src ) { | |
$rel = find_script_by_src( $src ); | |
if ( $rel ) { | |
return 'dist/assets/js/' . $rel; | |
} | |
return $relative; | |
}, 10, 2 | |
); | |
} ); | |
function find_script_by_src( $src ) { | |
$assets = array( | |
"googlesitekit-vendor" => "googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js", | |
"chunk-googlesitekit-adminbar~chunk-googlesitekit-setup-wizard-proxy" => "chunk-googlesitekit-adminbar~chunk-googlesitekit-setup-wizard-proxy-39bf2f5072bd0d1cdc96.js", | |
"chunk-googlesitekit-adminbar" => "chunk-googlesitekit-adminbar-0ef0a2edcaa68b6bf889.js", | |
"chunk-googlesitekit-setup-wizard" => "chunk-googlesitekit-setup-wizard-b0f9d8b73c453976e6a9.js", | |
"chunk-googlesitekit-setup-wizard-proxy" => "chunk-googlesitekit-setup-wizard-proxy-8d48e04604d76303faab.js", | |
"chunk-googlesitekit-setup-wrapper" => "chunk-googlesitekit-setup-wrapper-b9314dcca2640fc8a733.js", | |
"googlesitekit-activation" => "googlesitekit-activation.de7352254b7eb5c2e9b4.js", | |
"googlesitekit-adminbar-loader" => "googlesitekit-adminbar-loader.f74a1f6f0ee0050978a7.js", | |
"googlesitekit-api" => "googlesitekit-api.75cd39617a79d1c3894c.js", | |
"googlesitekit-base" => "googlesitekit-base.45fd96d13d7b9aba817e.js", | |
"googlesitekit-dashboard" => "googlesitekit-dashboard.41176eb144adcaf84380.js", | |
"googlesitekit-dashboard-details" => "googlesitekit-dashboard-details.b64fe3da0aa6e3ea7b34.js", | |
"googlesitekit-dashboard-splash" => "googlesitekit-dashboard-splash.329f8f4845069dcaca2e.js", | |
"googlesitekit-data" => "googlesitekit-data.3cf4912774bcdfe610b6.js", | |
"googlesitekit-datastore-forms" => "googlesitekit-datastore-forms.da48f0fdbca81be0df27.js", | |
"googlesitekit-datastore-site" => "googlesitekit-datastore-site.6aa153ca7f37808c3fa5.js", | |
"googlesitekit-datastore-user" => "googlesitekit-datastore-user.d1aaf50869324aa5849f.js", | |
"googlesitekit-module" => "googlesitekit-module.6f77021725498ecbdbfe.js", | |
"googlesitekit-modules" => "googlesitekit-modules.eeb37a29652bc73560c7.js", | |
"googlesitekit-modules-adsense" => "googlesitekit-modules-adsense.1079e1f43b37bd5458ae.js", | |
"googlesitekit-modules-analytics" => "googlesitekit-modules-analytics.8c9e943ed260ef398943.js", | |
"googlesitekit-modules-optimize" => "googlesitekit-modules-optimize.75e073afd46873c251ec.js", | |
"googlesitekit-modules-pagespeed-insights" => "googlesitekit-modules-pagespeed-insights.a2dfd08f7a775bfdac80.js", | |
"googlesitekit-modules-search-console" => "googlesitekit-modules-search-console.b6558d4b1f24fdec2b23.js", | |
"googlesitekit-modules-tagmanager" => "googlesitekit-modules-tagmanager.518bfe25b0a944312e93.js", | |
"googlesitekit-settings" => "googlesitekit-settings.b010fdef904b76a7b333.js", | |
"googlesitekit-user-input" => "googlesitekit-user-input.6fc048dcbe8eb371025e.js", | |
"googlesitekit-widgets" => "googlesitekit-widgets.c62195b08a5b0a665106.js", | |
"googlesitekit-wp-dashboard" => "googlesitekit-wp-dashboard.1b7af0a71c2a6cab2e8f.js", | |
"pagead2.ads" => "pagead2.ads.1098a210f4359760dc87.js", | |
"vendors~chunk-googlesitekit-adminbar" => "vendors~chunk-googlesitekit-adminbar-7a072713532ba6a23f7d.js", | |
"vendors~chunk-googlesitekit-setup-wizard-proxy" => "vendors~chunk-googlesitekit-setup-wizard-proxy-63f24f08ad3c2ca81616.js", | |
); | |
global $wp_scripts; | |
$clear_test = preg_replace( '/.[^.]*\..[^.]*$/', '', $src ); | |
foreach( $wp_scripts->registered as $reg ) { | |
// remove HASH.js from file paths. | |
$clear_src = preg_replace( '/.[^.]*\..[^.]*$/', '', $reg->src ); | |
if ( $clear_src === $clear_test ) { | |
if ( $assets[ $reg->handle ] ) { | |
return $assets[ $reg->handle ]; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@adamsilverstein Can you update this for the latest 1.20.0 release please?
May be worth to put both in there and allow to rely on different version translations, but we're probably not gonna maintain this and just use it for current QA, so that should be fine. If we want a long-term solution, we'll need to improve this so that it pulls this information from the plugin repository SVN.