Skip to content

Commit

Permalink
Transfer to TS and Functional - Localization (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanblinov2k17 authored Nov 24, 2023
1 parent 65a4845 commit 64cf90a
Show file tree
Hide file tree
Showing 26 changed files with 839 additions and 230 deletions.
119 changes: 0 additions & 119 deletions JSDemos/Demos/Localization/UsingGlobalize/React/App.js

This file was deleted.

115 changes: 115 additions & 0 deletions JSDemos/Demos/Localization/UsingGlobalize/React/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-webpack-loader-syntax */
import React from 'react';
import DataGrid, { Column, Editing, FilterRow } from 'devextreme-react/data-grid';
import SelectBox, { SelectBoxTypes } from 'devextreme-react/select-box';

import 'devextreme/localization/globalize/number';
import 'devextreme/localization/globalize/date';
import 'devextreme/localization/globalize/currency';
import 'devextreme/localization/globalize/message';

import deMessages from 'devextreme/localization/messages/de.json';
import ruMessages from 'devextreme/localization/messages/ru.json';

import deCldrData from 'devextreme-cldr-data/de.json';
import ruCldrData from 'devextreme-cldr-data/ru.json';
import supplementalCldrData from 'devextreme-cldr-data/supplemental.json';

import Globalize from 'globalize';

import service from './data.ts';

const editPopupOptions = {
width: 700,
height: 345,
};
const amountEditorOptions = {
format: 'currency',
showClearButton: true,
};
const selectBoxInputAttr = { id: 'selectInput' };

Globalize.load(
deCldrData,
ruCldrData,
supplementalCldrData,
);
Globalize.loadMessages(deMessages);
Globalize.loadMessages(ruMessages);
Globalize.loadMessages(service.getDictionary());
Globalize.locale(sessionStorage.getItem('locale') || 'en');

const App = () => {
const [locale, setLocale] = React.useState(sessionStorage.getItem('locale') || 'en');
const locales = service.getLocales();
const payments = service.getPayments();

const changeLocale = (e: SelectBoxTypes.ValueChangedEvent) => {
setLocale(e.value);
sessionStorage.setItem('locale', e.value);
document.location.reload();
};

return (
<div>
<DataGrid
dataSource={payments}
keyExpr="PaymentId"
>
<Editing
mode="popup"
allowUpdating={true}
popup={editPopupOptions}
/>
<FilterRow
visible={true}
applyFilter="auto"
/>
<Column
dataField="PaymentId"
caption={Globalize.formatMessage('Number')}
allowEditing={false}
width={100}
/>
<Column
dataField="ContactName"
caption={Globalize.formatMessage('Contact')}
/>
<Column
dataField="CompanyName"
caption={Globalize.formatMessage('Company')}
/>
<Column
dataField="Amount"
caption={Globalize.formatMessage('Amount')}
dataType="number"
format="currency"
editorOptions={amountEditorOptions}
/>
<Column
dataField="PaymentDate"
caption={Globalize.formatMessage('PaymentDate')}
dataType="date"
/>
</DataGrid>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<label htmlFor="selectInput">Language</label>
&nbsp;
<SelectBox
items={locales}
valueExpr="Value"
displayExpr="Name"
value={locale}
onValueChanged={changeLocale}
inputAttr={selectBoxInputAttr}
/>
</div>
</div>
</div>
);
};

export default App;
2 changes: 1 addition & 1 deletion JSDemos/Demos/Localization/UsingGlobalize/React/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script src="../../../../../node_modules/systemjs/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import("./index.js");
System.import("./index.tsx");
</script>
</head>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App.js';
import App from './App.tsx';

ReactDOM.render(
<App />,
Expand Down
101 changes: 101 additions & 0 deletions JSDemos/Demos/Localization/UsingGlobalize/ReactJs/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-webpack-loader-syntax */
import React from 'react';
import DataGrid, { Column, Editing, FilterRow } from 'devextreme-react/data-grid';
import SelectBox from 'devextreme-react/select-box';
import 'devextreme/localization/globalize/number';
import 'devextreme/localization/globalize/date';
import 'devextreme/localization/globalize/currency';
import 'devextreme/localization/globalize/message';
import deMessages from 'devextreme/localization/messages/de.json';
import ruMessages from 'devextreme/localization/messages/ru.json';
import deCldrData from 'devextreme-cldr-data/de.json';
import ruCldrData from 'devextreme-cldr-data/ru.json';
import supplementalCldrData from 'devextreme-cldr-data/supplemental.json';
import Globalize from 'globalize';
import service from './data.js';

const editPopupOptions = {
width: 700,
height: 345,
};
const amountEditorOptions = {
format: 'currency',
showClearButton: true,
};
const selectBoxInputAttr = { id: 'selectInput' };
Globalize.load(deCldrData, ruCldrData, supplementalCldrData);
Globalize.loadMessages(deMessages);
Globalize.loadMessages(ruMessages);
Globalize.loadMessages(service.getDictionary());
Globalize.locale(sessionStorage.getItem('locale') || 'en');
const App = () => {
const [locale, setLocale] = React.useState(sessionStorage.getItem('locale') || 'en');
const locales = service.getLocales();
const payments = service.getPayments();
const changeLocale = (e) => {
setLocale(e.value);
sessionStorage.setItem('locale', e.value);
document.location.reload();
};
return (
<div>
<DataGrid
dataSource={payments}
keyExpr="PaymentId"
>
<Editing
mode="popup"
allowUpdating={true}
popup={editPopupOptions}
/>
<FilterRow
visible={true}
applyFilter="auto"
/>
<Column
dataField="PaymentId"
caption={Globalize.formatMessage('Number')}
allowEditing={false}
width={100}
/>
<Column
dataField="ContactName"
caption={Globalize.formatMessage('Contact')}
/>
<Column
dataField="CompanyName"
caption={Globalize.formatMessage('Company')}
/>
<Column
dataField="Amount"
caption={Globalize.formatMessage('Amount')}
dataType="number"
format="currency"
editorOptions={amountEditorOptions}
/>
<Column
dataField="PaymentDate"
caption={Globalize.formatMessage('PaymentDate')}
dataType="date"
/>
</DataGrid>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<label htmlFor="selectInput">Language</label>
&nbsp;
<SelectBox
items={locales}
valueExpr="Value"
displayExpr="Name"
value={locale}
onValueChanged={changeLocale}
inputAttr={selectBoxInputAttr}
/>
</div>
</div>
</div>
);
};
export default App;
Loading

0 comments on commit 64cf90a

Please sign in to comment.