From 9e32559fa49bd23b54b2b9bc18783ed6d8e9bbab Mon Sep 17 00:00:00 2001 From: Daniel Marreiros de Oliveira Date: Tue, 25 Aug 2015 11:28:42 +0200 Subject: [PATCH] When translations not loaded yet, return empty string. --- Gruntfile.js | 6 +++--- dist/idai-components.js | 10 ++++++---- dist/idai-components.min.js | 2 +- src/js/services_transl8.js | 10 ++++++---- test/services_transl8_spec.js | 11 +++++++++++ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 32b7c82..d76e1c6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -102,10 +102,10 @@ module.exports = function(grunt) { 'watch' ]); - grunt.registerTask('build', ['html2js','concat','uglify','cssmin']); + grunt.registerTask('test', ['karma:unit']); - grunt.registerTask('test', ['karma:unit','karma:continuous']); + grunt.registerTask('build', ['test','html2js','concat','uglify','cssmin']); - grunt.registerTask('default', ['test', 'build']); + grunt.registerTask('default', ['build']); }; diff --git a/dist/idai-components.js b/dist/idai-components.js index 71bce1e..9ba2fba 100644 --- a/dist/idai-components.js +++ b/dist/idai-components.js @@ -709,28 +709,30 @@ angular.module('idai.components') "translation/jsonp?application=arachne4_frontend&lang={LANG}&callback=JSON_CALLBACK"; - var translationLang=ENGLISH_LANG; + var translationsLoaded = false; + var translations={}; // Map: [transl8_key,translation]. + + if (primaryBrowserLanguage.browserPrimaryLanguage()=='de') translationLang='de'; var transl8Url = TRANSL8_JSONP_URL.replace('{LANG}',translationLang); - var translations={}; // Map: [transl8_key,translation]. $http.jsonp(transl8Url). success(function(data) { - for(var i = 0; i < data.length; i++) { translations[data[i].key] = data[i].value; } + translationsLoaded=true; }). error(function() { alert("ERROR: Could not get translations. Try to reload the page or send a mail to arachne@uni-koeln.de"); }); return { - getTranslation: function(key) { + if (!translationsLoaded) return ''; var translation = translations[key]; if (!translation || 0 === translation.length) diff --git a/dist/idai-components.min.js b/dist/idai-components.min.js index 2e8c097..196ec72 100644 --- a/dist/idai-components.min.js +++ b/dist/idai-components.min.js @@ -1 +1 @@ -angular.module("idai.templates",["partials/directives/idai-footer.html","partials/directives/idai-navbar.html","partials/directives/idai-picker.html"]),angular.module("partials/directives/idai-footer.html",[]).run(["$templateCache",function(a){a.put("partials/directives/idai-footer.html",'')}]),angular.module("partials/directives/idai-navbar.html",[]).run(["$templateCache",function(a){a.put("partials/directives/idai-navbar.html",'\n')}]),angular.module("partials/directives/idai-picker.html",[]).run(["$templateCache",function(a){a.put("partials/directives/idai-picker.html",'
\n \n \n\n
\n \n \n \n \n {{ \'pick_an_item\' | transl8 }}\n \n {{ getTitleField(selectedItem) }}\n \n {{ getTitleField(selectedItem) }}\n \n \n
\n\n \n\n
')}]),angular.module("idai.components",[]),angular.module("idai.components").directive("idaiFooter",function(){return{restrict:"E",scope:{mailto:"@"},templateUrl:"partials/directives/idai-footer.html",controller:["$scope","$http","localizedContent",function(a,b,c){a.date=new Date,a.getFooterLinks=function(d){b.get("info/content.json").success(function(b){var d=c.getNodeById(b,"footer");void 0==d&&console.log("error: no footerLinks found"),c.reduceTitles(d),a.dynamicLinkList=d.children})}}],link:function(a,b,c){a.getFooterLinks(c.contentDir)}}}),angular.module("idai.components").directive("includeReplace",function(){return{require:"ngInclude",restrict:"A",link:function(a,b,c){b.replaceWith(b.children())}}}),angular.module("idai.components").directive("idaiNavbar",function(){return{restrict:"E",scope:{userObject:"=",loginFunction:"&",logoutFunction:"&",hideSearchForm:"=",projectId:"@"},templateUrl:"partials/directives/idai-navbar.html",controller:["$scope","$http","localizedContent","$location",function(a,b,c,d){a.getNavbarLinks=function(d){b.get("info/content.json").success(function(b){var d=c.getNodeById(b,"navbar");void 0==d&&console.log("error: no navbarLinks found"),c.reduceTitles(d),a.dynamicLinkList=d.children})},a.search=function(b){if(a.q){var c="/search?q="+a.q;b&&(c+="&fq="+b),a.q=null,d.url(c)}}}],link:function(a,b,c){a.getNavbarLinks(c.contentDir)}}}),angular.module("idai.components").directive("idaiPicker",function(){return{restrict:"E",scope:{searchUri:"@",resultField:"@",titleField:"@",totalField:"@",queryParam:"@",limitParam:"@",offsetParam:"@",addParams:"=",selectedItem:"="},templateUrl:"partials/directives/idai-picker.html",controller:["$scope","$parse","$modal",function(a,b,c){a.openModal=function(){var b=c.open({templateUrl:"picker_modal.html",controller:"PickerModalController",bindToController:!0,size:"lg",scope:a});b.result.then(function(b){a.selectedItem=b})},a.$watch("titleField",function(c){c||(c="title"),a.getTitleField=b(c)})}]}}).controller("PickerModalController",["$scope","$http","$q","$parse","$modalInstance",function(a,b,c,d,e){var f;a.result,a.total=0,a.offset=0,a.limit=10,a.loading=!1,a.preselect=0;var g=function(){if(f&&f.resolve(),a.query){a.loading=!0,f=c.defer(),a.queryParam||(a.queryParam="q"),a.limitParam||(a.limitParam="limit"),a.offsetParam||(a.offsetParam="offset");var e=a.searchUri+"?"+a.queryParam+"="+a.query;e+="&"+a.limitParam+"="+a.limit,e+="&"+a.offsetParam+"="+a.offset,a.addParams&&angular.forEach(a.addParams,function(a,b){e+="&"+b+"="+a}),b.get(e,{timeout:f.promise}).then(function(b){a.resultField||(a.resultField="result");var c=d(a.resultField);0==a.offset?a.result=c(b.data):a.result=a.result.concat(c(b.data)),a.totalField||(a.totalField="total");var e=d(a.totalField);a.total=e(b.data),a.loading=!1})}else a.result=[],a.total=0};a.more=function(){a.offset+=a.limit,g()},a.keydown=function(b){console.log(b.keyCode),40==b.keyCode&&a.preselect0&&a.preselect--},a.keypress=function(b){13==b.keyCode&&(a.total>0&&a.query==a.lastQuery?(b.stopPropagation(),a.selectItem(a.result[a.preselect])):a.newQuery())},a.newQuery=function(){a.lastQuery=a.query,a.offset=0,g()},a.open=function(a){window.open(a,"_blank")},a.selectItem=function(a){e.close(a)},a.$watch("titleField",function(b){b||(b="title"),a.getTitleField=d(b)})}]),angular.module("idai.components").filter("transl8",["transl8",function(a){var b=function(b){var c=a.getTranslation(b);return c};return b.$stateful=!0,b}]),angular.module("idai.components").factory("language",function(){var a=navigator.languages?navigator.languages[0]:navigator.language||navigator.userLanguage;return"de"==a.substring(0,2)&&(a="de"),"en"==a.substring(0,2)&&(a="en"),{browserPrimaryLanguage:function(){return a}}}),angular.module("idai.components").factory("languageSelection",["language",function(a){var b="de",c="en";return{__:function(d,e,f){return a.browserPrimaryLanguage()==b?void e(b,f):void(d(a.browserPrimaryLanguage(),f)?e(a.browserPrimaryLanguage(),f):a.browserPrimaryLanguage()==c?e(b,f):d(c,f)?e(c,f):e(b,f))}}}]),angular.module("idai.components").factory("localizedContent",["languageSelection",function(a){return{reduceTitles:function(b){var c=function(a,b){b.title&&(b.title=b.title[a])},d=function(a,b){return b.title?b.title[a]:!1},e=function(b){if(a.__(d,c,b),b.children)for(var f=0;f\n
\n

\n \n \n \n

\n

\n {{\'footer_licensed_under\'|transl8}}\n Creative Commons |\n \n {{link.title}} |\n \n {{\'footer_bugs_to\'|transl8}}\n {{mailto}}

\n
\n')}]),angular.module("partials/directives/idai-navbar.html",[]).run(["$templateCache",function(a){a.put("partials/directives/idai-navbar.html",'\n')}]),angular.module("partials/directives/idai-picker.html",[]).run(["$templateCache",function(a){a.put("partials/directives/idai-picker.html",'
\n \n \n\n
\n \n \n \n \n {{ \'pick_an_item\' | transl8 }}\n \n {{ getTitleField(selectedItem) }}\n \n {{ getTitleField(selectedItem) }}\n \n \n
\n\n \n\n
')}]),angular.module("idai.components",[]),angular.module("idai.components").directive("idaiFooter",function(){return{restrict:"E",scope:{mailto:"@"},templateUrl:"partials/directives/idai-footer.html",controller:["$scope","$http","localizedContent",function(a,b,c){a.date=new Date,a.getFooterLinks=function(d){b.get("info/content.json").success(function(b){var d=c.getNodeById(b,"footer");void 0==d&&console.log("error: no footerLinks found"),c.reduceTitles(d),a.dynamicLinkList=d.children})}}],link:function(a,b,c){a.getFooterLinks(c.contentDir)}}}),angular.module("idai.components").directive("includeReplace",function(){return{require:"ngInclude",restrict:"A",link:function(a,b,c){b.replaceWith(b.children())}}}),angular.module("idai.components").directive("idaiNavbar",function(){return{restrict:"E",scope:{userObject:"=",loginFunction:"&",logoutFunction:"&",hideSearchForm:"=",projectId:"@"},templateUrl:"partials/directives/idai-navbar.html",controller:["$scope","$http","localizedContent","$location",function(a,b,c,d){a.getNavbarLinks=function(d){b.get("info/content.json").success(function(b){var d=c.getNodeById(b,"navbar");void 0==d&&console.log("error: no navbarLinks found"),c.reduceTitles(d),a.dynamicLinkList=d.children})},a.search=function(b){if(a.q){var c="/search?q="+a.q;b&&(c+="&fq="+b),a.q=null,d.url(c)}}}],link:function(a,b,c){a.getNavbarLinks(c.contentDir)}}}),angular.module("idai.components").directive("idaiPicker",function(){return{restrict:"E",scope:{searchUri:"@",resultField:"@",titleField:"@",totalField:"@",queryParam:"@",limitParam:"@",offsetParam:"@",addParams:"=",selectedItem:"="},templateUrl:"partials/directives/idai-picker.html",controller:["$scope","$parse","$modal",function(a,b,c){a.openModal=function(){var b=c.open({templateUrl:"picker_modal.html",controller:"PickerModalController",bindToController:!0,size:"lg",scope:a});b.result.then(function(b){a.selectedItem=b})},a.$watch("titleField",function(c){c||(c="title"),a.getTitleField=b(c)})}]}}).controller("PickerModalController",["$scope","$http","$q","$parse","$modalInstance",function(a,b,c,d,e){var f;a.result,a.total=0,a.offset=0,a.limit=10,a.loading=!1,a.preselect=0;var g=function(){if(f&&f.resolve(),a.query){a.loading=!0,f=c.defer(),a.queryParam||(a.queryParam="q"),a.limitParam||(a.limitParam="limit"),a.offsetParam||(a.offsetParam="offset");var e=a.searchUri+"?"+a.queryParam+"="+a.query;e+="&"+a.limitParam+"="+a.limit,e+="&"+a.offsetParam+"="+a.offset,a.addParams&&angular.forEach(a.addParams,function(a,b){e+="&"+b+"="+a}),b.get(e,{timeout:f.promise}).then(function(b){a.resultField||(a.resultField="result");var c=d(a.resultField);0==a.offset?a.result=c(b.data):a.result=a.result.concat(c(b.data)),a.totalField||(a.totalField="total");var e=d(a.totalField);a.total=e(b.data),a.loading=!1})}else a.result=[],a.total=0};a.more=function(){a.offset+=a.limit,g()},a.keydown=function(b){console.log(b.keyCode),40==b.keyCode&&a.preselect0&&a.preselect--},a.keypress=function(b){13==b.keyCode&&(a.total>0&&a.query==a.lastQuery?(b.stopPropagation(),a.selectItem(a.result[a.preselect])):a.newQuery())},a.newQuery=function(){a.lastQuery=a.query,a.offset=0,g()},a.open=function(a){window.open(a,"_blank")},a.selectItem=function(a){e.close(a)},a.$watch("titleField",function(b){b||(b="title"),a.getTitleField=d(b)})}]),angular.module("idai.components").filter("transl8",["transl8",function(a){var b=function(b){var c=a.getTranslation(b);return c};return b.$stateful=!0,b}]),angular.module("idai.components").factory("language",function(){var a=navigator.languages?navigator.languages[0]:navigator.language||navigator.userLanguage;return"de"==a.substring(0,2)&&(a="de"),"en"==a.substring(0,2)&&(a="en"),{browserPrimaryLanguage:function(){return a}}}),angular.module("idai.components").factory("languageSelection",["language",function(a){var b="de",c="en";return{__:function(d,e,f){return a.browserPrimaryLanguage()==b?void e(b,f):void(d(a.browserPrimaryLanguage(),f)?e(a.browserPrimaryLanguage(),f):a.browserPrimaryLanguage()==c?e(b,f):d(c,f)?e(c,f):e(b,f))}}}]),angular.module("idai.components").factory("localizedContent",["languageSelection",function(a){return{reduceTitles:function(b){var c=function(a,b){b.title&&(b.title=b.title[a])},d=function(a,b){return b.title?b.title[a]:!1},e=function(b){if(a.__(d,c,b),b.children)for(var f=0;f