mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
Add translation for boolean value in toggle columns for text cell (#364)
This commit is contained in:
parent
0b4371ee22
commit
4116949ea5
@ -9,6 +9,9 @@ import { cssIconBackground, icon } from 'app/client/ui2018/icons';
|
|||||||
import { gristLink } from 'app/client/ui2018/links';
|
import { gristLink } from 'app/client/ui2018/links';
|
||||||
import { NewAbstractWidget, Options } from 'app/client/widgets/NewAbstractWidget';
|
import { NewAbstractWidget, Options } from 'app/client/widgets/NewAbstractWidget';
|
||||||
import { Computed, dom, DomArg, DomContents, fromKo, Observable, styled } from 'grainjs';
|
import { Computed, dom, DomArg, DomContents, fromKo, Observable, styled } from 'grainjs';
|
||||||
|
import {makeT} from 'app/client/lib/localization';
|
||||||
|
|
||||||
|
const t = makeT('NTextBox');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TextBox - The most basic widget for displaying text information.
|
* TextBox - The most basic widget for displaying text information.
|
||||||
@ -62,7 +65,7 @@ export class NTextBox extends NewAbstractWidget {
|
|||||||
return dom('div.field_clip',
|
return dom('div.field_clip',
|
||||||
dom.style('text-align', this.alignment),
|
dom.style('text-align', this.alignment),
|
||||||
dom.cls('text_wrapping', this.wrapping),
|
dom.cls('text_wrapping', this.wrapping),
|
||||||
dom.domComputed((use) => use(row._isAddRow) ? null : makeLinks(use(this.valueFormatter).formatAny(use(value))))
|
dom.domComputed((use) => use(row._isAddRow) ? null : makeLinks(use(this.valueFormatter).formatAny(use(value), t)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,19 +79,28 @@ export class BaseFormatter {
|
|||||||
* Formats using this.format() if a value is of the right type for this formatter, or using
|
* Formats using this.format() if a value is of the right type for this formatter, or using
|
||||||
* AnyFormatter otherwise. This method the recommended API. There is no need to override it.
|
* AnyFormatter otherwise. This method the recommended API. There is no need to override it.
|
||||||
*/
|
*/
|
||||||
public formatAny(value: any): string {
|
public formatAny(value: any, translate?: (val: string) => string): string {
|
||||||
return this.isRightType(value) ? this.format(value) : formatUnknown(value);
|
return this.isRightType(value) ? this.format(value, translate) : formatUnknown(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a value that matches the type of this formatter. This should be overridden by derived
|
* Formats a value that matches the type of this formatter. This should be overridden by derived
|
||||||
* classes to handle values in formatter-specific ways.
|
* classes to handle values in formatter-specific ways.
|
||||||
*/
|
*/
|
||||||
protected format(value: any): string {
|
protected format(value: any, _translate?: (val: string) => string): string {
|
||||||
return String(value);
|
return String(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class BoolFormatter extends BaseFormatter {
|
||||||
|
public format(value: boolean | 0 | 1, translate?: (val: string) => string): string {
|
||||||
|
if (typeof value === 'boolean' && translate) {
|
||||||
|
return translate(String(value));
|
||||||
|
}
|
||||||
|
return super.format(value, translate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class AnyFormatter extends BaseFormatter {
|
class AnyFormatter extends BaseFormatter {
|
||||||
public format(value: any): string {
|
public format(value: any): string {
|
||||||
return formatUnknown(value);
|
return formatUnknown(value);
|
||||||
@ -265,7 +274,7 @@ class ReferenceListFormatter extends ReferenceFormatter {
|
|||||||
const formatters: { [name: string]: typeof BaseFormatter } = {
|
const formatters: { [name: string]: typeof BaseFormatter } = {
|
||||||
Numeric: NumericFormatter,
|
Numeric: NumericFormatter,
|
||||||
Int: IntFormatter,
|
Int: IntFormatter,
|
||||||
Bool: BaseFormatter,
|
Bool: BoolFormatter,
|
||||||
Date: DateFormatter,
|
Date: DateFormatter,
|
||||||
DateTime: DateTimeFormatter,
|
DateTime: DateTimeFormatter,
|
||||||
Ref: ReferenceFormatter,
|
Ref: ReferenceFormatter,
|
||||||
|
@ -354,6 +354,10 @@
|
|||||||
"GiveFeedback": "Give feedback",
|
"GiveFeedback": "Give feedback",
|
||||||
"NoNotifications": "No notifications"
|
"NoNotifications": "No notifications"
|
||||||
},
|
},
|
||||||
|
"NTextBox": {
|
||||||
|
"false": "false",
|
||||||
|
"true": "true"
|
||||||
|
},
|
||||||
"OnBoardingPopups": {
|
"OnBoardingPopups": {
|
||||||
"Finish": "Finish",
|
"Finish": "Finish",
|
||||||
"Next": "Next"
|
"Next": "Next"
|
||||||
|
@ -351,6 +351,10 @@
|
|||||||
"GiveFeedback": "Donnez votre avis",
|
"GiveFeedback": "Donnez votre avis",
|
||||||
"NoNotifications": "Aucune notification"
|
"NoNotifications": "Aucune notification"
|
||||||
},
|
},
|
||||||
|
"NTextBox": {
|
||||||
|
"false": "faux",
|
||||||
|
"true": "vrai"
|
||||||
|
},
|
||||||
"OnBoardingPopups": {
|
"OnBoardingPopups": {
|
||||||
"Finish": "Terminer",
|
"Finish": "Terminer",
|
||||||
"Next": "Suivant"
|
"Next": "Suivant"
|
||||||
|
Loading…
Reference in New Issue
Block a user