fix(locale): Fix merge conflicts (#1794)
This commit is contained in:
Родитель
1158477084
Коммит
5406b56053
|
@ -152,7 +152,7 @@ module.exports = log => {
|
|||
|
||||
return request.gatherMetricsContext({
|
||||
event: event,
|
||||
locale: marshallLocale(request),
|
||||
locale: request.app && request.app.locale,
|
||||
userAgent: request.headers['user-agent']
|
||||
}).then(data => {
|
||||
if (data.flow_id) {
|
||||
|
@ -187,12 +187,6 @@ function optionallySetService (data, request) {
|
|||
(request.query && request.query.service)
|
||||
}
|
||||
|
||||
function marshallLocale (request) {
|
||||
if (request.app && request.app.locale) {
|
||||
return `${request.app.locale}${request.app.isLocaleAcceptable ? '' : '.default'}`
|
||||
}
|
||||
}
|
||||
|
||||
function coalesceUid (data, request) {
|
||||
if (data && data.uid) {
|
||||
return Buffer.isBuffer(data.uid) ? data.uid.toString('hex') : data.uid
|
||||
|
|
|
@ -287,9 +287,7 @@ function create(log, error, config, routes, db, translator) {
|
|||
|
||||
const acceptLanguage = trimLocale(request.headers['accept-language'])
|
||||
request.app.acceptLanguage = acceptLanguage
|
||||
const locale = translator.getLocale(acceptLanguage)
|
||||
request.app.locale = locale
|
||||
request.app.isLocaleAcceptable = isLocaleAcceptable(locale, acceptLanguage)
|
||||
request.app.locale = translator.getLocale(acceptLanguage)
|
||||
|
||||
if (request.headers.authorization) {
|
||||
// Log some helpful details for debugging authentication problems.
|
||||
|
@ -346,10 +344,6 @@ function create(log, error, config, routes, db, translator) {
|
|||
return server
|
||||
}
|
||||
|
||||
function isLocaleAcceptable (locale, acceptLanguage) {
|
||||
return RegExp(`^(?:.+, *)*${locale}(?:[,-].+)*$`, 'i').test(acceptLanguage)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
create: create,
|
||||
// Functions below exported for testing
|
||||
|
|
|
@ -190,7 +190,6 @@ describe('metrics/events', () => {
|
|||
const metricsContext = mocks.mockMetricsContext()
|
||||
const request = {
|
||||
app: {
|
||||
isLocaleAcceptable: false,
|
||||
locale: 'en'
|
||||
},
|
||||
auth: null,
|
||||
|
@ -219,7 +218,7 @@ describe('metrics/events', () => {
|
|||
flow_id: 'bar',
|
||||
flow_time: 1000,
|
||||
flowCompleteSignal: 'account.signed',
|
||||
locale: 'en.default',
|
||||
locale: 'en',
|
||||
time,
|
||||
userAgent: 'foo'
|
||||
}, 'argument was event data')
|
||||
|
|
|
@ -114,7 +114,6 @@ describe('lib/server', () => {
|
|||
assert.ok(args[1])
|
||||
assert.equal(args[1].path, '/account/create')
|
||||
assert.equal(args[1].app.locale, 'en')
|
||||
assert.equal(args[1].app.isLocaleAcceptable, true)
|
||||
})
|
||||
|
||||
it('called log.summary correctly', () => {
|
||||
|
@ -152,7 +151,6 @@ describe('lib/server', () => {
|
|||
assert.equal(log.begin.callCount, 1)
|
||||
const args = log.begin.args[0]
|
||||
assert.equal(args[1].app.locale, 'en')
|
||||
assert.equal(args[1].app.isLocaleAcceptable, false)
|
||||
})
|
||||
|
||||
it('called log.summary once', () => {
|
||||
|
|
|
@ -358,7 +358,6 @@ function mockRequest (data) {
|
|||
app: {
|
||||
acceptLanguage: 'en-US',
|
||||
clientAddress: data.clientAddress || '63.245.221.32',
|
||||
isLocaleAcceptable: true,
|
||||
locale: data.locale || 'en-US'
|
||||
},
|
||||
auth: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче