allow customize all messages for i18n

This commit is contained in:
Pooya Parsa 2017-09-01 21:00:49 +04:30
parent 2e11827209
commit 0d4bbf0b03
6 changed files with 20 additions and 15 deletions

View File

@ -228,7 +228,7 @@ async function render (to, from, next) {
await callMiddleware.call(this, Components, context, layout)
if (context._redirected) return
this.error({ statusCode: 404, message: 'This page could not be found.' })
this.error({ statusCode: 404, message: '<%= messages.error_404 %>' })
return next()
}
@ -272,7 +272,7 @@ async function render (to, from, next) {
})
// ...If .validate() returned false
if (!isValid) {
this.error({ statusCode: 404, message: 'This page could not be found.' })
this.error({ statusCode: 404, message: '<%= messages.error_404 %>' })
return next()
}

View File

@ -5,16 +5,14 @@
<div class="title">{{ message }}</div>
<p class="description" v-if="statusCode === 404">
<nuxt-link class="error-link" to="/">Back to the home page</nuxt-link>
<nuxt-link class="error-link" to="/"><%= messages.back_to_home %></nuxt-link>
</p>
<% if(debug) { %>
<p class="description" v-else>
An error occurred while rendering the page. Check developer tools console for details.
</p>
<p class="description" v-else><%= messages.client_error_details %></p>
<% } %>
<div class="logo">
Powered by <a href="https://nuxtjs.org" target="_blank" rel="noopener">Nuxt.js</a>
<a href="https://nuxtjs.org" target="_blank" rel="noopener"><%= messages.nuxtjs %></a>
</div>
</div>
</div>
@ -50,7 +48,7 @@ export default {
return (this.error && this.error.statusCode) || 500
},
message () {
return this.error.message || 'Nuxt Server Error'
return this.error.message || '<%= messages.client_error %>'
}
}
}

View File

@ -193,7 +193,7 @@ export default async context => {
// If no Components found, returns 404
if (!Components.length) {
context.nuxt.error = context.error({ statusCode: 404, message: 'This page could not be found.' })
context.nuxt.error = context.error({ statusCode: 404, message: '<%= messages.error_404 %>' })
}
<% if (isDev) { %>if (asyncDatas.length) debug('Data fetching ' + context.url + ': ' + (Date.now() - s) + 'ms')<% } %>

View File

@ -1,22 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Application error</title>
<title><%= messages.server_error %></title>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name=viewport>
<style>
.__nuxt-error-page{background:#f7f8fb;color:#47494e;text-align:center;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;font-family:sans-serif;font-weight:100!important;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-font-smoothing:antialiased;position:absolute;top:0;left:0;right:0;bottom:0}.__nuxt-error-page .error{max-width:450px}.__nuxt-error-page .title{font-size:24px;font-size:1.5rem;margin-top:15px;color:#47494e;margin-bottom:8px}.__nuxt-error-page .description{color:#7f828b;line-height:21px;margin-bottom:10px}.__nuxt-error-page a{color:#7f828b!important;text-decoration:none}.__nuxt-error-page .logo{position:fixed;right:12px;bottom:12px}
.__nuxt-error-page{background:#f7f8fb;color:#47494e;text-align:center;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;font-family:sans-serif;font-weight:100!important;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-font-smoothing:antialiased;position:absolute;top:0;left:0;right:0;bottom:0}.__nuxt-error-page .error{max-width:450px}.__nuxt-error-page .title{font-size:24px;font-size:1.5rem;margin-top:15px;color:#47494e;margin-bottom:8px}.__nuxt-error-page .description{color:#7f828b;line-height:21px;margin-bottom:10px}.__nuxt-error-page a{color:#7f828b!important;text-decoration:none}.__nuxt-error-page .logo{position:fixed;left:12px;bottom:12px}
</style>
</head>
<body>
<div class="__nuxt-error-page">
<div class="error">
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" fill="#DBE1EC" viewBox="0 0 48 48"><path d="M22 30h4v4h-4zm0-16h4v12h-4zm1.99-10C12.94 4 4 12.95 4 24s8.94 20 19.99 20S44 35.05 44 24 35.04 4 23.99 4zM24 40c-8.84 0-16-7.16-16-16S15.16 8 24 8s16 7.16 16 16-7.16 16-16 16z"/></svg>
<div class="title">Application error</div>
<div class="description"><% if (debug) { %>{{ message }}<% } else { %>An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.<% } %></div>
<div class="title"><%= messages.server_error %></div>
<div class="description"><% if (debug) { %>{{ message }}<% } else { %><%= messages.server_error_details %><% } %></div>
</div>
<div class="logo">
Powered by <a href="https://nuxtjs.org" target="_blank" rel="noopener">Nuxt.js</a>
<a href="https://nuxtjs.org" target="_blank" rel="noopener"><%= messages.nuxtjs %></a>
</div>
</div>
</body>

View File

@ -203,6 +203,7 @@ export default class Builder extends Tapable {
]
const templateVars = {
options: this.options,
messages: this.options.messages,
uniqBy: _.uniqBy,
isDev: this.options.dev,
debug: this.options.debug,

View File

@ -276,6 +276,12 @@ Options.defaults = {
chokidar: {}
},
messages: {
not_found: 'This page could not be found.'
error_404: 'This page could not be found (404)',
server_error: 'Server error',
nuxtjs: 'Nuxt.js',
back_to_home: 'Back to the home page',
server_error_details: 'An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.',
client_error: 'Error',
client_error_details: 'An error occurred while rendering the page. Check developer tools console for details.'
}
}