globalfy-glossary
v1.14.0
Published
Globalfy messages glossary
Downloads
642
Readme
Here’s an updated version of your README that includes the basic usage examples for getException
and getExceptionTranslation
:
Globalfy Glossary
globalfy-glossary
is a TypeScript library that provides translations and exception handling for the Globalfy platform.
Installation
To install the library, you can use npm or yarn:
npm install globalfy-glossary
# or
yarn add globalfy-glossary
Usage
Here’s how you can use the Messages
, Exceptions
, getException
, and getExceptionTranslation
from the library:
import {
Exceptions,
ExceptionCode,
getException,
getExceptionTranslation,
Language,
Messages,
} from 'globalfy-glossary';
// Using Messages and Exceptions
console.log(Messages.someMessage);
console.log(Exceptions.someException);
// Using getException
const exception = getException('API_ERROR');
console.log(exception);
// Using getExceptionTranslation
const translation = getExceptionTranslation('API_ERROR', Language.Pt);
console.log(translation);
// Using the ExceptionCode
getException(ExceptionCode.ActiveCompanyNotFound);
// or
getExceptionTranslation(ExceptionCode.ActiveCompanyNotFound, Language.Pt);
Replace someMessage
and someException
with the keys of the messages and exceptions you want to use. Replace 'API_ERROR'
with the exception key you're working with and 'pt'
with your preferred language (en
, pt
, or es
).
Types
The library provides the following types:
- Translations: An object with
en
,pt
, andes
properties, each of which is a string. - Message: An object with
code
,status
, andtranslations
properties.code
andstatus
are numbers, andtranslations
is aTranslations
object. - Exception: Similar to
Message
, but used for exceptions.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
ISC
This update includes the examples for both getException
and getExceptionTranslation
functions, showing how to handle exceptions and retrieve translations.