Skip to content

Commit

Permalink
Merge 278e375 into b880061
Browse files Browse the repository at this point in the history
  • Loading branch information
StijnVrolijk committed Jun 27, 2019
2 parents b880061 + 278e375 commit c22be25
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Frontend/Core/Js/frontend.js
Expand Up @@ -517,10 +517,17 @@ jsFrontend.gravatar = {
*/
jsFrontend.locale = {
initialized: false,
initializing: false,
data: {},

// init, something like a constructor
init: function () {
if (typeof jsFrontend.current.language == 'undefined') {
return
}

jsFrontend.locale.initializing = true

$.ajax({
url: '/src/Frontend/Cache/Locale/' + jsFrontend.current.language + '.json',
type: 'GET',
Expand All @@ -529,6 +536,7 @@ jsFrontend.locale = {
success: function (data) {
jsFrontend.locale.data = data
jsFrontend.locale.initialized = true
jsFrontend.locale.initializing = true
},
error: function (jqXHR, textStatus, errorThrown) {
throw new Error('Regenerate your locale-files.')
Expand All @@ -539,10 +547,24 @@ jsFrontend.locale = {
// get an item from the locale
get: function (type, key) {
// initialize if needed
if (!jsFrontend.locale.initialized) jsFrontend.locale.init()
if (!jsFrontend.locale.initialized && !jsFrontend.locale.initializing) jsFrontend.locale.init()

if (!jsFrontend.locale.initialized) {
setTimeout(
function () {
return jsFrontend.locale.get(type, key)
},
30
)

return;
}

// validate
if (typeof jsFrontend.locale.data[type][key] === 'undefined') return '{$' + type + key + '}'
if (typeof jsFrontend.locale.data[type] === 'undefined'
|| typeof jsFrontend.locale.data[type][key] === 'undefined') {
return '{$' + type + key + '}'
}

return jsFrontend.locale.data[type][key]
},
Expand Down

0 comments on commit c22be25

Please sign in to comment.