Skip to content

Commit 21ffbb7

Browse files
authored
feat: added i18n translation to postMessage fields (#244)
1 parent 260e3c0 commit 21ffbb7

6 files changed

+30
-13
lines changed

docs/classes/_pages_decimal_setting_d_.decimalsetting.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ ___
153153
**postMessage**(`value`: string): *[DecimalSetting](_pages_decimal_setting_d_.decimalsetting.md)*
154154

155155
A string to be shown after the text input field. One common use for this field is to
156-
specify a unit of measure.
156+
specify a unit of measure. Omitting the value and calling `postMessage()` will set the
157+
value to the default i18n string, allowing translations to be defines in the locale
158+
file in the usual way.
157159

158160
**Parameters:**
159161

docs/classes/_pages_number_setting_d_.numbersetting.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ ___
161161
**postMessage**(`value`: string): *[NumberSetting](_pages_number_setting_d_.numbersetting.md)*
162162

163163
A string to be shown after the text input field. One common use for this field is to
164-
specify a unit of measure.
164+
specify a unit of measure. Omitting the value and calling `postMessage()` will set the
165+
value to the default i18n string, allowing translations to be defines in the locale
166+
file in the usual way.
165167

166168
**Parameters:**
167169

@@ -195,7 +197,7 @@ ___
195197

196198
**step**(`value`: number): *[NumberSetting](_pages_number_setting_d_.numbersetting.md)*
197199

198-
The step between values values. If the style is not set to slider then setting a step will
200+
The step between values. If the style is not set to slider then setting a step will
199201
cause up and down arrows to appear next to the input box that increment or decrement the value
200202
by the value of the step.
201203

lib/pages/decimal-setting.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ export class DecimalSetting extends SectionSetting<DecimalSetting> {
3232

3333
/**
3434
* A string to be shown after the text input field. One common use for this field is to
35-
* specify a unit of measure.
35+
* specify a unit of measure. Omitting the value and calling `postMessage()` will set the
36+
* value to the default i18n string, allowing translations to be defines in the locale
37+
* file in the usual way.
3638
* @param value Max length 10 characters
3739
*/
38-
postMessage(value: string): DecimalSetting
40+
postMessage(value?: string): DecimalSetting
3941
}

lib/pages/decimal-setting.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = class DecimalSetting extends SectionSetting {
77
super(section, id)
88
this._type = 'DECIMAL'
99
this._description = 'Tap to set'
10-
this._postMessage = this.i18nKey('postMessage')
1110
}
1211

1312
max(value) {
@@ -26,7 +25,12 @@ module.exports = class DecimalSetting extends SectionSetting {
2625
}
2726

2827
postMessage(value) {
29-
this._postMessage = value
28+
if (value === undefined) {
29+
this._postMessage = this.i18nKey('postMessage')
30+
} else {
31+
this._postMessage = value
32+
}
33+
3034
return this
3135
}
3236

@@ -45,7 +49,7 @@ module.exports = class DecimalSetting extends SectionSetting {
4549
}
4650

4751
if (this._postMessage) {
48-
result.postMessage = this._postMessage
52+
result.postMessage = this.translate(this._postMessage)
4953
}
5054

5155
return result

lib/pages/number-setting.d.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export class NumberSetting extends SectionSetting<NumberSetting> {
4242

4343
/**
4444
* A string to be shown after the text input field. One common use for this field is to
45-
* specify a unit of measure.
45+
* specify a unit of measure. Omitting the value and calling `postMessage()` will set the
46+
* value to the default i18n string, allowing translations to be defines in the locale
47+
* file in the usual way.
4648
* @param value Max length 10 characters
4749
*/
48-
postMessage(value: string): NumberSetting
50+
postMessage(value?: string): NumberSetting
4951

5052
/**
51-
* The step between values values. If the style is not set to slider then setting a step will
53+
* The step between values. If the style is not set to slider then setting a step will
5254
* cause up and down arrows to appear next to the input box that increment or decrement the value
5355
* by the value of the step.
5456
*/

lib/pages/number-setting.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ module.exports = class NumberSetting extends SectionSetting {
7373
* @returns {NumberSetting} Number Setting instance
7474
*/
7575
postMessage(value) {
76-
this._postMessage = value
76+
if (value === undefined) {
77+
this._postMessage = this.i18nKey('postMessage')
78+
} else {
79+
this._postMessage = value
80+
}
81+
7782
return this
7883
}
7984

@@ -100,7 +105,7 @@ module.exports = class NumberSetting extends SectionSetting {
100105
}
101106

102107
if (this._postMessage) {
103-
result.postMessage = this._postMessage
108+
result.postMessage = this.translate(this._postMessage)
104109
}
105110

106111
return result

0 commit comments

Comments
 (0)