-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
import * as i18n from 'i18n'; | ||
|
||
i18n.configure({ | ||
directory: __dirname + '/locales', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultLocale: 'en',
src/lib/errorParser.ts
Outdated
if (correctMessage === error.code) { | ||
correctMessage = error.message; | ||
} | ||
parsedError = Object.assign({}, error, { message: correctMessage }); | ||
} | ||
|
||
// Return object easy to use for serialisation |
There was a problem hiding this comment.
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
src/lib/importTranslations.ts
Outdated
} | ||
} | ||
|
||
export interface Options { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TranslationOptions
instead of Options
src/lib/errorParser.ts
Outdated
parsedError = error; | ||
i18n.setLocale(language); | ||
|
||
let correctMessage = i18n.__(error.code); |
There was a problem hiding this comment.
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
src/lib/errorParser.ts
Outdated
|
||
export function parseErrors(error: any) { | ||
export function parseErrors(error: any, language: string) { |
There was a problem hiding this comment.
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)
src/lib/errorParser.ts
Outdated
parsedError = error; | ||
i18n.setLocale(language); | ||
|
||
let correctMessage = i18n.__(error.code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translatedMessage
instead of correctMessage
?
b493484
to
9394fb8
Compare
tests/errorParser.test.ts
Outdated
@@ -63,10 +73,29 @@ describe('errorParser', () => { | |||
|
|||
describe('Predefined Api errors', () => { | |||
it('Should succesfully parse default ApiError', () => { | |||
const errorTranslation = 'English translation'; | |||
i18nMock.mockImplementation(() => { |
There was a problem hiding this comment.
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)
tests/errorParser.test.ts
Outdated
it('Should succesfully parse default ApiError for Dutch translation', () => { | ||
const errorTranslation = 'Nederlands vertaling'; | ||
i18nMock.mockImplementation(() => { | ||
return errorTranslation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
9394fb8
to
5c6fb51
Compare
package.json
Outdated
@@ -21,14 +21,17 @@ | |||
"dependencies": { | |||
"express-validation": "~1.0.2", | |||
"http-status": "~1.0.1", | |||
"i18n": "0.8.3", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~0.8.3
Update package.json
5c6fb51
to
930cde4
Compare
Add translations