More translations

This commit is contained in:
garrettmills
2020-06-01 19:43:29 -05:00
parent c956628c53
commit 0bec18825e
8 changed files with 129 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ const template = `
</h3>
<div class="row" v-if="!is_ready">
<div class="col-12 text-center pad-top mb-5">
<h4>Loading...</h4>
<h4>{{ t['common.loading'] }}...</h4>
</div>
</div>
<form v-on:submit.prevent="do_nothing" v-if="is_ready">
@@ -106,7 +106,7 @@ const template = `
:id="uuid+field.field+'-confirm'"
v-model="data[field.field+'-confirm']"
:required="Array.isArray(field.required) ? field.required.includes(mode) : field.required"
:placeholder="'Confirm ' + field.name"
:placeholder="t['common.confirm'] + ' ' + field.name"
:readonly="mode === 'view' || (Array.isArray(field.readonly) ? field.readonly.includes(mode) : field.readonly)"
>
<small class="form-text" style="color: darkred;" v-if="field.error">{{ field.error }}</small>
@@ -121,7 +121,7 @@ const template = `
type="button"
v-if="mode !== 'view'"
@click="save_click"
>Save</button>
>{{ t['common.save'] }}</button>
</div>
</span>
</div>
@@ -159,6 +159,7 @@ export default class FormComponent extends Component {
is_ready = false
mode = ''
id = ''
t = {}
reset() {
this.definition = {}
@@ -171,6 +172,18 @@ export default class FormComponent extends Component {
}
async vue_on_create(internal = false) {
this.t = await T(
'common.loading',
'common.confirm',
'common.save',
'common.not_permission',
'common.item_saved',
'common.unknown_error',
'common.field_required',
'common.confirmation_not_match',
'common.invalid_json'
)
if ( !internal ) {
this.mode = this.initial_mode
this.id = this.form_id
@@ -181,7 +194,7 @@ export default class FormComponent extends Component {
this.access_msg = true
} else {
this.can_access = false
this.access_msg = 'Sorry, you do not have permission to ' + this.mode + ' this resource.'
this.access_msg = this.t['common.not_permission'].replace('ACTION', this.mode)
return
}
@@ -283,12 +296,12 @@ export default class FormComponent extends Component {
}
this.error_message = ''
this.other_message = `The ${this.resource_class.item} was saved.`
this.other_message = this.t['common.item_saved'].replace('ITEM', this.resource_class.item)
} catch (e) {
console.error(e)
if ( e.response && e.response.data && e.response.data.message )
this.error_message = e.response.data.message
else this.error_message = 'An unknown error occurred while saving the form.'
else this.error_message = this.t['common.unknown_error']
}
}
@@ -305,13 +318,13 @@ export default class FormComponent extends Component {
let valid = true
for ( const field of this.definition.fields ) {
if ( (Array.isArray(field.required) ? field.required.includes(this.mode) : field.required) && (!(field.field in this.data) || !this.data[field.field]) ) {
field.error = 'This field is required.'
field.error = this.t['common.field_required']
valid = false
} else if ( field.type === 'password' && this.data[field.field] !== this.data[field.field + '-confirm'] ) {
field.error = field.name + ' confirmation does not match.'
field.error = field.name + ' ' + this.t['common.confirmation_not_match']
valid = false
} else if ( field.type === 'json' && !this.is_json(this.data[field.field]) ) {
field.error = field.name + ' must be valid JSON.'
field.error = field.name + ' ' + this.t['common.invalid_json']
valid = false
} else {
field.error = ''