No description
Find a file
2025-06-10 21:10:15 +02:00
public split up the app 2025-06-06 23:16:10 +02:00
spec gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
test gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
views more languages 2025-06-10 20:55:22 +02:00
.rubocop.yml gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
.ruby-version ruby version 2025-06-06 23:20:59 +02:00
app.rb gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
Containerfile add curl so healthcheck works 2025-06-10 21:09:37 +02:00
Gemfile gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
Gemfile.lock gemini-suggestions, tests-fail 2025-06-06 23:18:20 +02:00
README.md improvement 2025-06-06 18:55:54 +02:00
responses.yml tweak languages and layout 2025-06-06 19:19:35 +02:00
TLDR.md doc: Update TLDR 2025-06-10 21:10:15 +02:00

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, nnno (Norwegian variants)
  • sv-*sv (Swedish variants)
  • da-*da (Danish variants)
  • etc.

Usage Examples

HTML (Browser)

# 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

# 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:

{
  "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:

{
  "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

# 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

podman build -t naas .

Run with Podman

# 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:

{
  "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:

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!