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

refactor(fscomponents): FLAGSHIP-94 Add Translations To Component #1054

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 11 additions & 9 deletions packages/fscomponents/src/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as t from 'tcomb-form-native';
import { emailRegex } from '../lib/email';
import { Form, FormLabelPosition } from './Form';
import { Button } from './Button';
import FSI18n, { translationKeys } from '@brandingbrand/fsi18n';
const componentTranslationKeys = translationKeys.flagship.loginForm;

export interface LoginFormProps {
/**
Expand Down Expand Up @@ -66,9 +68,9 @@ const EmailType = t.refinement(t.String, (str: string) => {

EmailType.getValidationErrorMessage = (s: string) => {
if (!s) {
return 'Email is required';
return FSI18n.string(componentTranslationKeys.emailReq);
} else {
return `${s} is not an valid email`;
return s + FSI18n.string(componentTranslationKeys.emailNotValid);
}
};

Expand All @@ -91,23 +93,23 @@ export class LoginForm extends Component<LoginFormProps, LoginFormState> {

this.fieldsOptions = {
emailAddress: {
label: 'Email',
placeholder: 'Email',
label: FSI18n.string(componentTranslationKeys.email),
placeholder: FSI18n.string(componentTranslationKeys.email),
returnKeyType: 'next',
autoCorrect: false,
autoCapitalize: 'none',
keyboardType: 'email-address',
onSubmitEditing: () => this.focusField('password'),
error: 'Please enter a valid email'
error: FSI18n.string(componentTranslationKeys.emailError)
},
password: {
label: 'Password',
placeholder: 'Password',
label: FSI18n.string(componentTranslationKeys.password),
placeholder: FSI18n.string(componentTranslationKeys.password),
returnKeyType: 'next',
autoCorrect: false,
autoCapitalize: 'none',
secureTextEntry: true,
error: 'Please enter your password'
error: FSI18n.string(componentTranslationKeys.passwordError)
},
...props.fieldsOptions
};
Expand Down Expand Up @@ -158,7 +160,7 @@ export class LoginForm extends Component<LoginFormProps, LoginFormState> {
onChange={this.handleChange}
/>
<Button
title={submitText || 'Submit'}
title={submitText || FSI18n.string(componentTranslationKeys.submit)}
onPress={this.handleSubmit}
style={submitButtonStyle}
/>
Expand Down
4 changes: 4 additions & 0 deletions packages/fsi18n/src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ export const keys: FSTranslationKeys = {
},
loginForm: {
email: 'Email',
emailReq: 'Email is required',
emailNotValid: ' is not an valid email',
emailError: 'Please enter a valid email',
password: 'Password',
passwordError: 'Please enter your password',
submit: 'Submit'
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/fsi18n/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ export interface ShareButtonTranslations<KeyType> {
}
export interface LoginFormTranslations<KeyType> {
email: KeyType;
emailReq: KeyType;
emailNotValid: KeyType;
emailError: KeyType;
password: KeyType;
passwordError: KeyType;
submit: KeyType;
}