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

feature/add_i18n_functionality #7

Merged
merged 3 commits into from
Apr 24, 2018

Conversation

horstenwillem
Copy link
Collaborator

Add translations

@coveralls
Copy link

coveralls commented Apr 23, 2018

Pull Request Test Coverage Report for Build 49

  • 17 of 17 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 24: 0.0%
Covered Lines: 65
Relevant Lines: 65

💛 - Coveralls

import * as i18n from 'i18n';

i18n.configure({
directory: __dirname + '/locales',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultLocale: 'en',

if (correctMessage === error.code) {
correctMessage = error.message;
}
parsedError = Object.assign({}, error, { message: correctMessage });
}

// Return object easy to use for serialisation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename file(s) to kebab-case

}
}

export interface Options {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TranslationOptions instead of Options

parsedError = error;
i18n.setLocale(language);

let correctMessage = i18n.__(error.code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use i18n property instead of coupling code to translation key


export function parseErrors(error: any) {
export function parseErrors(error: any, language: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make language optional (check if default from i18n gets used)

parsedError = error;
i18n.setLocale(language);

let correctMessage = i18n.__(error.code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translatedMessage instead of correctMessage?

@horstenwillem horstenwillem force-pushed the feature/add_i18n_functionality branch 2 times, most recently from b493484 to 9394fb8 Compare April 23, 2018 14:41
@@ -63,10 +73,29 @@ describe('errorParser', () => {

describe('Predefined Api errors', () => {
it('Should succesfully parse default ApiError', () => {
const errorTranslation = 'English translation';
i18nMock.mockImplementation(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be one line due to arrow fn
i18nMock.mockImplementation(() => errorTranslation)

it('Should succesfully parse default ApiError for Dutch translation', () => {
const errorTranslation = 'Nederlands vertaling';
i18nMock.mockImplementation(() => {
return errorTranslation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

package.json Outdated
@@ -21,14 +21,17 @@
"dependencies": {
"express-validation": "~1.0.2",
"http-status": "~1.0.1",
"i18n": "0.8.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~0.8.3

package.json Outdated
"joi": "~13.1.2",
"uuid": "~3.2.1"
},
"devDependencies": {
"@types/http-status": "~0.2.30",
"@types/i18n": "0.8.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~0.8.3

@knor-el-snor knor-el-snor merged commit c5f98a2 into master Apr 24, 2018
@knor-el-snor knor-el-snor deleted the feature/add_i18n_functionality branch April 24, 2018 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants