JarvisLanguage::translate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace JarvisPHP\Core;
4
5
/**
6
 * JarvisLanguage
7
 *
8
 * @author Stefano Bianchini
9
 * @website http://www.stefanobianchini.net
10
 */
11
class JarvisLanguage {
12
    
13
    private static $data = array();
0 ignored issues
show
Unused Code introduced by
The property $data is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
    
15
    /**
16
     * Load core translations
17
     */
18
    public static function loadCoreTranslation() {
19
        $_lang = array();
20
        JarvisLanguage::$data['core'] = array();
21
        //Loading JarvisPHP Core language
22
        if(file_exists('language/JarvisPHP_'._LANGUAGE.'.php')) {
23
            require 'language/JarvisPHP_'._LANGUAGE.'.php';
24
            JarvisLanguage::$data['core'] = array_merge(JarvisLanguage::$data['core'], $_lang);
25
        }
26
    }
27
    
28
    /**
29
     * Load the translations of a plugin (plugin name)
30
     * @param string $plugin
31
     */
32
    public static function loadPluginTranslation($plugin) {
33
        $plugin_class = JarvisPHP::getRealClassName($plugin);
34
        $_lang = array();
35
        JarvisLanguage::$data[$plugin] = array();
36
        $language_file = 'Plugins/'.$plugin_class.'/language/'.$plugin_class."_"._LANGUAGE.'.php';
37
38
        //Check if translation file exists
39
        if(file_exists($language_file)) {
40
            require $language_file;
41
            JarvisLanguage::$data[$plugin] = array_merge(JarvisLanguage::$data[$plugin], $_lang);
42
        }
43
    }
44
    
45
    /**
46
     * Translate a string
47
     * @param string $text
48
     * @param string $plugin
49
     * @return string
50
     */
51
    public static function translate($text, $plugin='core') {
52
        if(isset(JarvisLanguage::$data[$plugin][$text])) {
53
            return JarvisLanguage::$data[$plugin][$text];
54
        } else {
55
            return $text;
56
        }
57
    }
58
    
59
}
60