Skip to content

Commit

Permalink
give up for now
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed May 16, 2020
1 parent f86c9ac commit 13a3692
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 37 deletions.
5 changes: 0 additions & 5 deletions docs/src/pages/guides/localization/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ To create your own translation, or to customise the English text, copy this file
Please do consider contributing new translations back to Material-UI by opening a pull request.
However, Material-UI aims to support the [100 most popular locales](https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers), we might not accept contributions for locales that are not frequently used, for instance `gl-ES` that has "only" 2.5 million native speakers.

## Format numbers

The numbers are formated with the [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) API.
You can customize the behavior by providing your own formater in `theme.localization.formatNumber`.

## RTL Support

Right-to-left languages such as Arabic, Persian or Hebrew are supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
} = props;

const theme = useTheme();
const formatNumber = theme.localization.formatNumber;

const normalizedIcons =
theme.direction === 'rtl'
Expand Down Expand Up @@ -258,7 +257,7 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
)}
{...other}
>
{type === 'page' && formatNumber(page)}
{type === 'page' && page}
{Icon ? <Icon className={classes.icon} /> : null}
</ButtonBase>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/material-ui/src/TablePagination/TablePagination.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { IconButtonProps } from '../IconButton';
import { SelectProps } from '../Select';

export interface LabelDisplayedRowsArgs {
from: number | string;
to: number | string;
count: number | string;
page: number | string;
from: number;
to: number;
count: number;
page: number;
}

export interface TablePaginationTypeMap<P, D extends React.ElementType> {
Expand Down
13 changes: 4 additions & 9 deletions packages/material-ui/src/TablePagination/TablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import { chainPropTypes } from '@material-ui/utils';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import useTheme from '../styles/useTheme';
import InputBase from '../InputBase';
import MenuItem from '../MenuItem';
import Select from '../Select';
Expand Down Expand Up @@ -96,8 +95,6 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
SelectProps = {},
...other
} = props;
const theme = useTheme();
const formatNumber = theme.localization.formatNumber;
let colSpan;

if (Component === TableCell || Component === 'td') {
Expand Down Expand Up @@ -140,12 +137,10 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
)}
<Typography color="inherit" variant="body2" className={classes.caption}>
{labelDisplayedRows({
from: formatNumber(count === 0 ? 0 : page * rowsPerPage + 1),
to: formatNumber(
count !== -1 ? Math.min(count, (page + 1) * rowsPerPage) : (page + 1) * rowsPerPage,
),
count: count === -1 ? -1 : formatNumber(count),
page: formatNumber(page),
from: count === 0 ? 0 : page * rowsPerPage + 1,
to: count !== -1 ? Math.min(count, (page + 1) * rowsPerPage) : (page + 1) * rowsPerPage,
count: count === -1 ? -1 : count,
page,
})}
</Typography>
<ActionsComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe('<TablePagination />', () => {
let labelDisplayedRowsCalled = false;
function labelDisplayedRows({ from, to, count, page }) {
labelDisplayedRowsCalled = true;
expect(from).to.equal('11');
expect(to).to.equal('20');
expect(count).to.equal('42');
expect(page).to.equal('1');
expect(from).to.equal(11);
expect(to).to.equal(20);
expect(count).to.equal(42);
expect(page).to.equal(1);
return `Page ${page}`;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/material-ui/src/styles/createMuiTheme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@ import { Transitions, TransitionsOptions } from './transitions';
import { ZIndex, ZIndexOptions } from './zIndex';
import { Overrides } from './overrides';
import { ComponentsProps } from './props';
import { string } from 'prop-types';

export type Direction = 'ltr' | 'rtl';

export interface Localization {
formatNumber: (number: number) => string;
}

export interface LocalizationOptions extends Partial<Localization> {}

export interface ThemeOptions {
localization?: LocalizationOptions;
shape?: ShapeOptions;
breakpoints?: BreakpointsOptions;
direction?: Direction;
Expand All @@ -37,7 +29,6 @@ export interface ThemeOptions {
}

export interface Theme {
localization: Localization;
shape: Shape;
breakpoints: Breakpoints;
direction: Direction;
Expand Down
4 changes: 0 additions & 4 deletions packages/material-ui/src/styles/createMuiTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ function createMuiTheme(options = {}, ...args) {
...other
} = options;

const localization = {
formatNumber: (number) => number.toLocalString(),
};
const palette = createPalette(paletteInput);
const breakpoints = createBreakpoints(breakpointsInput);
const spacing = createSpacing(spacingInput);

let muiTheme = deepmerge(
{
localization,
breakpoints,
direction: 'ltr',
mixins: createMixins(breakpoints, spacing, mixinsInput),
Expand Down

0 comments on commit 13a3692

Please sign in to comment.