[![Crowdin](https://badges.crowdin.net/appwrite-exceptions-translations/localized.svg)](https://crowdin.com/project/appwrite-exceptions-translations)
[![version](https://img.shields.io/npm/v/@itishermann/appwrite-exceptions-translator.svg?style=flat-square)](https://npmjs.org/@itishermann/appwrite-exceptions-translator)
[![min size](https://img.shields.io/bundlephobia/min/@itishermann/appwrite-exceptions-translator?style=flat-square)](https://bundlephobia.com/result?p=@itishermann/appwrite-exceptions-translator)
[![mingzip size](https://img.shields.io/bundlephobia/minzip/@itishermann/appwrite-exceptions-translator)](https://bundlephobia.com/result?p=@itishermann/appwrite-exceptions-translator)
[![license](https://img.shields.io/npm/l/@itishermann/appwrite-exceptions-translator?color=%23007a1f&style=flat-square)](https://gitlab.com/itishermann/appwrite-exceptions-translator/blob/main/LICENSE)
![GitLab Stars](https://img.shields.io/gitlab/stars/itishermann%2Fappwrite-exceptions-translator)
![GitLab Contributors](https://img.shields.io/gitlab/contributors/itishermann%2Fappwrite-exceptions-translator)
[![code of conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://gitlab.com/itishermann/appwrite-exceptions-translator/blob/main/CODE_OF_CONDUCT.md)
[![pipeline status](https://gitlab.com/itishermann/appwrite-exceptions-translator/badges/main/pipeline.svg?ignore_skipped=true)](https://gitlab.com/itishermann/appwrite-exceptions-translator/-/pipelines)
[![coverage](https://gitlab.com/itishermann/appwrite-exceptions-translator/badges/main/coverage.svg)](https://gitlab.com/itishermann/appwrite-exceptions-translator/-/graphs/main/charts)
[![Known Vulnerabilities](https://snyk.io/test/npm/@itishermann/appwrite-exceptions-translator/badge.svg)](https://snyk.io/test/npm/@itishermann/appwrite-exceptions-translator)
# Appwrite Exception Translator

A lightweight translator for Appwrite SDK exceptions that provides user-friendly error messages in multiple languages.

## Installation

```bash
# Using npm
npm install @itishermann/appwrite-exceptions-translator

# Using bun
bun add @itishermann/appwrite-exceptions-translator

# Using yarn
yarn add @itishermann/appwrite-exceptions-translator
```

## Basic Usage

```typescript
import { createDefaultTranslator } from '@itishermann/appwrite-exceptions-translator';

try {
  // Some Appwrite SDK operation
} catch (error) {
  const translator = createDefaultTranslator();
  const userFriendlyMessage = translator.translate(error);
  console.log(userFriendlyMessage);
}
```

## Advanced Usage

```typescript
import { AppwriteExceptionTranslator, LocalTranslationProvider } from '@itishermann/appwrite-exceptions-translator';

// Create custom instance with dependency injection
const provider = new LocalTranslationProvider();
const translator = new AppwriteExceptionTranslator(provider);

// Set preferred language (defaults to 'en')
translator.setLanguage('fr');

// Translate different types of errors
try {
  // Appwrite SDK operation
} catch (error) {
  const message = translator.translate(error);
  console.log(message);
}

// Checking available languages
const languages = translator.getAvailableLanguages();
console.log(`Available languages: ${languages.join(', ')}`);
```

## Error Handling Details

The translator prioritizes error lookup in the following order:
1. By `error.type` (Appwrite error types like 'argument_invalid')
2. By `error.code` (HTTP status codes like 400, 404)
3. Falls back to the original error message if no translation is found

## Contributing Translations

This package uses Crowdin for translation management. To contribute translations:

1. Join the [Crowdin project](https://crowdin.com/project/appwrite-exceptions-translations) with this [invitation](https://crowdin.com/project/appwrite-exceptions-translations/invite?h=72bdd078c73ad069185f88e7950c1e1e2386482)
2. Select a language and start translating
3. Submit your translations
