### Install Supabase Error Translator JS Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md Instructions for installing the Supabase error translator library using npm or yarn, the two most common package managers for JavaScript projects. ```bash npm install supabase-error-translator-js ``` ```bash yarn add supabase-error-translator-js ``` -------------------------------- ### Set Up Supabase Error Translator Development Environment Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/CONTRIBUTING.md This snippet provides the necessary `git` and `pnpm` commands to clone the Supabase Error Translator repository and install its dependencies, preparing your local development environment. ```bash git clone https://github.com/srothgan/supabase-error-translator-js.git cd supabase-error-translator-js pnpm install ``` -------------------------------- ### Commit Changes with Conventional Commits Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/CONTRIBUTING.md Examples demonstrating how to write clear and descriptive commit messages following the Conventional Commits specification, categorizing changes such as features, fixes, documentation updates, and tests. ```bash feat: add Italian error translations fix: handle null error codes docs: update README with new language support test: add tests for edge cases ``` -------------------------------- ### Run Development Tasks: Test, Build, Lint, Format, Type Check Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/CONTRIBUTING.md This section provides `pnpm` commands to execute essential development tasks, including installing dependencies, running tests, building the project, linting with auto-fix, auto-formatting code, and performing type checks to maintain code quality. ```bash pnpm install pnpm test pnpm build pnpm run lint -- --fix pnpm run format pnpm run type-check ``` -------------------------------- ### Get Supported Translation Languages Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md Provides a list of all language codes supported by the error translation system. ```APIDOC getSupportedLanguages(): SupportedLanguage[] Returns: Array of supported language codes ``` -------------------------------- ### Get Current and Supported Languages in Supabase Error Translator JS Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md Illustrates how to retrieve the currently active language set in the translator and obtain a comprehensive list of all languages supported by the Supabase error translator library. ```typescript import { getCurrentLanguage, getSupportedLanguages } from 'supabase-error-translator-js'; // Get the currently active language const currentLang = getCurrentLanguage(); console.log(currentLang); // e.g., 'en', 'de', etc. // Get all supported languages const supportedLangs = getSupportedLanguages(); console.log(supportedLangs); // ['en', 'de', 'es', 'fr', 'jp', 'kr', 'pl', 'pt', 'cn'] ``` -------------------------------- ### Get Current Translation Language Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md Retrieves the currently active language used for error message translations. ```APIDOC getCurrentLanguage(): SupportedLanguage Returns: The current language code as a string ``` -------------------------------- ### Push Git Branch to GitHub Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/CONTRIBUTING.md After committing your changes, use this `git` command to push your local working branch to the remote GitHub repository, making it available for pull request submission. ```bash git push origin feature/your-feature-name ``` -------------------------------- ### Create a Git Working Branch for Supabase Error Translator Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/CONTRIBUTING.md Use these `git` commands to create a new feature or fix branch, ensuring your changes are isolated and follow standard development workflow practices before making modifications. ```bash git checkout -b feature/your-feature-name # or git checkout -b fix/issue-you-are-fixing ``` -------------------------------- ### Translate Supabase Error Codes with Basic Usage in TypeScript Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md Demonstrates how to import the translation functions, set a default language for all subsequent translations, and then translate a specific Supabase error code using the configured language. ```typescript import { translateErrorCode, setLanguage } from 'supabase-error-translator-js'; // Set the language (defaults to English if not set) setLanguage('es'); // Set to Spanish // Translate an error code const message = translateErrorCode('email_not_confirmed', 'auth'); console.log(message); // Outputs the Spanish translation for this error code ``` -------------------------------- ### Handle Supabase Auth Errors with Translation in React Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md This React functional component (`SignupForm`) demonstrates how to implement user signup with Supabase authentication, specifically focusing on translating error codes. It uses `supabase-error-translator-js` to convert raw Supabase error codes into localized, human-readable messages, enhancing the user experience. The component manages form state, displays translated errors, and handles loading states. ```jsx import React, { useState, useEffect } from 'react'; import { setLanguage, translateErrorCode } from 'supabase-error-translator-js'; import { supabase } from './supabaseClient'; import { useRouter }nfrom 'next/navigation'; function SignupForm() { const router = useRouter(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); useEffect(() => { // Set language setLanguage('de'); }, []); const handleSignup = async (e) => { e.preventDefault(); setError(null); setIsLoading(true); try { const { error } = await supabase.auth.signUp({ email, password, }); if (error) { // Translate the error code from Supabase const translatedError = translateErrorCode(error.code, 'auth'); setError(translatedError); } else { // Navigate to login page in Next.js 15 router.push('/login'); // Clear form setEmail(''); setPassword(''); } } catch (err) { setError(translateErrorCode('unknown_error', 'auth')); } finally { setIsLoading(false); } }; return (
); } ``` -------------------------------- ### Handle and Translate Supabase Database Errors in React Product Form Source: https://github.com/srothgan/supabase-error-translator-js/blob/main/README.md This React component (`ProductForm`) illustrates how to capture and translate Supabase database errors during data insertion. It uses `supabase-error-translator-js` to convert raw database error codes into localized, human-readable messages. The component initializes the translator's language to German, validates form inputs, attempts a Supabase insert operation, and displays either a success message or a translated error. It requires `react`, `supabase-error-translator-js`, and a configured Supabase client. ```jsx import React, { useState, useEffect } from 'react'; import { setLanguage, translateErrorCode } from 'supabase-error-translator-js'; import { supabase } from './supabaseClient'; function ProductForm() { const [name, setName] = useState(''); const [price, setPrice] = useState(''); const [description, setDescription] = useState(''); const [error, setError] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); const [successMessage, setSuccessMessage] = useState(''); useEffect(() => { // Set language to German setLanguage('de'); }, []); const handleSubmit = async (e) => { e.preventDefault(); setError(null); setSuccessMessage(''); setIsSubmitting(true); // Basic validation if (!name || !price) { setError('Bitte fülle alle Pflichtfelder aus.'); setIsSubmitting(false); return; } try { // Attempt to insert a new product into the database const { data, error: dbError } = await supabase .from('products') .insert([ { name, price: parseFloat(price), description, created_at: new Date(), }, ]) .select(); if (dbError) { // Simply translate the database error code const translatedError = translateErrorCode(dbError.code, 'database'); setError(translatedError); } else { // Clear the form and show success message setName(''); setPrice(''); setDescription(''); setSuccessMessage('Produkt erfolgreich gespeichert!'); } } catch (err) { // Handle unexpected errors setError(translateErrorCode('unknown_error', 'database')); } finally { setIsSubmitting(false); } }; return (