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
- 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 can I run AJAX on a button click event?
- Can I use the wp media uploader for my own plugin?
- How-to implement admin Ajax inside an admin WP_List_Table?
- 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
- lodash dependency in a Gutenberg plugin
- wp_localize_script $handle
- Problems with localization
- How does gettext works for translating readme file of 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?
- use __($str) to translate strings (symfony/twig)
- Plugin Localization
- Can’t get JS code to work with shortcode
- How do I add a javascript file to all admin pages via a plugin?
- 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?
- How to Load Plugin JS in theme’s footer section
- Print WordPress username id inside JavaScript
- How to i18n text coming from the db or from an external source
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- Widget translation on my plugin
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- Gutenberg: import dependency or assign from global variable?
- javascript datatables in a plugin
- Build a translation correcter plugin
- Translation per IP location [closed]
- add javascript files only when plugin is called?
- Translate MCE button text/tooltip in custom plugin
- 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?
- 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
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- 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
- About a programming language starts with [closed]
- Referencing files in JavaScript in WordPress Plugin
- How to translate wordpress backend to another language
- Should I put my plugin javascript inline?
- Borrowing of Previously Translated Strings by Child Plugin
- wp.media libary pdf type
- Query String Filtering API
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- HTML Elements in my WP Plugin being generated in JS. Security and Translated Text Question about this method being used
- converting a node.js project into a wp plugin
- What happens/fires when you select a block in the editor?
- Is “document loaded” different on admin side than public side?
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- jQueryUI draggable doesn’t work in WordPress plugin
- Load script on frontend from widget plugin
- WordPress with React: Saving and Using Data Collected with fetch
- Append php file to footer
- Load custom translation in custom plugin fails
- XMLHttpRequest to open PHP file responds with Missing Page
- Replace the WordPress Media Library Uploader
- Using JavaScript in WordPress page to call for server data using AJAX
- Filterable posts using categories
- Translation not working for Constant strings in Plugin
- Uncaught ReferenceError: kpoejy is not defined
- Remove from a div by class name from post page if post author role is not administrator
- Load textdomain from global languages directory
- Plugin translation not being displayed
- On one of my sites a file is shown as 404 but the file IS there
- Problem with Poedit [closed]
- How can i add insertion point between inner blocks in my custom block like core blocks
- How react js and other Javascript Technologies works on WordPress plugin?
- get the queried_object of an url
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- Save translation file of third party plugin in a custom plugin?
- Trouble Importing whatsapp-web.js in a WordPress Plugin Development
- Reinitiate Gutenburg’s blocks using javascript
- how to add contact form 7 shortcode in javascript variable