Skip to content

Commit

Permalink
Add locale for Modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
JustPilz committed Oct 15, 2018
1 parent 0b09e4e commit 9c05c75
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 6 deletions.
4 changes: 3 additions & 1 deletion components/locale-provider/en_US.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import DatePickerView from '../date-picker-view/locale/en_US';
import DatePicker from '../date-picker/locale/en_US';
import InputItem from '../input-item/locale/en_US';
import Modal from '../modal/locale/en_US';
import Pagination from '../pagination/locale/en_US';
import Picker from '../picker/locale/en_US';
import SearchBar from '../search-bar/locale/en_US';

export default {
locale: 'en',
Pagination,
DatePicker,
DatePickerView,
InputItem,
Modal,
Pagination,
Picker,
SearchBar,
};
1 change: 1 addition & 0 deletions components/locale-provider/locale-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface LocaleProviderProps {
DatePicker?: object;
DatePickerView?: object;
InputItem?: object;
Modal?: object;
};
children?: React.ReactElement<any>;
}
Expand Down
4 changes: 3 additions & 1 deletion components/locale-provider/ru_RU.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import DatePickerView from '../date-picker-view/locale/ru_RU';
import DatePicker from '../date-picker/locale/ru_RU';
import InputItem from '../input-item/locale/ru_RU';
import Modal from '../modal/locale/ru_RU';
import Pagination from '../pagination/locale/ru_RU';
import Picker from '../picker/locale/ru_RU';
import SearchBar from '../search-bar/locale/ru_RU';

export default {
locale: 'ru',
Pagination,
DatePicker,
DatePickerView,
InputItem,
Modal,
Pagination,
Picker,
SearchBar,
};
4 changes: 3 additions & 1 deletion components/locale-provider/sv_SE.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import DatePickerView from '../date-picker-view/locale/sv_Se';
import DatePicker from '../date-picker/locale/sv_Se';
import InputItem from '../input-item/locale/sv_Se';
import Modal from '../modal/locale/sv_Se';
import Pagination from '../pagination/locale/sv_Se';
import Picker from '../picker/locale/sv_Se';
import SearchBar from '../search-bar/locale/sv_Se';

export default {
locale: 'sv',
Pagination,
DatePicker,
DatePickerView,
InputItem,
Modal,
Pagination,
Picker,
SearchBar,
};
17 changes: 16 additions & 1 deletion components/modal/Modal.native.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';
import {
Dimensions,
Expand All @@ -15,6 +16,8 @@ import {
import RCModal from 'rmc-dialog/lib/Modal';
import { ModalPropsType } from './PropsType';
import modalStyle, { IModalStyle } from './style/index.native';
import { getComponentLocale } from '../_util/getLocale';
import zh_CN from './locale/zh_CN';

const maxHeight = StyleSheet.create({
maxHeight: {
Expand Down Expand Up @@ -50,6 +53,10 @@ class AntmModal extends React.Component<IModalNativeProps, any> {
static operation: any;
static prompt: any;

static contextTypes = {
antLocale: PropTypes.object,
};

root: View | null;

onFooterLayout = (e: LayoutChangeEvent) => {
Expand Down Expand Up @@ -84,6 +91,14 @@ class AntmModal extends React.Component<IModalNativeProps, any> {

const styles = this.props.styles!;

// tslint:disable-next-line:variable-name
const _locale = getComponentLocale(
this.props,
this.context,
'Modal',
() => zh_CN,
);

let btnGroupStyle = styles.buttonGroupV;
let horizontalFlex = {};
if (footer && footer.length === 2 && !operation) {
Expand Down Expand Up @@ -133,7 +148,7 @@ class AntmModal extends React.Component<IModalNativeProps, any> {
>
<View style={[buttonWrapStyle, noneBorder]}>
<Text style={[styles.buttonText, buttonStyle]}>
{button.text || `按钮${i}`}
{button.text || `${_locale.buttonText}${i}`}
</Text>
</View>
</TouchableHighlight>
Expand Down
20 changes: 18 additions & 2 deletions components/modal/PromptContainer.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* tslint:disable:jsx-no-multiline-js */
import PropTypes from 'prop-types';
import React from 'react';
import {
KeyboardAvoidingView,
Expand All @@ -11,6 +12,8 @@ import {
import Modal from './Modal.native';
import { CallbackOrActions } from './PropsType';
import promptStyle, { IPromptStyle } from './style/prompt.native';
import { getComponentLocale } from '../_util/getLocale';
import zh_CN from './locale/zh_CN';

export interface PropmptContainerProps {
title: React.ReactNode;
Expand All @@ -35,6 +38,10 @@ export default class PropmptContainer extends React.Component<
styles: promptStyles,
};

static contextTypes = {
antLocale: PropTypes.object,
};

constructor(props: PropmptContainerProps) {
super(props);
this.state = {
Expand Down Expand Up @@ -75,11 +82,20 @@ export default class PropmptContainer extends React.Component<
}
return func.apply(this, [text]);
};

// tslint:disable-next-line:variable-name
const _locale = getComponentLocale(
this.props,
this.context,
'Modal',
() => zh_CN,
);

let callbacks;
if (typeof actions === 'function') {
callbacks = [
{ text: '取消', style: 'cancel', onPress: () => {} },
{ text: '确定', onPress: () => getArgs(actions) },
{ text: _locale.cancelText, style: 'cancel', onPress: () => {} },
{ text: _locale.okText, onPress: () => getArgs(actions) },
];
} else {
callbacks = actions.map(item => {
Expand Down
1 change: 1 addition & 0 deletions components/modal/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ModalPropsType<T> {
transparent?: boolean;
popup?: boolean;
animated?: boolean;
locale?: object;
animationType?: any;
onAnimationEnd?: (visible: boolean) => void;
animateAppear?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions components/modal/locale/en_US.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
okText: 'Ok',
cancelText: 'Cancel',
buttonText: 'Button',
};
5 changes: 5 additions & 0 deletions components/modal/locale/ru_RU.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
okText: 'Ок',
cancelText: 'Отмена',
buttonText: 'Кнопка',
};
5 changes: 5 additions & 0 deletions components/modal/locale/sv_SE.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
okText: 'Ok',
cancelText: 'Avbryt',
buttonText: 'Knapp',
};
5 changes: 5 additions & 0 deletions components/modal/locale/zh_CN.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
okText: '确定',
cancelText: '取消',
buttonText: '按钮',
};

0 comments on commit 9c05c75

Please sign in to comment.