Skip to content

Commit 43fa844

Browse files
committed
FIO-9618: Move I18n shim to core
- Move relevant translation strings to core - Add form language to submission metadata
1 parent 7032471 commit 43fa844

File tree

8 files changed

+51
-204
lines changed

8 files changed

+51
-204
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"homepage": "https://github.com/formio/formio.js#readme",
8282
"dependencies": {
8383
"@formio/bootstrap": "v3.0.0-dev.121.085d187",
84-
"@formio/core": "v2.4.0-dev.232.d91b1e4",
84+
"@formio/core": "2.4.0-dev.235.b497e17",
8585
"@formio/text-mask-addons": "3.8.0-formio.4",
8686
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
8787
"abortcontroller-polyfill": "^1.7.5",

src/Element.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import EventEmitter from './EventEmitter';
22
import { Formio } from './Formio';
33
import * as FormioUtils from './utils/utils';
4-
import { I18n } from './utils/i18n';
4+
import { I18n } from '@formio/core';
55
import _ from 'lodash';
66
import moment from 'moment';
77
import maskInput from '@formio/vanilla-text-mask';
8+
import enTranslation from './translations/en';
89

910
/**
1011
* The root component for all elements within the Form.io renderer.
@@ -41,7 +42,7 @@ export default class Element {
4142
if (this.options?.language) {
4243
this.options.i18n.language = this.options.language;
4344
}
44-
this.options.i18next = this.i18next = this.options.i18next || I18n.init(this.options.i18n);
45+
this.options.i18next = this.i18next = this.options.i18next || I18n.init({ en: enTranslation, ...this.options.i18n });
4546

4647
/**
4748
* An instance of the EventEmitter class to handle the emitting and registration of events.
@@ -435,11 +436,12 @@ export default class Element {
435436
/**
436437
* Translate a text using the i18n system.
437438
* @param {string|Array<string>} text - The i18n identifier.
439+
* @param {any} data - contextual data object containing data, component, row, etc.
438440
* @param {...any} args - The arguments to pass to the i18n translation.
439441
* @returns {string} - The translated text.
440442
*/
441-
t(text, ...args) {
442-
return this.i18next ? this.i18next.t(text, ...args): text;
443+
t(text, data, ...args) {
444+
return this.i18next ? this.i18next.t(text, data, ...args): text;
443445
}
444446

445447
/**

src/Webform.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import moment from 'moment';
33
import { compareVersions } from 'compare-versions';
44
import EventEmitter from './EventEmitter';
5-
import i18nDefaults from './i18n';
5+
import enTranslation from './translations/en';
66
import { Formio } from './Formio';
77
import Components from './components/Components';
88
import NestedDataComponent from './components/_classes/nesteddata/NestedDataComponent';
@@ -114,7 +114,7 @@ function getOptions(options) {
114114
* @property {number} [saveDraftThrottle] - The throttle for the save draft feature.
115115
* @property {boolean} [readOnly] - Set this form to readOnly.
116116
* @property {boolean} [noAlerts] - Disable the alerts dialog.
117-
* @property {{[key: string]: string}} [i18n] - The translation file for this rendering.
117+
* @property {{[key: string]: string}} [enTranslation] - The translation file for this rendering.
118118
* @property {string} [template] - Custom logic for creation of elements.
119119
* @property {boolean} [noDefaults] - Exclude default values from the settings.
120120
* @property {any} [fileService] - The file service for this form.
@@ -395,7 +395,7 @@ export default class Webform extends NestedDataComponent {
395395
*/
396396
addLanguage(code, lang, active = false) {
397397
if (this.i18next) {
398-
var translations = _.assign(fastCloneDeep(i18nDefaults.resources.en.translation), lang);
398+
var translations = _.assign(fastCloneDeep(enTranslation), lang);
399399
this.i18next.addResourceBundle(code, 'translation', translations, true, true);
400400
if (active) {
401401
this.language = code;
@@ -1516,6 +1516,7 @@ export default class Webform extends NestedDataComponent {
15161516
userAgent: navigator.userAgent,
15171517
pathName: window.location.pathname,
15181518
onLine: navigator.onLine,
1519+
language: this.language,
15191520
});
15201521
}
15211522

src/formio.form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Evaluator } from './utils/Evaluator';
1212
import Licenses from './licenses';
1313
import EventEmitter from './EventEmitter';
1414
import Webform from './Webform';
15-
import { I18n } from './utils/i18n';
15+
import { I18n } from '@formio/core';
1616

1717
Formio.loadModules = (path = `${Formio.getApiUrl() }/externalModules.js`, name = 'externalModules') => {
1818
Formio.requireLibrary(name, name, path, true)

src/i18n.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/translations/en.js

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,28 @@
11

22
import bootstrap from '@formio/bootstrap';
3+
import { coreEnTranslation } from '@formio/core';
4+
import _ from 'lodash';
35

46
export default {
57
...(bootstrap?.translations?.en || {}),
8+
// these keys contain a '-' to strip whitespace in core
9+
// which is not handled correctly in the renderer, so we redefine them
10+
..._.omit(coreEnTranslation, ['maxDate', 'minDate']),
611
unsavedRowsError: 'Please save all rows before proceeding.',
712
invalidRowsError: 'Please correct invalid rows before proceeding.',
813
invalidRowError: 'Invalid row. Please correct it or delete.',
914
invalidOption: '{{field}} is an invalid value.',
1015
invalidDay: '{{field}} is not a valid day.',
16+
alertMessageWithLabel: '{{label}}: {{message}}',
17+
alertMessage: '{{message}}',
1118
complete: 'Submission Complete',
1219
error: 'Please fix the following errors before submitting.',
1320
errorListHotkey: 'Press Ctrl + Alt + X to go back to the error list.',
1421
errorsListNavigationMessage: 'Click to navigate to the field with following error.',
1522
submitError: 'Please check the form and correct all errors before submitting.',
16-
required: '{{field}} is required',
17-
unique: '{{field}} must be unique',
18-
array: '{{field}} must be an array',
19-
array_nonempty: '{{field}} must be a non-empty array', // eslint-disable-line camelcase
20-
nonarray: '{{field}} must not be an array',
21-
select: '{{field}} contains an invalid selection',
22-
pattern: '{{field}} does not match the pattern {{pattern}}',
23-
minLength: '{{field}} must have at least {{length}} characters.',
24-
maxLength: '{{field}} must have no more than {{length}} characters.',
25-
minWords: '{{field}} must have at least {{length}} words.',
26-
maxWords: '{{field}} must have no more than {{length}} words.',
27-
min: '{{field}} cannot be less than {{min}}.',
28-
max: '{{field}} cannot be greater than {{max}}.',
2923
maxDate: '{{field}} should not contain date after {{maxDate}}',
3024
minDate: '{{field}} should not contain date before {{minDate}}',
31-
maxYear: '{{field}} should not contain year greater than {{maxYear}}',
32-
minYear: '{{field}} should not contain year less than {{minYear}}',
33-
minSelectedCount: 'You must select at least {{minCount}} items',
34-
maxSelectedCount: 'You may only select up to {{maxCount}} items',
35-
invalid_email: '{{field}} must be a valid email.', // eslint-disable-line camelcase
36-
invalid_url: '{{field}} must be a valid url.', // eslint-disable-line camelcase
37-
invalid_regex: '{{field}} does not match the pattern {{regex}}.', // eslint-disable-line camelcase
38-
invalid_date: '{{field}} is not a valid date.', // eslint-disable-line camelcase
39-
invalid_day: '{{field}} is not a valid day.', // eslint-disable-line camelcase
40-
invalidValueProperty: 'Invalid Value Property',
41-
mask: '{{field}} does not match the mask.',
42-
valueIsNotAvailable: '{{ field }} is an invalid value.',
4325
stripe: '{{stripe}}',
44-
month: 'Month',
45-
day: 'Day',
46-
year: 'Year',
47-
january: 'January',
48-
february: 'February',
49-
march: 'March',
50-
april: 'April',
51-
may: 'May',
52-
june: 'June',
53-
july: 'July',
54-
august: 'August',
55-
september: 'September',
56-
october: 'October',
57-
november: 'November',
58-
december: 'December',
5926
next: 'Next',
6027
previous: 'Previous',
6128
cancel: 'Cancel',
@@ -76,10 +43,7 @@ export default {
7643
apiKey: 'API Key is not unique: {{key}}',
7744
typeRemaining: '{{ remaining }} {{ type }} remaining.',
7845
typeCount: '{{ count }} {{ type }}',
79-
requiredDayField: '{{ field }} is required',
8046
requiredDayEmpty: '{{ field }} is required',
81-
requiredMonthField: '{{ field }} is required',
82-
requiredYearField: '{{ field }} is required',
8347
formNotReady: 'Form not ready. Use form.ready promise',
8448
noFormElement: 'No DOM element for form.',
8549
notUniqueKey: 'API Key is not unique',
@@ -139,8 +103,6 @@ export default {
139103
words: 'words',
140104
characters: 'characters',
141105
addAnother: 'Add Another',
142-
yes: 'Yes',
143-
no: 'No',
144106
wantToClearData: 'Do you want to clear data?',
145107
yesDelete:'Yes, delete it',
146108
waitFileProcessing: 'Processing file. Please wait...',
@@ -157,8 +119,6 @@ export default {
157119
maxSelectItems: 'You may only select up to {{maxCount}} items',
158120
minSelectItems: 'You must select at least {{minCount}} items',
159121
clickToSign: 'Click to Sign',
160-
surveyQuestion: 'Question',
161-
surveyQuestionValue: 'Value',
162122
success: 'Success',
163123
noResultsFound: 'No results found',
164124
noChoices: 'No choices to choose from',

src/utils/i18n.js

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)