201 lines
5.1 KiB
Markdown
201 lines
5.1 KiB
Markdown
# No as a Service (NaaS) - Multilingual Edition
|
|
|
|
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 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 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
|
|
|
|
## Language Detection
|
|
|
|
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 API
|
|
```bash
|
|
# Auto-detected language
|
|
curl -H "Accept: application/json" http://localhost:4567/
|
|
|
|
# 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 Responses
|
|
|
|
**Basic Response:**
|
|
```json
|
|
{
|
|
"answer": "Absolutt ikke",
|
|
"language": "no",
|
|
"language_name": "Norsk (Norwegian)",
|
|
"timestamp": "2025-06-06T12:00:00Z",
|
|
"service": "No as a Service",
|
|
"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"
|
|
}
|
|
```
|
|
|
|
## 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",
|
|
"languages_loaded": 8,
|
|
"timestamp": "2025-06-06T12:00:00Z"
|
|
}
|
|
```
|
|
|
|
## File Structure
|
|
|
|
```
|
|
.
|
|
├── 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. Perfect for all your multilingual negative response needs!. Feel free to use it for your negative response needs!
|