Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c7e2cef
Add bin/setup script
mjankowski Jun 20, 2024
b67a302
Remove travis config
mjankowski Jun 20, 2024
8f5f34e
Remove Guardfile
mjankowski Jun 20, 2024
a0c49c5
Remove cucumber tests
mjankowski Jun 20, 2024
6747f8c
Require spec helper
mjankowski Jun 20, 2024
a99f5ff
Remove cucumber from Rakefile
mjankowski Jun 20, 2024
12bd401
Formatting once over on lib/
mjankowski Jun 20, 2024
97a53de
Ignore rspec status and coverage files
mjankowski Jun 20, 2024
6be2c78
Inherit from AC::Base in auto locale spec
mjankowski Jun 20, 2024
69364f1
Add GH Actions config
mjankowski Jun 20, 2024
161a588
Add standard and rspec binstub
mjankowski Jun 20, 2024
b77769a
Formatting once over on spec
mjankowski Jun 20, 2024
31a2f61
Once over on gemspec
mjankowski Jun 20, 2024
aba65d3
Use combustion for rails integration specs
mjankowski Jun 20, 2024
e299778
Remove travis badge
mjankowski Jun 20, 2024
b65b587
Once over on README
mjankowski Jun 20, 2024
3d3eafc
Allow ruby 2.7+
mjankowski Jun 20, 2024
e5a14e5
I18n will come in via rails
mjankowski Jun 20, 2024
b3ce7e2
rack will come in via rails
mjankowski Jun 20, 2024
4eecef0
Add license copy
mjankowski Jun 20, 2024
b54cb8b
Improve gemspec files listing
mjankowski Jun 20, 2024
8fbfcba
Improve gemspec files listing
mjankowski Jun 20, 2024
d206bd0
Improve gemspec files listing
mjankowski Jun 20, 2024
6d33037
Terminology correction
mjankowski Jun 20, 2024
fc722ab
Add CI matrix for ruby versions
mjankowski Jun 20, 2024
4596485
Remove sqllite3 (no db in specs)
mjankowski Jun 20, 2024
784524d
Remove listen gem
mjankowski Jun 20, 2024
396bce0
Move valid locale format to constant in parser
mjankowski Jun 20, 2024
a4bd415
Extract `languages_from_header` private method in `Parser`
mjankowski Jun 20, 2024
f30b8d9
Extract constant for default language quality in Parser
mjankowski Jun 20, 2024
701f747
Parser comments
mjankowski Jun 20, 2024
3df65dc
Rspec config
mjankowski Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Ruby

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
ruby-version:
- '3.0'
- '3.1'
- '3.2'
- '3.3'

steps:
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Run specs
run: |
bin/rspec

- name: Lint with standard
run: |
bin/standardrb
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ pkg/*
.rvmrc
log/*.log
tmp/

# rspec failure tracking
.rspec_status

/coverage/
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--color
--format progress
--require spec_helper
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
source "https://rubygems.org"

gemspec

gem "combustion"
gem "rack-test"
gem "rails", "> 6"
gem "rake"
gem "rspec-rails"
gem "rspec"
gem "simplecov", require: false
gem "standard"
8 changes: 0 additions & 8 deletions Guardfile

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# HttpAcceptLanguage [![Build Status](https://travis-ci.org/iain/http_accept_language.svg?branch=master)](https://travis-ci.org/iain/http_accept_language)
# HttpAcceptLanguage

A gem which helps you detect the users preferred language, as sent by the "Accept-Language" HTTP header.
A gem which helps you detect the users preferred language, as sent by the
"Accept-Language" HTTP header.

The algorithm is based on [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html), with one exception:
when a user requests "en-US" and "en" is an available language, "en" is deemed compatible with "en-US".
The RFC specifies that the requested language must either exactly match the available language or must exactly match a prefix of the available language. This means that when the user requests "en" and "en-US" is available, "en-US" would be compatible, but not the other way around. This is usually not what you're looking for.
The algorithm is based on [RFC 2616], with one exception: when a user requests
`en-US` and `en` is an available language, `en` is deemed compatible with
`en-US`. The RFC specifies that the requested language must either exactly match
the available language or must exactly match a prefix of the available language.
This means that when the user requests `en` and `en-US` is available, `en-US`
would be compatible, but not the other way around. This is usually not what
you're looking for.

Since version 2.0, this gem is Rack middleware.

Expand All @@ -30,11 +35,11 @@ class SomeController < ApplicationController
end
```

You can easily set the locale used for i18n in a before-filter:
You can easily set the locale used for i18n with a filter:

```ruby
class SomeController < ApplicationController
before_filter :set_locale
before_action :set_locale

private
def set_locale
Expand All @@ -43,12 +48,11 @@ class SomeController < ApplicationController
end
```

If you want to enable this behavior by default in your controllers, you can just include the provided concern:
To enable this behavior by default, include the provided concern:

```ruby
class ApplicationController < ActionController::Base
include HttpAcceptLanguage::AutoLocale

#...
end
```
Expand Down Expand Up @@ -88,21 +92,21 @@ end

## Available methods

* **user_preferred_languages**:
Returns a sorted array based on user preference in HTTP_ACCEPT_LANGUAGE, sanitized and all.
* **preferred_language_from(languages)**:
Finds the locale specifically requested by the browser
* **compatible_language_from(languages)**:
Returns the first of the user_preferred_languages that is compatible with the available locales.
* **user_preferred_languages**: Returns a sorted array based on user preference
in `HTTP_ACCEPT_LANGUAGE`, sanitized and all.
* **preferred_language_from(languages)**: Finds the locale specifically
requested by the browser.
* **compatible_language_from(languages)**: Returns the first of the
`user_preferred_languages` that is compatible with the available locales.
Ignores region.
* **sanitize_available_locales(languages)**:
Returns a supplied list of available locals without any extra application info
that may be attached to the locale for storage in the application.
* **language_region_compatible_from(languages)**:
Returns the first of the user preferred languages that is
also found in available languages. Finds best fit by matching on
primary language first and secondarily on region. If no matching region is
found, return the first language in the group matching that primary language.
* **sanitize_available_locales(languages)**: Returns a supplied list of
available locales without any extra application info that may be attached to
the locale for storage in the application.
* **language_region_compatible_from(languages)**: Returns the first of the user
preferred languages that is also found in available languages. Finds best fit
by matching on primary language first and secondarily on region. If no
matching region is found, return the first language in the group matching that
primary language.

## Installation

Expand All @@ -122,4 +126,6 @@ Run `bundle install` to install it.

---

Released under the MIT license
Released under the MIT license.

[RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
11 changes: 2 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require "bundler/gem_tasks"

require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber)

Cucumber::Rake::Task.new(:wip, "Run features tagged with @wip") do |t|
t.profile = "wip"
end

task :default => [:spec, :cucumber, :wip]
task default: [:spec]
27 changes: 27 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
27 changes: 27 additions & 0 deletions bin/standardrb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'standardrb' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("standard", "standardrb")
9 changes: 9 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "rubygems"
require "bundler"

Bundler.require :default, :development

Combustion.initialize! :all
run Combustion::Application
2 changes: 0 additions & 2 deletions cucumber.yml

This file was deleted.

29 changes: 0 additions & 29 deletions features/rails_integration.feature

This file was deleted.

37 changes: 0 additions & 37 deletions features/steps/rails.rb

This file was deleted.

Loading