-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_translator.php
More file actions
81 lines (71 loc) · 2.15 KB
/
Copy pathplugin_translator.php
File metadata and controls
81 lines (71 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
Plugin Name: Plugin Translator
Description: A translator plugin to translate strings to specified language.
Author: Nima
Version: 1.0
Text Domain: Plugin Translator
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( !class_exists( 'WpStringTranslator' )) {
class WpStringTranslator{
function __construct(){
add_action( 'init', array($this,'load_textdomain' ));
add_action('admin_menu',array($this,'wp_setup_translator_menu'));
add_filter( 'the_content', array($this,'wp_display_date_and_time' ));
add_action('wp_enqueue_scripts', array($this,'load_scripts'));
}
public function wp_setup_translator_menu(){
add_menu_page(
__( 'StringTranslator', 'plugin_translator' ),
__( 'StringTranslator', 'plugin_translator' ),
'manage_options',
'translator_settings',
array($this, 'test_init'),
);
}
public function test_init(){
$greeting = __( 'Good Morning!', 'plugin_translator' );
?> <h1><?php _e("Hello world",'plugin_translator'); ?></h1> <?php
echo $greeting;
?>
<!--
<br><br>
<button onclick="displayalert(this,event)" id="exitbutton" ></button>
<script>
function displayalert() {
alert("Are you sure you want to exit?");
}
</script>
-->
<?php
}
public function wp_display_date_and_time($content){
$post_type = get_post_type();
if ($post_type == 'post'){
//date_default_timezone_set('Indian/Mahe');
$date = __("Today's Date is : ",'plugin_translator');
$date .= date('Y-m-d');
$date .= "<br><br>";
$time = __("Current Time is : ",'plugin_translator');
$time .= date('g:i:a');
return $content.$date.$time;
}
else{
$content;
}
}
public function load_textdomain() {
load_plugin_textdomain( 'plugin_translator', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
public function load_scripts() {
//wp_register_script('demo',plugins_url('demo.js', __FILE__),array('wp-i18n'),false,true);
wp_enqueue_script('demo-js',plugins_url( '/demo.js', __FILE__ ));
wp_set_script_translations('demo-js', 'plugin_translator', plugin_dir_path(__FILE__) . 'languages/');
}
}
$objtranslator = new WpStringTranslator();
}
?>