|
| 1 | +# 🌐 Global Form Auto-Localization |
| 2 | + |
| 3 | +A demo showcasing **Lingo.dev's** structured object translation for automatic form localization. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Demo |
| 8 | + |
| 9 | +### [🎥 Watch the Demo Video](./public/demo-video.mp4) |
| 10 | +*(Click to play)* |
| 11 | + |
| 12 | +## What This App Does |
| 13 | + |
| 14 | +This demo demonstrates a real-world use case: **writing a form once in English and automatically localizing it into multiple languages** using Lingo.dev's SDK. |
| 15 | + |
| 16 | +Instead of translating plain text, this app translates **structured form content**: |
| 17 | + |
| 18 | +- Form title and description |
| 19 | +- Field labels |
| 20 | +- Input placeholders |
| 21 | +- Helper text |
| 22 | +- Validation error messages |
| 23 | +- Submit button text |
| 24 | +- **Supported Field Types**: Text, TextArea, Radio Groups, Checkboxes, Dropdowns (Select), Date inputs |
| 25 | +- **Option Translation**: Automatically translates options for choice-based fields |
| 26 | + |
| 27 | +## Why This Use Case Matters |
| 28 | + |
| 29 | +Forms are everywhere in web applications—contact forms, registration flows, checkout pages, surveys. Traditionally, localizing forms requires: |
| 30 | + |
| 31 | +1. Extracting all strings into translation files |
| 32 | +2. Managing keys for every field property |
| 33 | +3. Coordinating with translators for each language |
| 34 | +4. Keeping translations in sync as forms evolve |
| 35 | + |
| 36 | +With Lingo.dev, you can **skip the complexity**. Just pass your form structure to the API, and get back a perfectly translated form—instantly. |
| 37 | + |
| 38 | +## Lingo.dev Features Demonstrated |
| 39 | + |
| 40 | +| Feature | Description | |
| 41 | +|---------|-------------| |
| 42 | +| **`localizeObject()`** | Translates structured JavaScript objects while preserving structure | |
| 43 | +| **Multi-language Support** | Supports EN, ES, FR, DE, HI (easily extensible) | |
| 44 | +| **Structured Translation** | Translates nested form properties, not just flat strings | |
| 45 | +| **API Key Authentication** | Secure API key configuration via environment variables | |
| 46 | + |
| 47 | +## How to Run Locally |
| 48 | + |
| 49 | +### Prerequisites |
| 50 | + |
| 51 | +- Node.js 18+ installed |
| 52 | +- A [Lingo.dev](https://lingo.dev) API key |
| 53 | + |
| 54 | +### Step-by-Step Setup |
| 55 | + |
| 56 | +1. **Navigate to the demo directory:** |
| 57 | + |
| 58 | + ```bash |
| 59 | + cd community/lingo-global-forms |
| 60 | + ``` |
| 61 | + |
| 62 | +2. **Install dependencies:** |
| 63 | + |
| 64 | + ```bash |
| 65 | + npm install |
| 66 | + ``` |
| 67 | + |
| 68 | +3. **Configure your API key:** |
| 69 | + |
| 70 | + Create a `.env` file in the project root: |
| 71 | + |
| 72 | + ```bash |
| 73 | + cp .env.example .env |
| 74 | + ``` |
| 75 | + |
| 76 | + Then edit `.env` and add your Lingo.dev API key: |
| 77 | + |
| 78 | + ``` |
| 79 | + VITE_LINGO_API_KEY=your_actual_api_key_here |
| 80 | + ``` |
| 81 | + |
| 82 | + > 💡 Get your API key at [lingo.dev](https://lingo.dev) |
| 83 | +
|
| 84 | +4. **Start the development server:** |
| 85 | + |
| 86 | + ```bash |
| 87 | + npm run dev |
| 88 | + ``` |
| 89 | + |
| 90 | +5. **Open your browser:** |
| 91 | + |
| 92 | + Navigate to [http://localhost:3000](http://localhost:3000) |
| 93 | + |
| 94 | +## Usage |
| 95 | + |
| 96 | +1. **Edit the form** in the left panel—change labels, placeholders, error messages |
| 97 | +2. **Select a language** from the dropdown in the preview panel |
| 98 | +3. **Watch the form translate** automatically |
| 99 | +4. **Submit the form** with empty required fields to see translated validation errors |
| 100 | + |
| 101 | +## Project Structure |
| 102 | + |
| 103 | +``` |
| 104 | +lingo-global-forms/ |
| 105 | +├── src/ |
| 106 | +│ ├── components/ |
| 107 | +│ │ ├── FormBuilder.tsx # Form editing panel |
| 108 | +│ │ ├── FormPreview.tsx # Live preview with validation |
| 109 | +│ │ └── LanguageSelect.tsx # Language dropdown |
| 110 | +│ ├── lib/ |
| 111 | +│ │ ├── lingo.ts # Lingo.dev SDK initialization |
| 112 | +│ │ └── translateForm.ts # Translation logic with caching |
| 113 | +│ ├── types/ |
| 114 | +│ │ └── form.ts # TypeScript interfaces |
| 115 | +│ ├── App.tsx # Main application |
| 116 | +│ ├── main.tsx # Entry point |
| 117 | +│ └── index.css # Styles |
| 118 | +├── .env.example # Environment variable template |
| 119 | +├── package.json |
| 120 | +└── README.md |
| 121 | +``` |
| 122 | + |
| 123 | +## Environment Variables |
| 124 | + |
| 125 | +| Variable | Description | Required | |
| 126 | +|----------|-------------|----------| |
| 127 | +| `VITE_LINGO_API_KEY` | Your Lingo.dev API key | Yes | |
| 128 | + |
| 129 | +## License |
| 130 | + |
| 131 | +This project is part of the [Lingo.dev](https://github.com/lingodotdev/lingo.dev) community contributions and is licensed under the Apache-2.0 license. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +Built with ❤️ by the community for [Lingo.dev](https://lingo.dev) |
0 commit comments