improvement

This commit is contained in:
Ole-Morten Duesund 2025-06-06 18:55:54 +02:00
commit c0ccb8ca5e
6 changed files with 516 additions and 63 deletions

117
README.md
View file

@ -1,51 +1,104 @@
# No as a Service (NaaS)
# No as a Service (NaaS) - Multilingual Edition
A simple Sinatra-based web service that provides creative "no" responses in both HTML and JSON formats.
A Sinatra-based web service that provides creative "no" responses in multiple languages, with full support for all Nordic languages and automatic language detection.
## Features
- **Multilingual Support**: 8 languages including all Nordic languages
- **Automatic Language Detection**: Via Accept-Language headers and URL parameters
- **Dual Format Support**: Serves both HTML (for browsers) and JSON (for APIs)
- **Random Responses**: Returns a random "no" response from a curated list
- **Modern Styling**: Beautiful glassmorphism design for the HTML interface
- **Random Responses**: Returns a random "no" response from curated lists per language
- **Modern Styling**: Beautiful glassmorphism design with language indicators
- **Health Checks**: Built-in health check endpoint for monitoring
- **Containerized**: Ready for deployment with Podman/Docker
## 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
## API Endpoints
- `GET /` - Returns a random "no" (HTML by default, JSON with Accept header)
- `GET /api/no` - Explicit JSON endpoint with additional metadata
- `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
- `GET /health` - Health check endpoint
- `GET /*` - Catch-all that returns "no" for any other path
## Content Negotiation
## Language Detection
The root endpoint (`/`) supports content negotiation:
- Browser requests get HTML
- Requests with `Accept: application/json` get JSON
The service automatically detects language preference through:
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.
## Usage Examples
### HTML (Browser)
```
```bash
# Default language (auto-detected)
curl http://localhost:4567/
# 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/
```
### JSON
### JSON API
```bash
# Using Accept header
# Auto-detected language
curl -H "Accept: application/json" http://localhost:4567/
# Using explicit API endpoint
curl http://localhost:4567/api/no
# 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
```
### Sample JSON Response
### Sample JSON Responses
**Basic Response:**
```json
{
"answer": "Absolutely not",
"answer": "Absolutt ikke",
"language": "no",
"language_name": "Norsk (Norwegian)",
"timestamp": "2025-06-06T12:00:00Z",
"service": "No as a Service",
"version": "1.0.0"
"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"
}
```
@ -101,6 +154,7 @@ The service includes a health check endpoint at `/health` that returns:
```json
{
"status": "healthy",
"languages_loaded": 8,
"timestamp": "2025-06-06T12:00:00Z"
}
```
@ -110,11 +164,38 @@ The service includes a health check endpoint at `/health` that returns:
```
.
├── app.rb # Main Sinatra application
├── responses.yml # Multilingual response data
├── Gemfile # Ruby dependencies
├── Containerfile # Container build instructions
└── README.md # This file
```
## 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)
## License
This project is released under the MIT License. Feel free to use it for your negative response needs!
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!