Completed
Push — master ( 866116...4a55ed )
by Ajeh
36s
created

src/docs/js/translations.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 30
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 6
c 1
b 0
f 0
nc 1
mnd 2
bc 5
fnc 3
dl 0
loc 30
rs 10
bpm 1.6666
cpm 2
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A translations.js ➔ Translator 0 6 2
A Translator.get 0 14 3
A translations.js ➔ ??? 0 3 1
1
// mini translator
2
3
import en from './translations/en'
4
5
6
const Translator = function (translations, separator = '.') {
7
    let lang = window.navigator.languages[1] || window.navigator.userLanguage[1]
8
    this.lang = typeof translations[lang] !== 'undefined' ? lang : 'en'
9
    this.separator = separator
10
    this.translations = translations
11
}
12
13
Translator.prototype.get = function (route) {
14
    let parts = route.split(this.separator)
15
    let translation = this.translations[this.lang]
16
17
    for (let i = 0; i < parts.length; i++) {
18
        translation = translation[parts[i]]
19
        if (translation === undefined) {
20
            translation = 'No Translation'
21
            break
22
        }
23
    }
24
25
    return translation
26
}
27
28
let T = new Translator({en})
29
30
export default function (n) {
31
    return T.get(n)
32
}