Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez DavidPeralvarez/alert-button.js Secret
Created Mar 19, 2019

Embed
What would you like to do?
Internacionalizando Javascript
function dp_ip_show_text_1(){
alert(dp_ip_l10n.dp_ip_text_1);
}
function dp_ip_show_text_2(){
alert(dp_ip_l10n.dp_ip_text_2);
}
<?php
/*
Plugin Name: Internacionalizando Plugins
Description: Aprendiendo a internacionalizar plugins
Text Domain: internacionalizando-plugins
Domain Path: /languages
*/
add_action( 'plugins_loaded', 'dp_ip_load_textdomain' );
function dp_ip_load_textdomain(){
/*load_plugin_textdomain( 'internacionalizando-plugins', false, 'internacionalizando-plugins/languages');*/
/* /cursodesarrolloplugins/app/public/wp-content/plugins/internacionalizando-plugins/internacionalizando-plugins.php */
/* internacionalizando-plugins/internacionalizando-plugins.php */
/* internacionalizando-plugins */
load_plugin_textdomain( 'internacionalizando-plugins', false, dirname( plugin_basename(__FILE__)).'/languages' );
}
/* Incluimos nuestro script */
add_action( 'wp_enqueue_scripts', 'dp_ip_enqueue_scripts' );
function dp_ip_enqueue_scripts(){
wp_enqueue_script( 'dp-ip-alert-buttons', trailingslashit( plugins_url( 'internacionalizando-plugins' ) ) . 'js/alert-buttons.js' );
wp_localize_script( 'dp-ip-alert-buttons', 'dp_ip_l10n' ,
array(
'dp_ip_text_1' => __('Mensaje del alert 1','internacionalizando-plugins'),
'dp_ip_text_2' => __('Mensaje del alert 2','internacionalizando-plugins'),
)
);
}
/* Añadimos los botones que mostrarán las alertas */
add_action( 'wp_head', 'dp_ip_show_buttons' );
function dp_ip_show_buttons(){
?>
<p>
<input type="button" onclick="dp_ip_show_text_1()" value="<?php esc_attr_e('Botón 1','internacionalizando-plugins'); ?>">
<input type="button" onclick="dp_ip_show_text_2()" value="<?php esc_attr_e('Botón 2','internacionalizando-plugins'); ?>">
</p>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.