mirror of
https://github.com/ClaperCo/Claper.git
synced 2026-02-24 04:01:04 +01:00
290 lines
12 KiB
HTML
290 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="generator" content="ExDoc v0.29.4">
|
|
<meta name="project" content="Claper v1.7.0">
|
|
|
|
<title>ClaperWeb.Plugs.Locale — Claper v1.7.0</title>
|
|
<link rel="stylesheet" href="dist/html-elixir-HHVY3JYD.css" />
|
|
|
|
|
|
<script src="dist/handlebars.runtime-NWIB6V2M.js"></script>
|
|
<script src="dist/handlebars.templates-XWGFFSCD.js"></script>
|
|
<script src="dist/sidebar_items-E6912480.js"></script>
|
|
|
|
<script src="docs_config.js"></script>
|
|
|
|
<script async src="dist/html-JDI3AVDD.js"></script>
|
|
|
|
|
|
</head>
|
|
<body data-type="modules" class="page-module">
|
|
<script>
|
|
|
|
try {
|
|
var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}');
|
|
|
|
if (settings.theme === 'dark' ||
|
|
((settings.theme === 'system' || settings.theme == null) &&
|
|
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
) {
|
|
document.body.classList.add('dark')
|
|
}
|
|
} catch (error) { }
|
|
</script>
|
|
|
|
<div class="main">
|
|
|
|
<button class="sidebar-button sidebar-toggle" aria-label="toggle sidebar">
|
|
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
|
|
</button>
|
|
|
|
<section class="sidebar">
|
|
<form class="sidebar-search" action="search.html">
|
|
<button type="submit" class="search-button" aria-label="Submit Search">
|
|
<i class="ri-search-2-line" aria-hidden="true" title="Submit search"></i>
|
|
</button>
|
|
<button type="button" tabindex="-1" class="search-close-button" aria-label="Cancel Search">
|
|
<i class="ri-close-line ri-lg" aria-hidden="true" title="Cancel search"></i>
|
|
</button>
|
|
<label class="search-label">
|
|
<p class="sr-only">Search</p>
|
|
<input name="q" type="text" class="search-input" placeholder="Search..." aria-label="Input your search terms" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
|
</label>
|
|
</form>
|
|
|
|
<div class="autocomplete">
|
|
<div class="autocomplete-results">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-header">
|
|
|
|
<a href="https://claper.co">
|
|
<img src="assets/logo.png" alt="Claper" class="sidebar-projectImage">
|
|
</a>
|
|
|
|
<div class="sidebar-projectDetails">
|
|
<a href="https://claper.co" class="sidebar-projectName" translate="no">
|
|
Claper
|
|
</a>
|
|
<div class="sidebar-projectVersion" translate="no">
|
|
v1.7.0
|
|
</div>
|
|
</div>
|
|
<ul class="sidebar-listNav">
|
|
<li><a id="extras-list-link" href="#full-list">GUIDES</a></li>
|
|
|
|
<li><a id="modules-list-link" href="#full-list">Modules</a></li>
|
|
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="gradient"></div>
|
|
<ul id="full-list"></ul>
|
|
</section>
|
|
|
|
<section class="content">
|
|
<output role="status" id="toast"></output>
|
|
<div class="content-outer">
|
|
<div id="content" class="content-inner">
|
|
|
|
<h1>
|
|
<button class="icon-action display-settings">
|
|
<i class="ri-settings-3-line"></i>
|
|
<span class="sr-only">Settings</span>
|
|
</button>
|
|
|
|
|
|
<a href="https://github.com/ClaperCo/Claper/blob/main/lib/claper_web/plugs/locale.ex#L1" title="View Source" class="icon-action" rel="help">
|
|
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
|
<span class="sr-only">View Source</span>
|
|
</a>
|
|
|
|
<span translate="no">ClaperWeb.Plugs.Locale</span>
|
|
<small class="app-vsn" translate="no">(Claper v1.7.0)</small>
|
|
|
|
</h1>
|
|
|
|
|
|
<section id="moduledoc">
|
|
<p> Plug to set the locale based on the Accept-Language header.</p><p> ## Usage</p><p> Add the plug to your pipeline in <code class="inline">router.ex</code>:</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="n">pipeline</span><span class="w"> </span><span class="ss">:browser</span><span class="w"> </span><span class="k" data-group-id="5425085124-1">do</span><span class="w">
|
|
</span><span class="n">...</span><span class="w">
|
|
</span><span class="n">plug</span><span class="w"> </span><span class="nc">ClaperWeb.Plugs.Locale</span><span class="w">
|
|
</span><span class="k" data-group-id="5425085124-1">end</span></code></pre><p> ## Configuration</p><p> The plug will use the <code class="inline">:default_locale</code> configuration value as the default
|
|
locale. If the <code class="inline">:default_locale</code> is not set, it will default to <code class="inline">:en</code>.</p><p> ## Accept-Language header</p><p> The plug will parse the <code class="inline">Accept-Language</code> header and set the locale to the
|
|
first language in the list that is known to the application. If no language
|
|
is known, the locale will not be changed.</p><p> The <code class="inline">Accept-Language</code> header is a comma-separated list of language tags with
|
|
optional quality values. The quality value is a number between 0 and 1,
|
|
where 1 is the highest quality. The quality value is optional and defaults
|
|
to 1.</p><p> Examples:</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="nc">Accept</span><span class="o">-</span><span class="ss">Language</span><span class="p">:</span><span class="w"> </span><span class="n">en</span><span class="o">-</span><span class="nc">US</span><span class="p">,</span><span class="n">en</span><span class="p">;</span><span class="n">q</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span><span class="n">da</span><span class="p">;</span><span class="n">q</span><span class="o">=</span><span class="mf">0.6</span></code></pre><p> The above example will set the locale to <code class="inline">:en</code> if it is known to the
|
|
application. If <code class="inline">:en</code> is not known, it will set the locale to <code class="inline">:da</code> if it is
|
|
known to the application. If neither <code class="inline">:en</code> nor <code class="inline">:da</code> is known, the locale
|
|
will not be changed.</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="nc">Accept</span><span class="o">-</span><span class="ss">Language</span><span class="p">:</span><span class="w"> </span><span class="n">en</span><span class="o">-</span><span class="nc">US</span><span class="p">,</span><span class="n">en</span><span class="p">;</span><span class="n">q</span><span class="o">=</span><span class="mf">0.8</span></code></pre><p> The above example will set the locale to <code class="inline">:en</code> if it is known to the
|
|
application. If <code class="inline">:en</code> is not known, the locale will not be changed.</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="nc">Accept</span><span class="o">-</span><span class="ss">Language</span><span class="p">:</span><span class="w"> </span><span class="n">en</span><span class="o">-</span><span class="nc">US</span></code></pre><p> The above example will set the locale to <code class="inline">:en</code> if it is known to the
|
|
application. If <code class="inline">:en</code> is not known, the locale will not be changed.</p><p> ## Known locales</p><p> The plug will only set the locale if it is known to the application. The
|
|
known locales are determined by the <code class="inline">:gettext</code> configuration. The
|
|
<code class="inline">:gettext</code> configuration is set in <code class="inline">config/config.exs</code>:</p><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="n">config</span><span class="w"> </span><span class="ss">:claper</span><span class="p">,</span><span class="w"> </span><span class="nc">ClaperWeb.Gettext</span><span class="p">,</span><span class="w">
|
|
</span><span class="ss">default_locale</span><span class="p">:</span><span class="w"> </span><span class="s">"en"</span><span class="p">,</span><span class="w">
|
|
</span><span class="ss">default_domain</span><span class="p">:</span><span class="w"> </span><span class="s">"claper"</span><span class="p">,</span><span class="w">
|
|
</span><span class="ss">available_locales</span><span class="p">:</span><span class="w"> </span><span class="sx">~w(en fr)</span></code></pre><p> The <code class="inline">:available_locales</code> option is</p>
|
|
</section>
|
|
|
|
|
|
<section id="summary" class="details-list">
|
|
<h1 class="section-heading">
|
|
<a class="hover-link" href="#summary">
|
|
<i class="ri-link-m" aria-hidden="true"></i>
|
|
<span class="sr-only">Link to this section</span>
|
|
</a>
|
|
Summary
|
|
</h1>
|
|
<div class="summary-functions summary">
|
|
<h2>
|
|
<a href="#functions">Functions</a>
|
|
</h2>
|
|
|
|
<div class="summary-row">
|
|
<div class="summary-signature">
|
|
<a href="#call/2" translate="no">call(conn, opts)</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="summary-row">
|
|
<div class="summary-signature">
|
|
<a href="#extract_accept_language/1" translate="no">extract_accept_language(conn)</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="summary-row">
|
|
<div class="summary-signature">
|
|
<a href="#init/1" translate="no">init(opts)</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
<section id="functions" class="details-list">
|
|
<h1 class="section-heading">
|
|
<a class="hover-link" href="#functions">
|
|
<i class="ri-link-m" aria-hidden="true"></i>
|
|
<span class="sr-only">Link to this section</span>
|
|
</a>
|
|
Functions
|
|
</h1>
|
|
<div class="functions-list">
|
|
<section class="detail" id="call/2">
|
|
|
|
<div class="detail-header">
|
|
<a href="#call/2" class="detail-link" title="Link to this function">
|
|
<i class="ri-link-m" aria-hidden="true"></i>
|
|
<span class="sr-only">Link to this function</span>
|
|
</a>
|
|
<h1 class="signature" translate="no">call(conn, opts)</h1>
|
|
|
|
<a href="https://github.com/ClaperCo/Claper/blob/main/lib/claper_web/plugs/locale.ex#L67" class="icon-action" rel="help" title="View Source">
|
|
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
|
<span class="sr-only">View Source</span>
|
|
</a>
|
|
|
|
|
|
</div>
|
|
|
|
<section class="docstring">
|
|
|
|
|
|
</section>
|
|
</section>
|
|
<section class="detail" id="extract_accept_language/1">
|
|
|
|
<div class="detail-header">
|
|
<a href="#extract_accept_language/1" class="detail-link" title="Link to this function">
|
|
<i class="ri-link-m" aria-hidden="true"></i>
|
|
<span class="sr-only">Link to this function</span>
|
|
</a>
|
|
<h1 class="signature" translate="no">extract_accept_language(conn)</h1>
|
|
|
|
<a href="https://github.com/ClaperCo/Claper/blob/main/lib/claper_web/plugs/locale.ex#L86" class="icon-action" rel="help" title="View Source">
|
|
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
|
<span class="sr-only">View Source</span>
|
|
</a>
|
|
|
|
|
|
</div>
|
|
|
|
<section class="docstring">
|
|
|
|
|
|
</section>
|
|
</section>
|
|
<section class="detail" id="init/1">
|
|
|
|
<div class="detail-header">
|
|
<a href="#init/1" class="detail-link" title="Link to this function">
|
|
<i class="ri-link-m" aria-hidden="true"></i>
|
|
<span class="sr-only">Link to this function</span>
|
|
</a>
|
|
<h1 class="signature" translate="no">init(opts)</h1>
|
|
|
|
<a href="https://github.com/ClaperCo/Claper/blob/main/lib/claper_web/plugs/locale.ex#L65" class="icon-action" rel="help" title="View Source">
|
|
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
|
<span class="sr-only">View Source</span>
|
|
</a>
|
|
|
|
|
|
</div>
|
|
|
|
<section class="docstring">
|
|
|
|
|
|
</section>
|
|
</section>
|
|
|
|
</div>
|
|
</section>
|
|
|
|
<footer class="footer">
|
|
<p>
|
|
|
|
<span class="line">
|
|
<button class="a-main footer-button display-quick-switch" title="Search HexDocs packages">
|
|
Search HexDocs
|
|
</button>
|
|
|
|
<a href="Claper.epub" title="ePub version">
|
|
Download ePub version
|
|
</a>
|
|
|
|
</span>
|
|
</p>
|
|
|
|
<p class="built-using">
|
|
Built using
|
|
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v0.29.4) for the
|
|
|
|
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
|
|
|
|
</p>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
|
|
</body>
|
|
</html>
|