Skip to content
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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { codes } from './codes';
import { CodeGetter } from './utils';
import { ELocal, IFullCode } from './types';

const errors = new CodeGetter(codes, ELocal.en_US);
const errors = new CodeGetter(codes, ELocal.en);

export { errors, ELocal, IFullCode };
8 changes: 5 additions & 3 deletions src/resources/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { II18n, IErrorRes, EHttpCode } from '../../types';
import * as fr_FR from './locales/fr_FR.json';
import * as en_US from './locales/en_US.json';

const i18n: II18n = { fr_FR, en_US };
// Locales
import * as fr from './locales/fr.json';
import * as en from './locales/en.json';

const i18n: II18n = { fr, en };

const authentication: IErrorRes = {
client: {
Expand Down
8 changes: 4 additions & 4 deletions src/resources/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { II18n, IErrorRes, EHttpCode } from '../../types';

// Locals
import * as fr_FR from './locales/fr_FR.json';
import * as en_US from './locales/en_US.json';
// Locales
import * as fr from './locales/fr.json';
import * as en from './locales/en.json';

const i18n: II18n = { fr_FR, en_US };
const i18n: II18n = { fr, en };

const general: IErrorRes = {
client: {},
Expand Down
8 changes: 5 additions & 3 deletions src/resources/signIn/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { II18n, IErrorRes, EHttpCode } from '../../types';
import * as fr_FR from './locales/fr_FR.json';
import * as en_US from './locales/en_US.json';

const i18n: II18n = { fr_FR, en_US };
// Locales
import * as fr from './locales/fr.json';
import * as en from './locales/en.json';

const i18n: II18n = { fr, en };

const authentication: IErrorRes = {
client: {
Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ enum EHttpCode {
}

enum ELocal {
'fr_FR' = 'fr_FR',
'en_US' = 'en_US',
'fr' = 'fr',
'en' = 'en',
}

interface ICode {
Expand Down
14 changes: 7 additions & 7 deletions tests/utils/codeGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe('/src/utils/codeGetter.ts', () => {
internal: {},
external: {},
i18n: {
en_US: {
en: {
client: {
testError2: 'testError2_en_US',
},
},
fr_FR: {
fr: {
client: {
testError2: 'testError2_fr_FR',
},
Expand All @@ -32,7 +32,7 @@ describe('/src/utils/codeGetter.ts', () => {
};

beforeEach(() => {
errorsMock = new CodeGetter(fakeCodes, ELocal.fr_FR);
errorsMock = new CodeGetter(fakeCodes, ELocal.fr);
});

it('should get one error by key', () => {
Expand All @@ -50,24 +50,24 @@ describe('/src/utils/codeGetter.ts', () => {
});

it('should get translation of error with given lang', () => {
const err = errorsMock.get('carts:client:testError2').i18n(ELocal.en_US);
const err = errorsMock.get('carts:client:testError2').i18n(ELocal.en);

expect(typeof err).toBe('string');
expect(err).toBe('testError2_en_US');
});

it('should throw an error', () => {
let err: Error|null = null;
let err: Error | null = null;

try {
errorsMock.get('carts:client:testError').i18n(ELocal.en_US);
errorsMock.get('carts:client:testError').i18n(ELocal.en);
} catch (e) {
err = e;
}

expect(err).toStrictEqual(
Error(
'Translation for key carts:client:testError in en_US was not found',
'Translation for key carts:client:testError in en was not found',
),
);
});
Expand Down