Skip to content

Commit

Permalink
When translations not loaded yet, return empty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarreirosdeoliveira committed Aug 25, 2015
1 parent a7390a6 commit 9e32559
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

};
10 changes: 6 additions & 4 deletions dist/idai-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]");
});

return {

getTranslation: function(key) {
if (!translationsLoaded) return '';

var translation = translations[key];
if (!translation || 0 === translation.length)
Expand Down
2 changes: 1 addition & 1 deletion dist/idai-components.min.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/js/services_transl8.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,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 [email protected]");
});

return {

getTranslation: function(key) {
if (!translationsLoaded) return '';

var translation = translations[key];
if (!translation || 0 === translation.length)
Expand Down
11 changes: 11 additions & 0 deletions test/services_transl8_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ describe('transl8', function (){
$httpBackend.flush();
expect(transl8.getTranslation(KEY_INVALID).substring(0,4)).toBe(TRANSLATION_MISSING);
});



it ('shows nothing if items not loaded yet', function () {

prepare('da');

expect(transl8.getTranslation(KEY)).toBe('');
});


});

0 comments on commit 9e32559

Please sign in to comment.