Skip to content

Commit 577fb55

Browse files
committed
Use field.baseKey and field.index to generate localizedFieldID
1 parent 6fbf70e commit 577fb55

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

data/core.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ en:
25432543
source:
25442544
label: Source
25452545
source_multiple:
2546-
label: Source {localizerOption}
2546+
label: Source {index}
25472547
presets:
25482548
type/chronology:
25492549
name: Chronology

modules/presets/field.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export function presetField(fieldID, field, allFields) {
1010
allFields = allFields || {};
1111
let _this = Object.assign({}, field); // shallow copy
1212

13-
// This handles fieldIDs that contain ':', like 'source:1'
14-
let localizerFieldID = fieldID.includes(':') ? fieldID.split(':')[0] + '_multiple': fieldID;
15-
// This is what comes after the ':' in the fieldID.
16-
let localizerOption = fieldID.includes(':') ? fieldID.split(':')[1]: 0;
13+
// This handles fields that are composed of a base key and an index, like 'source:1'
14+
let localizerFieldID = fieldID;
15+
if (field.baseKey && field.index){
16+
localizerFieldID = field.baseKey + '_multiple';
17+
}
1718

1819
_this.id = fieldID;
1920

@@ -48,10 +49,10 @@ export function presetField(fieldID, field, allFields) {
4849
return _this;
4950
};
5051

51-
_this.title = () => _this.overrideLabel || _this.resolveReference('label').t('label', { 'default': fieldID, 'localizerOption': localizerOption });
52+
_this.title = () => _this.overrideLabel || _this.resolveReference('label').t('label', { 'default': fieldID, 'index': field.index });
5253
_this.label = () => _this.overrideLabel ?
5354
selection => selection.text(_this.overrideLabel) :
54-
_this.resolveReference('label').t.append('label', { 'default': fieldID, 'localizerOption': localizerOption });
55+
_this.resolveReference('label').t.append('label', { 'default': fieldID, 'index': field.index });
5556

5657
_this.placeholder = () => _this.resolveReference('placeholder').t('placeholder', { 'default': '' });
5758

modules/presets/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ function addHistoricalFields(fields) {
6262
fields.source.keys = ['source', 'source:url', 'source:name', 'source:date'];
6363

6464
for (let i = 1; i < 4; i++){
65-
let id = 'source' + (i > 0 ? ':' + i.toString() : '');
65+
let id = 'source:' + i.toString();
6666
let previousId = 'source' + ((i-1) > 0 ? ':' + (i-1).toString() : '');
6767
fields[id] = {
6868
...fields.source,
6969
key: id,
7070
keys: [id, id + ':url', id + ':name', id + ':date'],
71+
// baseKey and index will be used to create a localized label for this field
72+
baseKey: 'source',
73+
index: i,
7174
prerequisiteTag: {
7275
keys: [
7376
previousId,

0 commit comments

Comments
 (0)