PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.1
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / class-wpsc-translations.php

class-wpsc-translations.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.1, at includes/class-wpsc-translations.php

109 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Translations' ) ) :
7
8 final class WPSC_Translations {
9
10 /**
11 * Init class
12 */
13 public static function init() {
14 add_action( 'admin_init', array( __CLASS__, 'register_strings' ) );
15 }
16
17 /**
18 * Register custom strings for translation
19 */
20 public static function register_strings() {
21
22 $strings = get_option( 'wpsc-string-translation', array() );
23
24 // latest compatible.
25 if ( defined( 'WPML_PLUGIN_PATH' ) ) {
26 foreach ( $strings as $name => $str ) {
27 do_action( 'wpml_register_single_string', 'SupportCandy', $name, $str );
28 }
29 return;
30 }
31
32 // depricated but being used by other rival plugins like polylang, translatepress, etc.
33 if ( function_exists( 'icl_register_string' ) ) {
34 foreach ( $strings as $name => $str ) {
35 icl_register_string( 'SupportCandy', $name, $str );
36 }
37 return;
38 }
39 }
40
41 /**
42 * Get translated string
43 *
44 * @param mixed $name - String index given earlier while adding it to translation.
45 * @param mixed $str - String to be translated.
46 * @return mixed
47 */
48 public static function get( $name, $str ) {
49
50 // latest compatible.
51 if ( defined( 'WPML_PLUGIN_PATH' ) ) {
52 return apply_filters( 'wpml_translate_single_string', $str, 'SupportCandy', $name, ICL_LANGUAGE_CODE );
53 }
54
55 if ( function_exists( 'icl_t' ) ) {
56 return icl_t( 'SupportCandy', $name );
57 }
58
59 return $str;
60 }
61
62 /**
63 * Adds a string to translation
64 *
65 * @param mixed $name - Unique index for string.
66 * @param mixed $str - String to be translated.
67 * @return void
68 */
69 public static function add( $name, $str ) {
70
71 if ( ! $str ) {
72 return;
73 }
74
75 $strings = get_option( 'wpsc-string-translation', array() );
76 if ( isset( $strings[ $name ] ) ) {
77 self::remove( $name );
78 }
79
80 $strings[ $name ] = $str;
81 update_option( 'wpsc-string-translation', $strings );
82
83 // register strings.
84 self::register_strings();
85 }
86
87 /**
88 * Remove string from translation
89 *
90 * @param string $name - translation string name.
91 * @return void
92 */
93 public static function remove( $name ) {
94
95 if ( function_exists( 'icl_unregister_string' ) ) {
96 icl_unregister_string( 'SupportCandy', $name );
97 }
98
99 $strings = get_option( 'wpsc-string-translation', array() );
100 if ( isset( $strings[ $name ] ) ) {
101 unset( $strings[ $name ] );
102 update_option( 'wpsc-string-translation', $strings );
103 }
104 }
105 }
106 endif;
107
108 WPSC_Translations::init();
109