claude-says-no/README.md

201 lines
5.1 KiB
Markdown
Raw Normal View History

2025-06-06 18:55:54 +02:00
# No as a Service (NaaS) - Multilingual Edition
2025-06-06 18:50:32 +02:00
2025-06-06 18:55:54 +02:00
A Sinatra-based web service that provides creative "no" responses in multiple languages, with full support for all Nordic languages and automatic language detection.
2025-06-06 18:50:32 +02:00
## Features
2025-06-06 18:55:54 +02:00
- **Multilingual Support**: 8 languages including all Nordic languages
- **Automatic Language Detection**: Via Accept-Language headers and URL parameters
2025-06-06 18:50:32 +02:00
- **Dual Format Support**: Serves both HTML (for browsers) and JSON (for APIs)
2025-06-06 18:55:54 +02:00
- **Random Responses**: Returns a random "no" response from curated lists per language
- **Modern Styling**: Beautiful glassmorphism design with language indicators
2025-06-06 18:50:32 +02:00
- **Health Checks**: Built-in health check endpoint for monitoring
- **Containerized**: Ready for deployment with Podman/Docker
2025-06-06 18:55:54 +02:00
## Supported Languages
- 🇬🇧 **English** (`en`) - Default
- 🇳🇴 **Norwegian** (`no`) - Norsk
- 🇸🇪 **Swedish** (`sv`) - Svenska
- 🇩🇰 **Danish** (`da`) - Dansk
- 🇮🇸 **Icelandic** (`is`) - Íslenska
- 🇫🇮 **Finnish** (`fi`) - Suomi
- 🇫🇴 **Faroese** (`fo`) - Føroyskt
- 🏔️ **Northern Sami** (`smi`) - Sámegiella
2025-06-06 18:50:32 +02:00
## API Endpoints
- `GET /` - Returns a random "no" (HTML by default, JSON with Accept header)
2025-06-06 18:55:54 +02:00
- `GET /api/no` - Explicit JSON endpoint with language detection
- `GET /api/no/:lang` - Get response in specific language (e.g., `/api/no/no`)
- `GET /languages` - List all available languages
2025-06-06 18:50:32 +02:00
- `GET /health` - Health check endpoint
- `GET /*` - Catch-all that returns "no" for any other path
2025-06-06 18:55:54 +02:00
## Language Detection
The service automatically detects language preference through:
2025-06-06 18:50:32 +02:00
2025-06-06 18:55:54 +02:00
1. **URL Parameter**: `?lang=no` (highest priority)
2. **Accept-Language Header**: Browser language preferences
3. **Default Fallback**: English (`en`)
Language family mapping is supported:
- `nb`, `nn``no` (Norwegian variants)
- `sv-*``sv` (Swedish variants)
- `da-*``da` (Danish variants)
- etc.
2025-06-06 18:50:32 +02:00
## Usage Examples
### HTML (Browser)
2025-06-06 18:55:54 +02:00
```bash
# Default language (auto-detected)
2025-06-06 18:50:32 +02:00
curl http://localhost:4567/
2025-06-06 18:55:54 +02:00
# Specific language via parameter
curl http://localhost:4567/?lang=no
# Language via Accept-Language header
curl -H "Accept-Language: sv-SE,sv;q=0.9" http://localhost:4567/
2025-06-06 18:50:32 +02:00
```
2025-06-06 18:55:54 +02:00
### JSON API
2025-06-06 18:50:32 +02:00
```bash
2025-06-06 18:55:54 +02:00
# Auto-detected language
2025-06-06 18:50:32 +02:00
curl -H "Accept: application/json" http://localhost:4567/
2025-06-06 18:55:54 +02:00
# Specific language endpoint
curl http://localhost:4567/api/no/is
# With language parameter
curl http://localhost:4567/api/no?lang=fi
# List available languages
curl http://localhost:4567/languages
2025-06-06 18:50:32 +02:00
```
2025-06-06 18:55:54 +02:00
### Sample JSON Responses
**Basic Response:**
2025-06-06 18:50:32 +02:00
```json
{
2025-06-06 18:55:54 +02:00
"answer": "Absolutt ikke",
"language": "no",
"language_name": "Norsk (Norwegian)",
2025-06-06 18:50:32 +02:00
"timestamp": "2025-06-06T12:00:00Z",
"service": "No as a Service",
2025-06-06 18:55:54 +02:00
"version": "2.0.0"
}
```
**Languages List:**
```json
{
"languages": [
{"code": "en", "name": "English"},
{"code": "no", "name": "Norsk (Norwegian)"},
{"code": "sv", "name": "Svenska (Swedish)"}
],
"default": "en",
"timestamp": "2025-06-06T12:00:00Z"
2025-06-06 18:50:32 +02:00
}
```
## Local Development
### Prerequisites
- Ruby 3.2+
- Bundler
### Setup
```bash
# Install dependencies
bundle install
# Run the application
ruby app.rb
# Or use rerun for auto-reload during development
bundle exec rerun ruby app.rb
```
The application will be available at `http://localhost:4567`
## Container Deployment
### Build with Podman
```bash
podman build -t naas .
```
### Run with Podman
```bash
# Basic run
podman run -p 4567:4567 naas
# Run in background with restart policy
podman run -d --name naas-service -p 4567:4567 --restart=always naas
# Run with custom port
podman run -p 8080:4567 -e PORT=4567 naas
```
### Docker Commands
The same commands work with Docker by replacing `podman` with `docker`.
## Environment Variables
- `PORT` - Port to bind to (default: 4567)
## Health Monitoring
The service includes a health check endpoint at `/health` that returns:
```json
{
"status": "healthy",
2025-06-06 18:55:54 +02:00
"languages_loaded": 8,
2025-06-06 18:50:32 +02:00
"timestamp": "2025-06-06T12:00:00Z"
}
```
## File Structure
```
.
├── app.rb # Main Sinatra application
2025-06-06 18:55:54 +02:00
├── responses.yml # Multilingual response data
2025-06-06 18:50:32 +02:00
├── Gemfile # Ruby dependencies
├── Containerfile # Container build instructions
└── README.md # This file
```
2025-06-06 18:55:54 +02:00
## Adding New Languages
To add a new language, edit `responses.yml`:
```yaml
xx: # Language code
name: "Language Name"
responses:
- "Response 1"
- "Response 2"
# ... more responses
```
Then optionally add language family mapping in `app.rb` if needed.
## Nordic Language Features
Each Nordic language includes culturally appropriate expressions:
- **Norwegian**: "Når kua flyger" (When cows fly)
- **Swedish**: "När grisar flyger" (When pigs fly)
- **Danish**: "Når svin flyver" (When pigs fly)
- **Icelandic**: "Þegar svín fljúga" (When pigs fly)
- **Finnish**: "Kun lehmät lentää" (When cows fly)
- **Faroese**: "Tá svín fljúgva" (When pigs fly)
- **Northern Sami**: "Go vuonji liddjo" (When reindeer fly)
2025-06-06 18:50:32 +02:00
## License
2025-06-06 18:55:54 +02:00
This project is released under the MIT License. Perfect for all your multilingual negative response needs!. Feel free to use it for your negative response needs!