From 268e2727cae18207468608f31558aad23f96e9c6 Mon Sep 17 00:00:00 2001 From: Volmer Soares Date: Fri, 6 Mar 2015 22:31:19 -0500 Subject: [PATCH] Default locale to `en` if translations are missing Fixes #24 --- app/assets/javascripts/bootsy.js | 2 +- app/assets/javascripts/bootsy/bootsy.js | 5 ++++- app/assets/javascripts/bootsy/init.js | 12 +++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/bootsy.js b/app/assets/javascripts/bootsy.js index 07a97d25..a95e4531 100644 --- a/app/assets/javascripts/bootsy.js +++ b/app/assets/javascripts/bootsy.js @@ -3,7 +3,7 @@ //= require bootsy/wysihtml5 //= require bootsy/bootstrap-wysihtml5 //= require bootsy/bootsy -//= require bootsy/bootstrap.file-input.js +//= require bootsy/bootstrap.file-input //= require bootsy/init //= require bootsy/editor_options //= require bootsy/translations diff --git a/app/assets/javascripts/bootsy/bootsy.js b/app/assets/javascripts/bootsy/bootsy.js index d9189c22..350cd1fe 100644 --- a/app/assets/javascripts/bootsy/bootsy.js +++ b/app/assets/javascripts/bootsy/bootsy.js @@ -5,8 +5,11 @@ window.Bootsy = window.Bootsy || {}; Bootsy.Area = function($el) { this.$el = $el; this.modal = $el.siblings('.bootsy-modal'); - this.locale = $el.data('bootsy-locale') || $('html').attr('lang') || 'en'; this.unsavedChanges = false; + this.locale = $el.data('bootsy-locale') || $('html').attr('lang'); + if (!Bootsy.translations[this.locale]) { + this.locale = 'en'; + } this.options = { locale: this.locale, diff --git a/app/assets/javascripts/bootsy/init.js b/app/assets/javascripts/bootsy/init.js index aa2b16b9..81cc5769 100644 --- a/app/assets/javascripts/bootsy/init.js +++ b/app/assets/javascripts/bootsy/init.js @@ -27,10 +27,12 @@ Bootsy.init = function() { /* Initialize Bootsy on document load */ $(function() { - Bootsy.init(); + $(window).load(function() { + Bootsy.init(); - /* Reload Bootsy on page load when using Turbolinks. */ - if (window.Turbolinks) { - $(document).on('page:load', Bootsy.init); - } + /* Reload Bootsy on page load when using Turbolinks. */ + if (window.Turbolinks) { + $(document).on('page:load', Bootsy.init); + } + }); });