Skip to content

Commit 4aa1529

Browse files
Fix i18n Issues (#852)
* Fix: mi18n fallback values use mi18n api instead of accessing mi18n.current.key directly * v2.10.2 * update changelog, really need to setup semantic-release deployments for this project
1 parent f3be686 commit 4aa1529

9 files changed

Lines changed: 48 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
- v2.10.2 - Bugfix i18n lookups [#852](https://github.com/kevinchappell/formBuilder/pull/852)
34
- v2.10.1 - Bugfix typeUserAttrs [#851](https://github.com/kevinchappell/formBuilder/pull/851)
45
- v2.10.0 - Release 2.10.0 [#842](https://github.com/kevinchappell/formBuilder/pull/842)
56
## Fixed:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
formBuilder v2.10.1
1+
formBuilder v2.10.2
22
===========
33

44
[![Join the chat at https://gitter.im/kevinchappell/formBuilder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kevinchappell/formBuilder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

demo/assets/js/form-builder.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
112 Bytes
Binary file not shown.

demo/assets/js/form-render.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
75 Bytes
Binary file not shown.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "formBuilder",
3-
"version": "2.10.1",
3+
"version": "2.10.2",
44
"main": "dist/form-builder.min.js",
55
"files": [
66
"dist/form-builder.min.js",
@@ -120,11 +120,11 @@
120120
"eslint-config-prettier": "2.9.0",
121121
"eslint-loader": "2.0.0",
122122
"eslint-plugin-prettier": "2.6.0",
123-
"formbuilder-languages": "0.0.3",
123+
"formbuilder-languages": "^0.0.4",
124124
"html-webpack-harddisk-plugin": "0.2.0",
125125
"html-webpack-plugin": "3.2.0",
126126
"inquirer": "6.0.0",
127-
"mi18n": "0.4.6",
127+
"mi18n": "^0.4.6",
128128
"node-sass": "4.9.0",
129129
"opener": "1.4.3",
130130
"postcss-loader": "2.1.5",

src/js/form-builder.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const FormBuilder = function(opts, element) {
248248
d.stage.classList.remove('empty')
249249
} else if (!opts.prepend && !opts.append) {
250250
d.stage.classList.add('empty')
251-
d.stage.dataset.content = i18n.getStarted
251+
d.stage.dataset.content = mi18n.get('getStarted')
252252
}
253253

254254
if (nonEditableFields()) {
@@ -267,8 +267,8 @@ const FormBuilder = function(opts, element) {
267267
const fieldOptions = function(fieldData) {
268268
const { type, values, name } = fieldData
269269
let fieldValues
270-
const optionActions = [m('a', i18n.addOption, { className: 'add add-opt' })]
271-
const fieldOptions = [m('label', i18n.selectOptions, { className: 'false-label' })]
270+
const optionActions = [m('a', mi18n.get('addOption'), { className: 'add add-opt' })]
271+
const fieldOptions = [m('label', mi18n.get('selectOptions'), { className: 'false-label' })]
272272
const isMultiple = fieldData.multiple || type === 'checkbox-group'
273273
const optionDataTemplate = label => {
274274
const optionData = {
@@ -288,7 +288,7 @@ const FormBuilder = function(opts, element) {
288288
if (['checkbox-group', 'checkbox'].includes(type)) {
289289
defaultOptCount = [1]
290290
}
291-
fieldValues = defaultOptCount.map(index => optionDataTemplate(`${i18n.option} ${index}`))
291+
fieldValues = defaultOptCount.map(index => optionDataTemplate(`${mi18n.get('optionCount', index)}`))
292292

293293
const firstOption = fieldValues[0]
294294
if (firstOption.hasOwnProperty('selected') && type !== 'radio-group') {
@@ -374,10 +374,10 @@ const FormBuilder = function(opts, element) {
374374
const fieldAttrs = defaultFieldAttrs(type)
375375
const advFieldMap = {
376376
required: () => requiredField(values),
377-
toggle: () => boolAttribute('toggle', values, { first: i18n.toggle }),
377+
toggle: () => boolAttribute('toggle', values, { first: mi18n.get('toggle') }),
378378
inline: () => {
379379
const labels = {
380-
first: i18n.inline,
380+
first: mi18n.get('inline'),
381381
second: mi18n.get('inlineDesc', type.replace('-group', '')),
382382
}
383383

@@ -417,23 +417,23 @@ const FormBuilder = function(opts, element) {
417417
}
418418
availableRoles.push('</div>')
419419
const accessLabels = {
420-
first: i18n.roles,
421-
second: i18n.limitRole,
420+
first: mi18n.get('roles'),
421+
second: mi18n.get('limitRole'),
422422
content: availableRoles.join(''),
423423
}
424424

425425
return boolAttribute('access', values, accessLabels)
426426
},
427427
other: () =>
428428
boolAttribute('other', values, {
429-
first: i18n.enableOther,
430-
second: i18n.enableOtherMsg,
429+
first: mi18n.get('enableOther'),
430+
second: mi18n.get('enableOtherMsg'),
431431
}),
432432
options: () => fieldOptions(values),
433433
requireValidOption: () =>
434434
boolAttribute('requireValidOption', values, {
435435
first: ' ',
436-
second: i18n.requireValidOption,
436+
second: mi18n.get('requireValidOption'),
437437
}),
438438
multiple: () => {
439439
const typeLabels = {
@@ -442,12 +442,12 @@ const FormBuilder = function(opts, element) {
442442
second: 'set multiple attribute',
443443
},
444444
file: {
445-
first: i18n.multipleFiles,
446-
second: i18n.allowMultipleFiles,
445+
first: mi18n.get('multipleFiles'),
446+
second: mi18n.get('allowMultipleFiles'),
447447
},
448448
select: {
449449
first: ' ',
450-
second: i18n.selectionsMessage,
450+
second: mi18n.get('selectionsMessage'),
451451
},
452452
}
453453
return boolAttribute('multiple', values, typeLabels[type] || typeLabels.default)
@@ -530,7 +530,7 @@ const FormBuilder = function(opts, element) {
530530
for (const attribute in typeUserAttr) {
531531
if (typeUserAttr.hasOwnProperty(attribute)) {
532532
const attrValType = userAttrType(attribute, typeUserAttr[attribute])
533-
const orig = i18n[attribute]
533+
const orig = mi18n.get(attribute)
534534
const tUA = typeUserAttr[attribute]
535535
const origValue = tUA.value || ''
536536
tUA.value = values[attribute] || tUA.value || ''
@@ -701,8 +701,8 @@ const FormBuilder = function(opts, element) {
701701
const numberAttribute = (attribute, values) => {
702702
const { class: classname, className, ...attrs } = values
703703
const attrVal = attrs[attribute]
704-
const attrLabel = i18n[attribute] || attribute
705-
const placeholder = i18n[`placeholder.${attribute}`]
704+
const attrLabel = mi18n.get(attribute) || attribute
705+
const placeholder = mi18n.get(`placeholder.${attribute}`)
706706
const inputConfig = {
707707
type: 'number',
708708
value: attrVal,
@@ -748,7 +748,7 @@ const FormBuilder = function(opts, element) {
748748
name: attribute,
749749
className: `fld-${attribute} form-control`,
750750
}
751-
const labelText = i18n[attribute] || capitalize(attribute) || ''
751+
const labelText = mi18n.get(attribute) || capitalize(attribute) || ''
752752
const label = m('label', labelText, { for: selectAttrs.id })
753753
const select = m('select', selectOptions, selectAttrs)
754754
const inputWrap = m('div', select, { className: 'input-wrap' })
@@ -770,17 +770,17 @@ const FormBuilder = function(opts, element) {
770770
const textArea = ['paragraph']
771771

772772
let attrVal = values[attribute] || ''
773-
let attrLabel = i18n[attribute]
773+
let attrLabel = mi18n.get(attribute)
774774

775775
if (attribute === 'label') {
776776
if (textArea.includes(values.type)) {
777-
attrLabel = i18n.content
777+
attrLabel = mi18n.get('content')
778778
} else {
779779
attrVal = parsedHtml(attrVal)
780780
}
781781
}
782782

783-
const placeholder = i18n[`placeholders.${attribute}`] || ''
783+
const placeholder = mi18n.get(`placeholders.${attribute}`) || ''
784784
let attributefield = ''
785785
const noMakeAttr = []
786786

@@ -831,7 +831,7 @@ const FormBuilder = function(opts, element) {
831831
}
832832
if (!noMake.some(elem => elem === true)) {
833833
requireField = boolAttribute('required', fieldData, {
834-
first: i18n.required,
834+
first: mi18n.get('required'),
835835
})
836836
}
837837

@@ -841,26 +841,26 @@ const FormBuilder = function(opts, element) {
841841
// Append the new field to the editor
842842
const appendNewField = function(values, isNew = true) {
843843
const type = values.type || 'text'
844-
const label = values.label || (isNew ? i18n[type] || i18n.label : '')
844+
const label = values.label || (isNew ? i18n.get(type) || mi18n.get('label') : '')
845845
const disabledFieldButtons = opts.disabledFieldButtons[type] || values.disabledFieldButtons
846846
let fieldButtons = [
847847
m('a', null, {
848848
type: 'remove',
849849
id: 'del_' + data.lastID,
850850
className: 'del-button btn icon-cancel delete-confirm',
851-
title: i18n.removeMessage,
851+
title: mi18n.get('removeMessage'),
852852
}),
853853
m('a', null, {
854854
type: 'edit',
855855
id: data.lastID + '-edit',
856856
className: 'toggle-form btn icon-pencil',
857-
title: i18n.hide,
857+
title: mi18n.get('hide'),
858858
}),
859859
m('a', null, {
860860
type: 'copy',
861861
id: data.lastID + '-copy',
862862
className: 'copy-button btn icon-copy',
863-
title: i18n.copyButtonTooltip,
863+
title: mi18n.get('copyButtonTooltip'),
864864
}),
865865
]
866866

@@ -892,7 +892,7 @@ const FormBuilder = function(opts, element) {
892892
liContents.push(m('span', '?', descAttrs))
893893

894894
liContents.push(m('div', '', { className: 'prev-holder' }))
895-
const formElements = m('div', [advFields(values), m('a', i18n.close, { className: 'close-field' })], {
895+
const formElements = m('div', [advFields(values), m('a', mi18n.get('close'), { className: 'close-field' })], {
896896
className: 'form-elements',
897897
})
898898

@@ -966,7 +966,7 @@ const FormBuilder = function(opts, element) {
966966
name: name + '-option',
967967
}
968968

969-
attrs.placeholder = i18n[`placeholder.${prop}`] || ''
969+
attrs.placeholder = mi18n.get(`placeholder.${prop}`) || ''
970970

971971
if (prop === 'selected' && optionData.selected === true) {
972972
attrs.checked = optionData.selected
@@ -978,7 +978,7 @@ const FormBuilder = function(opts, element) {
978978

979979
const removeAttrs = {
980980
className: 'remove btn icon-cancel',
981-
title: i18n.removeMessage,
981+
title: mi18n.get('removeMessage'),
982982
}
983983
optionInputs.push(m('a', null, removeAttrs))
984984

@@ -1046,7 +1046,7 @@ const FormBuilder = function(opts, element) {
10461046
const options = field.querySelector('.sortable-options')
10471047
const optionsCount = options.childNodes.length
10481048
if (optionsCount <= 2 && !type.includes('checkbox')) {
1049-
opts.notify.error('Error: ' + i18n.minOptionMessage)
1049+
opts.notify.error('Error: ' + mi18n.get('minOptionMessage'))
10501050
} else {
10511051
$option.slideUp('250', () => {
10521052
$option.remove()
@@ -1191,7 +1191,7 @@ const FormBuilder = function(opts, element) {
11911191
if (e.target.value === '') {
11921192
$(e.target)
11931193
.addClass('field-error')
1194-
.attr('placeholder', i18n.cannotBeEmpty)
1194+
.attr('placeholder', mi18n.get('cannotBeEmpty'))
11951195
} else {
11961196
$(e.target).removeClass('field-error')
11971197
}
@@ -1239,8 +1239,8 @@ const FormBuilder = function(opts, element) {
12391239

12401240
// Check if user is sure they want to remove the field
12411241
if (opts.fieldRemoveWarn) {
1242-
const warnH3 = m('h3', i18n.warning)
1243-
const warnMessage = m('p', i18n.fieldRemoveWarning)
1242+
const warnH3 = m('h3', mi18n.get('warning'))
1243+
const warnMessage = m('p', mi18n.get('fieldRemoveWarning'))
12441244
h.confirm([warnH3, warnMessage], () => h.removeField(deleteID), coords)
12451245
$field.addClass('deleting')
12461246
} else {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,9 +2817,9 @@ form-data@~2.3.1, form-data@~2.3.2:
28172817
combined-stream "^1.0.6"
28182818
mime-types "^2.1.12"
28192819

2820-
formbuilder-languages@0.0.3:
2821-
version "0.0.3"
2822-
resolved "https://registry.yarnpkg.com/formbuilder-languages/-/formbuilder-languages-0.0.3.tgz#0ff606fc480cb1b8c2cdd514580206f09bfb70d3"
2820+
formbuilder-languages@^0.0.4:
2821+
version "0.0.4"
2822+
resolved "https://registry.yarnpkg.com/formbuilder-languages/-/formbuilder-languages-0.0.4.tgz#9a12e67211385716e6a0a6ce2521607df90f5e60"
28232823
dependencies:
28242824
mi18n "0.4.6"
28252825

@@ -4131,7 +4131,7 @@ methods@~1.1.2:
41314131
version "1.1.2"
41324132
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
41334133

4134-
mi18n@0.4.6:
4134+
mi18n@0.4.6, mi18n@^0.4.6:
41354135
version "0.4.6"
41364136
resolved "https://registry.yarnpkg.com/mi18n/-/mi18n-0.4.6.tgz#fc3b73dd9d1c821beff0b3d99f5e7af3d8577237"
41374137
dependencies:

0 commit comments

Comments
 (0)