Skip to content

Commit

Permalink
Merge pull request #1987 from geoadmin/gal_fix_topic_translate
Browse files Browse the repository at this point in the history
Fix topic translation
  • Loading branch information
gjn committed Dec 18, 2014
2 parents 7d39111 + 81175d7 commit 2dacf42
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/components/topic/TopicDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]);

module.directive('gaTopic',
function($rootScope, $http, $translate, gaPermalink, gaLayers) {
function($rootScope, $http, $q, gaPermalink, gaLayers) {
return {
restrict: 'A',
replace: true,
Expand Down Expand Up @@ -56,24 +56,25 @@
return res;
}

function translateLabels() {
angular.forEach(scope.topics, function(value) {
value.label = $translate.instant(value.id);
});
}

$http.get(options.url).then(function(result) {
var topics = result.data.topics;
angular.forEach(topics, function(value) {
value.label = $translate.instant(value.id);
value.tooltip = 'topic_' + value.id + '_tooltip';
value.thumbnail =
options.thumbnailUrlTemplate.replace('{Topic}', value.id);
value.langs = extendLangs(value.langs);
});
scope.topics = topics;
initTopics();
});
var loadTopics = function(url) {
var deferred = $q.defer();
$http.get(url).
success(function(data) {
var topics = data.topics;
angular.forEach(topics, function(value) {
value.tooltip = 'topic_' + value.id + '_tooltip';
value.thumbnail =
options.thumbnailUrlTemplate.
replace('{Topic}', value.id);
value.langs = extendLangs(value.langs);
});
deferred.resolve(topics);
}).
error(function() {
deferred.reject();
});
return deferred.promise;
};

// Because ng-repeat creates a new scope for each item in the
// collection we can't use ng-click="activeTopic = topic" in
Expand Down Expand Up @@ -114,12 +115,14 @@
}
});

var firstLoad = true;
$rootScope.$on('$translateChangeEnd', function() {
if (!firstLoad) {
translateLabels();
} else {
firstLoad = false;
if (!scope.topics) {
loadTopics(options.url).then(
function(topics) {
scope.topics = topics;
initTopics();
}
);
}
});
}
Expand Down

0 comments on commit 2dacf42

Please sign in to comment.