Coder Social home page Coder Social logo

relocale's Introduction

relocale

Overview

relocale redirects requests via the Accept-Language HTTP header. It is meant for static sites that need to redirect users based on their locale without any JavaScript or meta tags.

Installation

Before you start, you need to make sure that the relocale binary is installed somewhere. I will leave that part up to you.

Preparation

Create the relocale user:

useradd --system --shell /bin/false relocale

Locale configuration

Here is an example of how a configuration file could be written:

# Mandatory fallbacks which are used when no or empty values have been provided.
locale = 'en'
destination = '/${locale}${path}'

[network]
# Network address for relocale.
# This defaults to localhost:10451.
address = 'localhost:10451'

[locales]
# This regular expression will set the locale to 'en' if the client's locale
# matches 'en', 'en-US', ...
en.alias = '^en-.+$'

de.alias = '^de-.+$'

# The destination path which will be redirected to.
# This is a template string with the following predefined parameters:
# * path: Original request path
# * locale: Current locale
de.destination = '/${locale}${path}'

Service configuration

[Unit]
Description=relocale redirection service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/relocale --config %i
ProtectSystem=strict
ReadOnlyPaths=/etc/relocale
WorkingDirectory=/etc/relocale
TimeoutStopSec=20
KillMode=mixed
Restart=on-failure
User=relocale
Group=relocale

[Install]
WantedBy=multi-user.target

Next, put the systemd unit file (e.g. as [email protected]) into /etc/systemd/system. This unit file might not work for every setup out there, so make sure to modify it as needed.

Reverse proxy

server {
    # Change this to match your server's name or domain.
    server_name example.com;

    # This matches any path without the available locales 'en' and 'de' at the
    # start.
    location ~ ^/(?!(de|en)) {
        # Change this to match relocale's configuration.
        proxy_pass http://localhost:10451;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Every other request will serve a static file.
    location / {
        root /srv/http/example.com;
        index index.html;
    }

    # Your TLS configuration goes here.
    listen 80;
}

relocale's People

Contributors

lukaswrz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.