Skip to content

Instantly share code, notes, and snippets.

@ocReaper
Last active July 15, 2016 12:56
Show Gist options
  • Save ocReaper/61b646f319286c35a5072a98a3ecd962 to your computer and use it in GitHub Desktop.
Save ocReaper/61b646f319286c35a5072a98a3ecd962 to your computer and use it in GitHub Desktop.
Internationalize your WordPress javascripts
// the php file
<?php
wp_enqueue_script( 'custom-js', get_bloginfo( 'stylesheet_directory' ) . '/js/custom.js', array( 'jquery' ), '1.0' );
wp_localize_script(
'custom-js',
'theme_custom_js_i18n',
array(
'checkYourMail' => __( 'We\'ve sent you an e-mail with a link. Please click it to confirm your e-mail.' )
)
);
?>
// then in the js file you have a global variable called theme_custom_js_i18n which contains the array json_encode-ed
<script>
$(document).ready(function(theme_custom_js_i18n){
var checkYourMailHtml = theme_custom_js_i18n.checkYourMail;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment