{"action":"created","issue":{"url":"https://api.github.com/repos/angular-translate/angular-translate/issues/1188","labels_url":"https://api.github.com/repos/angular-translate/angular-translate/issues/1188/labels{/name}","comments_url":"https://api.github.com/repos/angular-translate/angular-translate/issues/1188/comments","events_url":"https://api.github.com/repos/angular-translate/angular-translate/issues/1188/events","html_url":"https://github.com/angular-translate/angular-translate/issues/1188","id":104390849,"number":1188,"title":"question: using custom loader & service to load view translations during runtime","user":{"login":"komushi","id":3174130,"avatar_url":"https://avatars.githubusercontent.com/u/3174130?v=3","gravatar_id":"","url":"https://api.github.com/users/komushi","html_url":"https://github.com/komushi","followers_url":"https://api.github.com/users/komushi/followers","following_url":"https://api.github.com/users/komushi/following{/other_user}","gists_url":"https://api.github.com/users/komushi/gists{/gist_id}","starred_url":"https://api.github.com/users/komushi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/komushi/subscriptions","organizations_url":"https://api.github.com/users/komushi/orgs","repos_url":"https://api.github.com/users/komushi/repos","events_url":"https://api.github.com/users/komushi/events{/privacy}","received_events_url":"https://api.github.com/users/komushi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-02T02:33:12Z","updated_at":"2015-09-13T17:00:14Z","closed_at":null,"body":"I have dynamic views based on controllers which need to load specific translations.\r\nI know my approach might not follow the best practice. But it might work - testing now.\r\n\r\nview controller:\r\n```\r\nangular.module('app')\r\n    .controller('HomeCtrl', ['$scope', 'viewName', function($scope, viewName) {\r\n\r\n\t\t$scope.clickChangeLanguage = function (localeCode) {\r\n\r\n\t\t\tvar json = {\"localeCode\":localeCode, \"viewName\":viewName};\r\n\t\t\t$translate.use(JSON.stringify(json));\r\n\t\t};\r\n\r\n    }]);\r\n```\r\n\r\ncustom loader:\r\n```\r\nvar asyncLoaderAPI = function( $q, dataService) {\r\n\r\n\treturn function (options) {\r\n\t    var deferred = $q.defer(),\r\n\t        translations;\r\n\r\n\t    var localOption = JSON.parse(options.key);\r\n\r\n\t\tdataService.getTranslationsData(localOption.viewName)\r\n\t\t\t.then(function (translations){\r\n\t\t\t\t/* dataService.getTranslationsData will call a REST API to retrieve translations programatically.\r\n\t\t\t\ttranslations =\r\n\t\t\t\t{\r\n\t\t\t\t  \"en-US\": {\r\n\t\t\t\t    \"Home\": \"Home\",\r\n\t\t\t\t    \"GREETING\": \"Hello there~~~\",\r\n\t\t\t\t    \"VAR\": \"Welcome，{{name}}！\"\r\n\t\t\t\t  },\r\n\t\t\t\t  \"zh-CN\": {\r\n\t\t\t\t    \"Home\": \"首页\",\r\n\t\t\t\t    \"GREETING\": \"你好\",\r\n\t\t\t\t    \"VAR\": \"欢迎，{{name}}！\"\r\n\t\t\t\t  },\r\n\t\t\t\t  \"zh-TW\": {\r\n\t\t\t\t    \"Home\": \"首頁\",\r\n\t\t\t\t    \"GREETING\": \"你好\",\r\n\t\t\t\t    \"VAR\": \"歡迎，{{name}}！\"\r\n\t\t\t\t  }\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t     deferred.resolve(translations[localOption.localeCode]);\r\n\t\t\t});\r\n\t \r\n\r\n\t \r\n\t    return deferred.promise;\r\n\t};\r\n};\r\n\r\nservices.factory('asyncLoader', [ '$q', 'dataService', asyncLoaderAPI]);\r\n```\r\n\r\nWhat I originally wanted is a custom loader which can load view translations partially - like the $translatePartialLoader but can do more complex REST API calls. Is there a reasonable and easy approach to achieve it?"},"comment":{"url":"https://api.github.com/repos/angular-translate/angular-translate/issues/comments/139894684","html_url":"https://github.com/angular-translate/angular-translate/issues/1188#issuecomment-139894684","issue_url":"https://api.github.com/repos/angular-translate/angular-translate/issues/1188","id":139894684,"user":{"login":"knalli","id":65389,"avatar_url":"https://avatars.githubusercontent.com/u/65389?v=3","gravatar_id":"","url":"https://api.github.com/users/knalli","html_url":"https://github.com/knalli","followers_url":"https://api.github.com/users/knalli/followers","following_url":"https://api.github.com/users/knalli/following{/other_user}","gists_url":"https://api.github.com/users/knalli/gists{/gist_id}","starred_url":"https://api.github.com/users/knalli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knalli/subscriptions","organizations_url":"https://api.github.com/users/knalli/orgs","repos_url":"https://api.github.com/users/knalli/repos","events_url":"https://api.github.com/users/knalli/events{/privacy}","received_events_url":"https://api.github.com/users/knalli/received_events","type":"User","site_admin":false},"created_at":"2015-09-13T17:00:14Z","updated_at":"2015-09-13T17:00:14Z","body":"Please elaborate a little more the actual question. So far, you have already implemented a custom loader and this is in use?"}}