Skip to content
Cyril Kato edited this page Jan 20, 2026 · 2 revisions

Welcome to the AcceptLanguage wiki! This gem helps you parse the Accept-Language HTTP header and match user language preferences against your application's available locales.

Table of Contents

What is Accept-Language?

When a browser sends a request to your server, it includes an Accept-Language header that looks something like this:

Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5

This header tells your application: "I prefer Swiss French, then French, then English, then German, and I'll accept anything else as a last resort."

Parsing this header correctly—respecting quality values, wildcards, and prefix matching rules—is exactly what this gem does.

Quick Example

require "accept_language"

# Parse the header and find the best match
AcceptLanguage.parse("fr-CH, fr;q=0.9, en;q=0.8").match(:en, :fr, :"fr-CH")
# => :"fr-CH"

That's it. One line to parse, one method to match.

Key Features

Standards-compliant
Implements RFC 7231 (Accept-Language header) and RFC 4647 (Basic Filtering matching scheme).
Quality values
Respects user preferences from q=1 (most preferred) down to q=0 (not acceptable).
Prefix matching
The range en correctly matches en-US, en-GB, and other regional variants.
Wildcards
Supports * to match any language not explicitly listed.
Exclusions
Handles q=0 to explicitly reject specific languages.
Thread-safe
Parser instances are immutable and safe to share across threads.

Wiki Pages

Getting Started

  • Getting Started — Install the gem and write your first matching code in 5 minutes.

Core Concepts

Framework Integration

Practical Usage

Standards Reference

This library conforms to:

Specification Description
RFC 7231 §5.3.5 Accept-Language header definition
RFC 7231 §5.3.1 Quality values syntax
RFC 4647 §3.3.1 Basic Filtering matching scheme
BCP 47 Language tag structure

Additional Resources

Contributing

Found an issue or have a suggestion? Feel free to open an issue or submit a pull request.


Ready to get started? Head over to Getting Started

Clone this wiki locally