diff --git a/src/index.ts b/src/index.ts index 40118ec..dc6fd69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }; diff --git a/src/resources/authentication/index.ts b/src/resources/authentication/index.ts index a36791a..3567717 100644 --- a/src/resources/authentication/index.ts +++ b/src/resources/authentication/index.ts @@ -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: { diff --git a/src/resources/authentication/locales/en_US.json b/src/resources/authentication/locales/en.json similarity index 100% rename from src/resources/authentication/locales/en_US.json rename to src/resources/authentication/locales/en.json diff --git a/src/resources/authentication/locales/fr_FR.json b/src/resources/authentication/locales/fr.json similarity index 100% rename from src/resources/authentication/locales/fr_FR.json rename to src/resources/authentication/locales/fr.json diff --git a/src/resources/general/index.ts b/src/resources/general/index.ts index 6f4dde2..e15dc70 100644 --- a/src/resources/general/index.ts +++ b/src/resources/general/index.ts @@ -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: {}, diff --git a/src/resources/general/locales/en_US.json b/src/resources/general/locales/en.json similarity index 100% rename from src/resources/general/locales/en_US.json rename to src/resources/general/locales/en.json diff --git a/src/resources/general/locales/fr_FR.json b/src/resources/general/locales/fr.json similarity index 100% rename from src/resources/general/locales/fr_FR.json rename to src/resources/general/locales/fr.json diff --git a/src/resources/signIn/index.ts b/src/resources/signIn/index.ts index 669d21a..a815be6 100644 --- a/src/resources/signIn/index.ts +++ b/src/resources/signIn/index.ts @@ -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: { diff --git a/src/resources/signIn/locales/en_US.json b/src/resources/signIn/locales/en.json similarity index 100% rename from src/resources/signIn/locales/en_US.json rename to src/resources/signIn/locales/en.json diff --git a/src/resources/signIn/locales/fr_FR.json b/src/resources/signIn/locales/fr.json similarity index 100% rename from src/resources/signIn/locales/fr_FR.json rename to src/resources/signIn/locales/fr.json diff --git a/src/types/index.ts b/src/types/index.ts index db1c522..7f3f5e9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -61,8 +61,8 @@ enum EHttpCode { } enum ELocal { - 'fr_FR' = 'fr_FR', - 'en_US' = 'en_US', + 'fr' = 'fr', + 'en' = 'en', } interface ICode { diff --git a/tests/utils/codeGetter.ts b/tests/utils/codeGetter.ts index 8b86cf5..0bdd9e6 100644 --- a/tests/utils/codeGetter.ts +++ b/tests/utils/codeGetter.ts @@ -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', }, @@ -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', () => { @@ -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', ), ); });