This is a way to do this without wp_localize_script. I do it this way with forms and scripts when I want to visualize the output inside a HEREDOC. I name a variable something like the string in my native English, l18n it first, and then put it where it goes in the heredoc:
$someText = __('Some Text', 'myPluginSlug');
$helloWorld = __('Hello World!!', 'myPluginSlug');
$output = <<<OUTPUT
$someText
<script>
alert('$helloWorld');
</script>
OUTPUT;
return $output;
Related Posts:
- How to provide translations for a WordPress TinyMCE plugin?
- `wp_set_script_translations` with `wp.i18n` does not return translated strings in simple plugin
- Translate javascript with WordPress built-in localization API for static strings
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to make a WordPress plugin translation ready?
- How to include jQuery and JavaScript files correctly?
- How to implement color picker from wordpress in my plugin?
- How can I run AJAX on a button click event?
- Add async script
- Can I use the wp media uploader for my own plugin?
- How-to implement admin Ajax inside an admin WP_List_Table?
- API to trigger prompt on leaving page
- Customizing the 3.5 “Add Media” popup (Backbone.js)
- Test to see if jQuery or Prototype is queued by another plugin?
- Include third party Javascript library which is not included in WordPress
- jQuery in header or footer
- Hook the Keydown Event in the TinyMCE Post Editor
- How to Add a .js file Only in one specific Page Dynamically to Head
- lodash dependency in a Gutenberg plugin
- wp_localize_script $handle
- Problems with localization
- How to prevent loading of all plugin’s resources?
- How to trap “Publish” button to check for meta box validation?
- Pass javascript result to shortcode executer function
- The changes I make to an external JS file of my WP plugin are only applied after I clear my browser’s cache
- How does gettext works for translating readme file of plugin?
- Use js script from one plugin in another plugin
- How do I only load js on the post-new.php and post.php pages in admin?
- creating elements/innerblocks via rangecontrol
- Can’t we use strings defined as PHP constants if we want to translate them in a plugin?
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- Making a custom widget that includes a tinymce and works in Site Origin Page Builder
- Looking for callback function after Gutenberg is rendered?
- use __($str) to translate strings (symfony/twig)
- Plugin Localization
- What’s the better way to add an inline script?
- Can’t get JS code to work with shortcode
- Is it possible to check is loaded language files correctly with WordPress plugin?
- How do I add a javascript file to all admin pages via a plugin?
- Gutenberg: useDispatch is not a function – @wordpress/data included
- Make a list with header and subtext in Gutenberg blocks
- Translate strings not recognised in plugin
- Gutenberg – What is the best way to save/update post meta?
- Prevent Javascript Facebook SDK Conflicts in plugin
- How to Load Plugin JS in theme’s footer section
- how to include javascript file and css file in wordpress
- Print WordPress username id inside JavaScript
- How to i18n text coming from the db or from an external source
- Mixing Regular Javascript With jQuery in a Plugin
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Why is my javascript not invoked in my hooks except wp_head?
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- Should shorcodes in i18n plugins be translated and if so, how?
- Where to call wp_enqueue_script in a plugin with custom template?
- Widget translation on my plugin
- Plugin translations not installed but… strings are translated!
- Is there an event or an other method that tells me the preview is loaded?
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- How to prevent UNDO on guternberg block editor
- Do I have to worry about useState causing a re-render?
- Generate JSON files for language translation from po file without wp-cli i18n make-json
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- wp.template() returns tags in Ajax response
- Gutenberg: import dependency or assign from global variable?
- My WordPress plugin cannot load my JavaScript file
- javascript datatables in a plugin
- Build a translation correcter plugin
- Translation per IP location [closed]
- Translate slug in WPMU with PO files
- add javascript files only when plugin is called?
- Inserting code to HTML view from a pop up initiated from visual view
- Translate MCE button text/tooltip in custom plugin
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- should i be checking for jquery before enqueing it in a plugin
- Loading custom js file on the admin page through plugin
- esc_html__() and __() not working within arrays
- How to prevent someone from entering strings without making it available for translation?
- Readme.txt seems to be cached but not the version
- Run JavaScript validation script on form submit in plugin
- Return Value of load_plugin_textdomain
- Custom Plugin – CSS works, JS doesn’t
- Plugin language always shows WP site language, not profile language
- Is hint for translator compulsory while internationalizing a string containing variables?
- Need help about understand api, wp, $ syntax in WordPress plugin script
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Translating plugin settings page – dropdown list
- Make dynamic string translatable
- Insert Into Post Not Working For Audio File Using jQuery
- Service Worker Uncaught (in promise) DOMException
- Developing the save function in Gutenberg blocks
- Gutenberg – is it ok to load dependencies multiple times?
- Preventing double loading JS scripts (like React) when developing for Gutenberg
- Using HTML links within translatable string