Skip to content

Use map instead of 'if' where applicable #8

@oxpa

Description

@oxpa

{% for code, lang in languages %}

this part:

{% for code, lang in languages %}
  if ($http_accept_language ~* ^{{code}}) {
    # Not safe, but it seems to work. May change depending on the outer directives.
    set $lang {{code}};
  }
{% endfor %}

can be replaced with:


map $http_accept_language $lang {
{% for code, lang in languages %}
^{{code}} {{code}};
{% endfor %}
default en;
}

which reduces the size of configuration (and let you avoid IFs).
You can make it even more interesting by composing a more complex RE with capture like:
^(?<language>(en|fr|de)) $language
Which will result in only two lines: one RE for languages and one default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions