<commit_before>rack-i8n_best_langs: guess best language for content served over Rack
=====================================================================

rack-i18n_best_langs is a Rack middleware component that takes care of
understanding what are the best languages for a site visitor.

If you manage a site that has content many languages and also localized URLs,
you will find `rack-i18n_best_langs` very useful, especially when used in
conjunction with `rack-i18n_routes`.

Differently from other similar Rack middleware components,
`rack-i18n_best_langs` returns a list of languages in order of guessed
importance, not a single language. Also, it does not require the use of the
`i18n` gem.


Features
--------

Language discovery is done using three clues:

* the presences of language tags in paths (e.g. `/service/warranty/ita`),
* the content of the HTTP `Accept-Language` header,
* the content of the `rack.i18n_best_langs` cookie when set.

All these clues are taken into account and evaluated against the list
of languages available and their preferred order. It is possible to configure
which of these clues is the most important.

An additional clue is available when `AliasMapping` (part of
[rack-i18n_routes](http://rubydoc.info/gems/rack-i18n_routes)) is used as the
mapping function: the language in which the path is written. For example,
`/articles/the-victory` add preference of English, `/artículos/la-victoria`
for Spanish and `/articles/la-victoire` for French.


How it works
------------

Each request is analysed in search for possible clues that can expose what
are the best languages to use in the content served in response. Each clue
contributes part of the final score of each language; the score is amplified
by the weight associated to the clue.

For example, if a person requests the URL `/article/vittoria/ita` from
a browser in a German internet point (thus sending `Accept-Language: de-DE`),
their request would lead to the following scores:

* ita: 315 = 0 (not in header) + 15 (partially lang of uri) + 300 (path ends in '/ita')
* eng: 15 = 0 (not in header) + 15 (partially lang of uri) + 0 (path does not end in '/eng')
* ger: 3 = 3 (in header) + 0 (not lang of uri) + 0 (path does not end in '/ger')

The downstream application will find the guessed languages in the
`rack.i18n_best_langs` env variable, in order of importance.

    env['rack.i18n_best_langs'] # => [ 'ita', 'eng', 'ger' ]

At this point, it is up to the application to choose what to do, either change
the locale using the `i18n` gem, set up its own locale management system or<commit_msg>Use consistent language and markup in explainations<commit_after>rack-i8n_best_langs: guess best language for content served over Rack
=====================================================================

rack-i18n_best_langs is a Rack middleware component that takes care of
understanding what are the best languages for a site visitor.

If you manage a site that has content many languages and also localized URLs,
you will find `rack-i18n_best_langs` very useful, especially when used in
conjunction with `rack-i18n_routes`.

Differently from other similar Rack middleware components,
`rack-i18n_best_langs` returns a list of languages in order of guessed
importance, not a single language. Also, it does not require the use of the
`i18n` gem.


Features
--------

Language discovery is done using three clues:

* the presences of language tags in paths (e.g. `/service/warranty/ita`),
* the content of the HTTP `Accept-Language` header,
* the content of the `rack.i18n_best_langs` cookie when set.

All these clues are taken into account and evaluated against the list
of languages available and their preferred order. It is possible to configure
which of these clues is the most important.

An additional clue is available when `AliasMapping` (part of
[rack-i18n_routes](http://rubydoc.info/gems/rack-i18n_routes)) is used as the
mapping function: the language in which the path is written. For example,
`/articles/the-victory` add preference of English, `/artículos/la-victoria`
for Spanish and `/articles/la-victoire` for French.


How it works
------------

Each request is analysed in search for possible clues that can expose what
are the best languages to use in the content served in response. Each clue
contributes part of the final score of each language; the score is amplified
by the weight associated to the clue.

For example, if a person requests the URL `/article/vittoria/ita` from
a browser in a German internet point (thus sending `Accept-Language: de-DE`),
their request would lead to the following scores:

* `ita`: 315 = 0 (not in header) + 15 (partially language of URL) + 300 (path
   ends in `/ita`);
* `eng`: 15 = 0 (not in header) + 15 (partially language of URL) + 0 (path
   does not end in `/eng`);
* `ger`: 3 = 3 (in header) + 0 (not language of URL) + 0 (path does not end
   in `/ger`).

The downstream application will find the guessed languages in the
`rack.i18n_best_langs` env variable, in order of importance.

    env['rack.i18n_best_langs'] # => [ 'ita', 'eng', 'ger' ]

At this point, it is up to the application to choose what to do, either change
the locale using the `i18n` gem, set up its own locale management system or
{'fraction_non_alphanumeric': 0.10147951441578149, 'fraction_numerical': 0.015933232169954476, 'mean_word_length': 4.353299492385787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3031266', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1455, 'n_words': 749}