Last active
July 15, 2016 12:56
-
-
Save ocReaper/61b646f319286c35a5072a98a3ecd962 to your computer and use it in GitHub Desktop.
Internationalize your WordPress javascripts
This file contains 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
// 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