Passed
Push — master ( 459d0e...53f14f )
by Jesus
06:22
created

main.js ➔ getLocalizedString   B

Complexity

Conditions 6

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
c 0
b 0
f 0
dl 0
loc 20
rs 8.6666
eloc 10
1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
$(document).on('turbolinks:load', function(){
18
  $.rails.refreshCSRFTokens();
19
})
20
21
document.addEventListener("turbolinks:before-cache", function() {
22
  $(".alert").remove()
23
})
24
25
// Gets the localized string
26
function getLocalizedString(key) {
27
  var keyArr = key.split(".")
28
  var translated = I18n
0 ignored issues
show
Bug introduced by
The variable I18n seems to be never declared. If this is a global, consider adding a /** global: I18n */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
29
30
  // Search current language for the key
31
  keyArr.forEach(function(k) {
32
    translated = translated[k]
33
  })
34
35
  // If key is not found, search the fallback language for the key
36
  if (translated == undefined) { 
0 ignored issues
show
Best Practice introduced by
Comparing translated to undefined using the == operator is not safe. Consider using === instead.
Loading history...
37
    translated = I18nFallback
0 ignored issues
show
Bug introduced by
The variable I18nFallback seems to be never declared. If this is a global, consider adding a /** global: I18nFallback */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
38
39
    keyArr.forEach(function(k) {
40
      translated = translated[k]
41
    })
42
  }
43
44
  return translated
45
}