[i18n] Add user language to the headers in all API requests

stable
David Barragán Merino 2015-04-21 20:42:21 +02:00
parent 3913712bbd
commit da17a265bf
1 changed files with 14 additions and 5 deletions

View File

@ -22,16 +22,25 @@
taiga = @.taiga
class HttpService extends taiga.Service
@.$inject = ["$http", "$q", "$tgStorage"]
@.$inject = ["$http", "$q", "$tgStorage", "$rootScope"]
constructor: (@http, @q, @storage, @rootScope) ->
super()
headers: ->
headers = {}
# Authorization
token = @storage.get('token')
if token
return {"Authorization":"Bearer #{token}"}
return {}
headers["Authorization"] = "Bearer #{token}"
constructor: (@http, @q, @storage) ->
super()
# Accept-Language
lang = @rootScope.user?.lang
if lang
headers["Accept-Language"] = lang
return headers
request: (options) ->
options.headers = _.merge({}, options.headers or {}, @.headers())