Skip to content

Commit 34655da

Browse files
authored
Merge pull request #550 from devgeniem/TMS-1209
TMS-1209: Rework window.s translations inline script
2 parents 4d96054 + 2ba88b1 commit 34655da

File tree

2 files changed

+54
-45
lines changed

2 files changed

+54
-45
lines changed

CHANGELOG.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
- TMS-1209: Rework window.s translations inline script
1011
- TMS-1201: Add iframe-field for accordion-blocks video field
1112

1213
## [1.66.1] - 2025-10-01

lib/Assets.php

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function hooks() : void {
6666
0
6767
);
6868

69-
add_filter(
69+
\add_filter(
7070
'script_loader_tag',
7171
\Closure::fromCallable( [ $this, 'add_script_attributes' ] ),
7272
10,
@@ -89,18 +89,18 @@ private function add_editor_styles() : void {
8989
* @param string $theme Theme file name without prefix 'theme_' or suffix '.js/.css'.
9090
*/
9191
protected function enqueue_theme( $theme = 'tunnelma' ) : void {
92-
$css = apply_filters( 'tms/theme/theme_css_file', sprintf( 'theme_%s.css', $theme ) );
93-
$js = apply_filters( 'tms/theme/theme_js_file', sprintf( 'theme_%s.js', $theme ) );
92+
$css = \apply_filters( 'tms/theme/theme_css_file', sprintf( 'theme_%s.css', $theme ) );
93+
$js = \apply_filters( 'tms/theme/theme_js_file', sprintf( 'theme_%s.js', $theme ) );
9494

9595
\wp_enqueue_style(
9696
'theme-css',
97-
apply_filters(
97+
\apply_filters(
9898
'tms/theme/theme_css_path',
9999
DPT_ASSET_URI . '/' . $css,
100100
$css
101101
),
102102
[],
103-
apply_filters(
103+
\apply_filters(
104104
'tms/theme/asset_mod_time',
105105
static::get_theme_asset_mod_time( $css ),
106106
$css
@@ -110,13 +110,13 @@ protected function enqueue_theme( $theme = 'tunnelma' ) : void {
110110

111111
\wp_enqueue_script(
112112
'theme-js',
113-
apply_filters(
113+
\apply_filters(
114114
'tms/theme/theme_js_path',
115115
DPT_ASSET_URI . '/' . $js,
116116
$js
117117
),
118118
[ 'jquery', 'vendor-js' ],
119-
apply_filters(
119+
\apply_filters(
120120
'tms/theme/asset_mod_time',
121121
static::get_theme_asset_mod_time( $js ),
122122
$js
@@ -131,26 +131,26 @@ protected function enqueue_theme( $theme = 'tunnelma' ) : void {
131131
private function enqueue_assets() : void {
132132
\wp_enqueue_script(
133133
'vendor-js',
134-
apply_filters(
134+
\apply_filters(
135135
'tms/theme/theme_js_path',
136136
DPT_ASSET_URI . '/vendor.js',
137137
'vendor.js'
138138
),
139139
[ 'jquery', 'wp-a11y' ],
140-
apply_filters(
140+
\apply_filters(
141141
'tms/theme/asset_mod_time',
142142
static::get_theme_asset_mod_time( 'vendor.js' ),
143143
'vendor.js'
144144
),
145145
true
146146
);
147147

148-
$theme_default_color = apply_filters(
148+
$theme_default_color = \apply_filters(
149149
'tms/theme/theme_default_color',
150150
DEFAULT_THEME_COLOR
151151
);
152152

153-
$selected_theme = apply_filters(
153+
$selected_theme = \apply_filters(
154154
'tms/theme/theme_selected',
155155
Settings::get_setting( 'theme_color' ) ?? $theme_default_color
156156
);
@@ -160,11 +160,19 @@ private function enqueue_assets() : void {
160160
/**
161161
* Add localizations to window.s object.
162162
*/
163-
\wp_localize_script( 'theme-js', 's', ( new \Strings() )->s() );
163+
\wp_add_inline_script(
164+
'theme-js',
165+
'var s = ' . json_encode( ( new \Strings() )->s() ) . ';',
166+
'before'
167+
);
164168

165-
\wp_localize_script( 'theme-js', 'themeData', [
166-
'assetsUri' => esc_url( get_template_directory_uri() ),
167-
] );
169+
\wp_add_inline_script(
170+
'theme-js',
171+
'var themeData = ' . json_encode( [
172+
'assetsUri' => \esc_url( \get_template_directory_uri() ),
173+
] ) . ';',
174+
'before'
175+
);
168176

169177
\wp_dequeue_style( 'wp-block-library' );
170178

@@ -397,36 +405,36 @@ protected function get_theme_icons() {
397405
*/
398406
public static function get_accessibility_icons() {
399407
return [
400-
'aaniopastus' => __( 'Audio guide', 'tms-theme-base' ),
401-
'avustaja' => __( 'Assistant', 'tms-theme-base' ),
402-
'hissi' => __( 'Lift', 'tms-theme-base' ),
403-
'induktiosilmukka' => __( 'Induction loop', 'tms-theme-base' ),
404-
'info' => __( 'Information', 'tms-theme-base' ),
405-
'internet' => __( 'Internet', 'tms-theme-base' ),
406-
'isa' => __( 'Accessible entrance, Accessible toilet, Accessible parking', 'tms-theme-base' ),
407-
'kahvila' => __( 'Café', 'tms-theme-base' ),
408-
'kauppa' => __( 'Shop', 'tms-theme-base' ),
409-
'kokoustilaa' => __( 'Meeting room', 'tms-theme-base' ),
410-
'lainattavia-valineita' => __( 'Assistive device lending', 'tms-theme-base' ),
411-
'lastenhoitotila' => __( 'Baby changing', 'tms-theme-base' ),
412-
'latauspiste' => __( 'Charging point', 'tms-theme-base' ),
413-
'lipunmyynti' => __( 'Ticket sales', 'tms-theme-base' ),
414-
'luiska' => __( 'Ramp', 'tms-theme-base' ),
415-
'nakovammaisia_helpottavat_palvelut' => __( 'Services for the visually impaired', 'tms-theme-base' ),
416-
'opaskoirat_sallittu' => __( 'Service dogs allowed', 'tms-theme-base' ),
417-
'pistekirjoitus' => __( 'Braille', 'tms-theme-base' ),
418-
'porrashissi' => __( 'Stairlift', 'tms-theme-base' ),
419-
'portaat' => __( 'Staircase', 'tms-theme-base' ),
420-
'pyoratuolihissi' => __( 'Platform lift', 'tms-theme-base' ),
421-
'rollaattori' => __( 'Rollator, walker', 'tms-theme-base' ),
422-
'sahkomopon_sailytys' => __( 'Electric mobility scooter storage', 'tms-theme-base' ),
423-
'sailytyslokerot' => __( 'Lockers', 'tms-theme-base' ),
424-
'suuri_teksti' => __( 'Large print', 'tms-theme-base' ),
425-
'vaatesailytys' => __( 'Cloakroom', 'tms-theme-base' ),
426-
'viitomakielinen_palvelu' => __( 'Sign-language services', 'tms-theme-base' ),
427-
'wc_oikea' => __( 'Accessible toilet: one-sided access', 'tms-theme-base' ),
428-
'wc_vasen' => __( 'Accessible toilet: one-sided access', 'tms-theme-base' ),
429-
'wc' => __( 'WC', 'tms-theme-base' ),
408+
'aaniopastus' => \__( 'Audio guide', 'tms-theme-base' ),
409+
'avustaja' => \__( 'Assistant', 'tms-theme-base' ),
410+
'hissi' => \__( 'Lift', 'tms-theme-base' ),
411+
'induktiosilmukka' => \__( 'Induction loop', 'tms-theme-base' ),
412+
'info' => \__( 'Information', 'tms-theme-base' ),
413+
'internet' => \__( 'Internet', 'tms-theme-base' ),
414+
'isa' => \__( 'Accessible entrance, Accessible toilet, Accessible parking', 'tms-theme-base' ),
415+
'kahvila' => \__( 'Café', 'tms-theme-base' ),
416+
'kauppa' => \__( 'Shop', 'tms-theme-base' ),
417+
'kokoustilaa' => \__( 'Meeting room', 'tms-theme-base' ),
418+
'lainattavia-valineita' => \__( 'Assistive device lending', 'tms-theme-base' ),
419+
'lastenhoitotila' => \__( 'Baby changing', 'tms-theme-base' ),
420+
'latauspiste' => \__( 'Charging point', 'tms-theme-base' ),
421+
'lipunmyynti' => \__( 'Ticket sales', 'tms-theme-base' ),
422+
'luiska' => \__( 'Ramp', 'tms-theme-base' ),
423+
'nakovammaisia_helpottavat_palvelut' => \__( 'Services for the visually impaired', 'tms-theme-base' ),
424+
'opaskoirat_sallittu' => \__( 'Service dogs allowed', 'tms-theme-base' ),
425+
'pistekirjoitus' => \__( 'Braille', 'tms-theme-base' ),
426+
'porrashissi' => \__( 'Stairlift', 'tms-theme-base' ),
427+
'portaat' => \__( 'Staircase', 'tms-theme-base' ),
428+
'pyoratuolihissi' => \__( 'Platform lift', 'tms-theme-base' ),
429+
'rollaattori' => \__( 'Rollator, walker', 'tms-theme-base' ),
430+
'sahkomopon_sailytys' => \__( 'Electric mobility scooter storage', 'tms-theme-base' ),
431+
'sailytyslokerot' => \__( 'Lockers', 'tms-theme-base' ),
432+
'suuri_teksti' => \__( 'Large print', 'tms-theme-base' ),
433+
'vaatesailytys' => \__( 'Cloakroom', 'tms-theme-base' ),
434+
'viitomakielinen_palvelu' => \__( 'Sign-language services', 'tms-theme-base' ),
435+
'wc_oikea' => \__( 'Accessible toilet: one-sided access', 'tms-theme-base' ),
436+
'wc_vasen' => \__( 'Accessible toilet: one-sided access', 'tms-theme-base' ),
437+
'wc' => \__( 'WC', 'tms-theme-base' ),
430438
];
431439
}
432440
}

0 commit comments

Comments
 (0)