Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Add bgBG locale #983

Merged
merged 6 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/src/pages/components/data-grid/localization/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ In the following example, the labels of the density selector are customized.

{{"demo": "pages/components/data-grid/localization/CustomLocaleTextGrid.js", "bg": "inline"}}

## 🚧 Locale text
## Locale text

The default locale of Material-UI is English (United States).
You can find all the locales supported in [the source](https://github.com/mui-org/material-ui-x/blob/HEAD/packages/grid/_modules_/grid/locales) in the GitHub repository.

### Supported locales

| Locale | BCP 47 language tag | Import name |
| :-------- | :------------------ | :---------- |
| Bulgarian | bg-BG | `bgBG` |

> ⚠️ This feature isn't implemented yet. It's coming.
>
> 👍 Upvote [issue #777](https://github.com/mui-org/material-ui-x/issues/777) if you want to see it land faster.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { capitalize } from '@material-ui/core';
import FormControl from '@material-ui/core/FormControl';
import IconButton from '@material-ui/core/IconButton';
import InputLabel from '@material-ui/core/InputLabel';
Expand All @@ -11,6 +12,7 @@ import { FilterItem, LinkOperator } from '../../../models/filterItem';
import { FilterOperator } from '../../../models/filterOperator';
import { ApiContext } from '../../api-context';
import { CloseIcon } from '../../icons/index';
import { TranslationKeys } from '../../../models/api/localeTextApi';

export interface FilterFormProps {
item: FilterItem;
Expand Down Expand Up @@ -200,7 +202,9 @@ export function FilterForm(props: FilterFormProps) {
>
{currentColumn?.filterOperators?.map((operator) => (
<option key={operator.value} value={operator.value}>
{operator.label}
{apiRef!.current.getLocaleText(
`filterOperator${capitalize(operator.value)}` as TranslationKeys,
)}
</option>
))}
</Select>
Expand Down
11 changes: 11 additions & 0 deletions packages/grid/_modules_/grid/constants/localeTextConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export const DEFAULT_LOCALE_TEXT: LocaleText = {
filterPanelOperatorOr: 'Or',
filterPanelColumns: 'Columns',

// Filter operators text
filterOperatorContains: 'contains',
filterOperatorEquals: 'equals',
filterOperatorStartsWith: 'starts with',
filterOperatorEndsWith: 'ends with',
filterOperatorIs: 'is',
filterOperatorNot: 'is not',
filterOperatorOnOrAfter: 'is on or after',
filterOperatorBefore: 'is before',
filterOperatorOnOrBefore: 'is on or before',

// Column menu text
columnMenuLabel: 'Menu',
columnMenuShowColumns: 'Show columns',
Expand Down
1 change: 1 addition & 0 deletions packages/grid/_modules_/grid/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './components';
export * from './constants';
export * from './hooks';
export * from './locales';
export * from './models';
export * from './utils';
export * from './GridComponentProps';
Expand Down
78 changes: 78 additions & 0 deletions packages/grid/_modules_/grid/locales/bgBG.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { getLocalization, Localization } from '../utils';

export const bgBG: Localization = getLocalization({
// Root
rootGridLabel: 'мрежа',
noRowsLabel: 'Няма редове',
errorOverlayDefaultLabel: 'Възникна грешка.',

// Density selector toolbar button text
toolbarDensity: 'Гъстота',
toolbarDensityLabel: 'Гъстота',
toolbarDensityCompact: 'Компактна',
toolbarDensityStandard: 'Стандартна',
toolbarDensityComfortable: 'Комфортна',

// Columns selector toolbar button text
toolbarColumns: 'Колони',
toolbarColumnsLabel: 'Покажи селектора на колони',

// Filters toolbar button text
toolbarFilters: 'Филтри',
toolbarFiltersLabel: 'Покажи Филтрите',
toolbarFiltersTooltipHide: 'Скрий Филтрите',
toolbarFiltersTooltipShow: 'Покажи Филтрите',
toolbarFiltersTooltipActive: (count) => `${count} активни филтри`,

// Columns panel text
columnsPanelTextFieldLabel: 'Намери колона',
columnsPanelTextFieldPlaceholder: 'Заглавие на колона',
columnsPanelDragIconLabel: 'Пренареди на колона',
columnsPanelShowAllButton: 'Покажи Всички',
columnsPanelHideAllButton: 'Скрий Всички',

// Filter panel text
filterPanelAddFilter: 'Добави Филтър',
filterPanelDeleteIconLabel: 'Изтрий',
filterPanelOperators: 'Оператори',
filterPanelOperatorAnd: 'И',
filterPanelOperatorOr: 'Или',
filterPanelColumns: 'Колони',

// Filter operators text
filterOperatorContains: 'съдържа',
filterOperatorEquals: 'равно',
filterOperatorStartsWith: 'започва с',
filterOperatorEndsWith: 'завършва с',
filterOperatorIs: 'е',
filterOperatorNot: 'не е',
filterOperatorOnOrAfter: 'е на или след',
filterOperatorBefore: 'е преди',
filterOperatorOnOrBefore: 'е на или преди',

// Column menu text
columnMenuLabel: 'Меню',
columnMenuShowColumns: 'Покажи колоните',
columnMenuFilter: 'Филтри',
columnMenuHideColumn: 'Скрий',
columnMenuUnsort: 'Отмени сортирането',
columnMenuSortAsc: 'Сортирай по възходящ ред',
columnMenuSortDesc: 'Сортирай по низходящ ред',

// Column header text
columnHeaderFiltersTooltipActive: (count) => `${count} активни филтри`,
columnHeaderFiltersLabel: 'Покажи Филтрите',
columnHeaderSortIconLabel: 'Сортирай',

// Rows selected footer text
footerRowSelected: (count) =>
count !== 1
? `${count.toLocaleString()} избрани редове`
: `${count.toLocaleString()} избран ред`,

// Total rows footer text
footerTotalRows: 'Общо Rедове:',

// Pagination footer text
footerPaginationRowsPerPage: 'Редове на страница:',
});
1 change: 1 addition & 0 deletions packages/grid/_modules_/grid/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './bgBG';
11 changes: 11 additions & 0 deletions packages/grid/_modules_/grid/models/api/localeTextApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ export interface LocaleText {
filterPanelOperatorOr: React.ReactNode;
filterPanelColumns: React.ReactNode;

// Filter operators text
filterOperatorContains: string;
filterOperatorEquals: string;
filterOperatorStartsWith: string;
filterOperatorEndsWith: string;
filterOperatorIs: string;
filterOperatorNot: string;
filterOperatorOnOrAfter: string;
filterOperatorBefore: string;
filterOperatorOnOrBefore: string;

// Column menu text
columnMenuLabel: string;
columnMenuShowColumns: React.ReactNode;
Expand Down
6 changes: 0 additions & 6 deletions packages/grid/_modules_/grid/models/colDef/dateOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ColDef } from './colDef';

export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showTime) => [
{
label: 'is',
value: 'is',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -28,7 +27,6 @@ export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showT
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
label: 'is not',
value: 'not',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -51,7 +49,6 @@ export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showT
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
label: 'is after',
value: 'after',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -74,7 +71,6 @@ export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showT
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
label: 'is on or after',
value: 'onOrAfter',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -97,7 +93,6 @@ export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showT
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
label: 'is before',
value: 'before',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -120,7 +115,6 @@ export const getDateOperators: (showTime?: boolean) => FilterOperator[] = (showT
InputComponentProps: { type: showTime ? 'datetime-local' : 'date' },
},
{
label: 'is on or before',
value: 'onOrBefore',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand Down
4 changes: 0 additions & 4 deletions packages/grid/_modules_/grid/models/colDef/stringOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ColDef } from './colDef';

export const getStringOperators: () => FilterOperator[] = () => [
{
label: 'contains',
value: 'contains',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -21,7 +20,6 @@ export const getStringOperators: () => FilterOperator[] = () => [
InputComponent: FilterInputValue,
},
{
label: 'equals',
value: 'equals',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -39,7 +37,6 @@ export const getStringOperators: () => FilterOperator[] = () => [
InputComponent: FilterInputValue,
},
{
label: 'starts with',
value: 'startsWith',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand All @@ -55,7 +52,6 @@ export const getStringOperators: () => FilterOperator[] = () => [
InputComponent: FilterInputValue,
},
{
label: 'ends with',
value: 'endsWith',
getApplyFilterFn: (filterItem: FilterItem, column: ColDef) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Expand Down
1 change: 0 additions & 1 deletion packages/grid/_modules_/grid/models/filterOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FilterItem } from './filterItem';
import { CellParams } from './params/cellParams';

export interface FilterOperator {
label: string;
value: string;
getApplyFilterFn: (
filterItem: FilterItem,
Expand Down
41 changes: 41 additions & 0 deletions packages/grid/_modules_/grid/utils/getLocalization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { LocaleText } from '../models/api/localeTextApi';
import { GridOptions } from '../models/gridOptions';
import { isMuiV5 } from './utils';

export interface LocalizationV4 {
props: {
MuiDataGrid: Pick<GridOptions, 'localeText'>;
};
}

export interface LocalizationV5 {
components: {
MuiDataGrid: {
defaultProps: Pick<GridOptions, 'localeText'>;
};
};
}

export type Localization = LocalizationV4 | LocalizationV5;

export const getLocalization = (translations: LocaleText): Localization => {
if (isMuiV5()) {
return {
components: {
MuiDataGrid: {
defaultProps: {
localeText: translations,
},
},
},
};
}

return {
props: {
MuiDataGrid: {
localeText: translations,
},
},
};
};
1 change: 1 addition & 0 deletions packages/grid/_modules_/grid/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './classnames';
export * from './keyboardUtils';
export * from './mergeUtils';
export * from './paramsUtils';
export * from './getLocalization';