analytics/Plausible.Cldr.Locale.html

813 lines
41 KiB
HTML
Raw Normal View History

<!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.30.3">
<meta name="project" content="Plausible v0.0.1">
<title>Plausible.Cldr.Locale — Plausible v0.0.1</title>
<link rel="stylesheet" href="dist/html-elixir-P5GXSCHE.css" />
<script src="dist/handlebars.runtime-NWIB6V2M.js"></script>
<script src="dist/handlebars.templates-NBND3S2D.js"></script>
<script src="dist/sidebar_items-EC7673F3.js"></script>
<script src="docs_config.js"></script>
<script async src="dist/html-CGDDOCMI.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="readme.html">
<img src="assets/logo.png" alt="Plausible" class="sidebar-projectImage">
</a>
<div class="sidebar-projectDetails">
<a href="readme.html" class="sidebar-projectName" translate="no">
Plausible
</a>
<div class="sidebar-projectVersion" translate="no">
v0.0.1
</div>
</div>
<ul class="sidebar-listNav">
<li><a id="extras-list-link" href="#full-list">Pages</a></li>
<li><a id="modules-list-link" href="#full-list">Modules</a></li>
<li><a id="tasks-list-link" href="#full-list"><span translate="no">Mix</span> Tasks</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/plausible/analytics/blob/main/lib/plausible/cldr.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">Plausible.Cldr.Locale</span>
<small class="app-vsn" translate="no">(Plausible v0.0.1)</small>
</h1>
<section id="moduledoc">
<p>Backend module that provides functions
to define new locales and display human-readable
locale names for presentation purposes.</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>
Summary
</a>
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#fallback_locale_names/1" translate="no">fallback_locale_names(locale)</a>
</div>
<div class="summary-synopsis"><p>Returns the list of fallback locale names, starting
with the provided locale name.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#fallback_locales/1" translate="no">fallback_locales(locale)</a>
</div>
<div class="summary-synopsis"><p>Returns the list of fallback locales, starting
with the provided locale name.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#locale_for_territory/1" translate="no">locale_for_territory(territory)</a>
</div>
<div class="summary-synopsis"><p>Returns the &quot;best fit&quot; locale for a given territory.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#locale_from_host/2" translate="no">locale_from_host(host, options \\ [])</a>
</div>
<div class="summary-synopsis"><p>Returns a &quot;best fit&quot; locale for a host name.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#new/1" translate="no">new(locale_name)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#new!/1" translate="no">new!(locale_name)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#script_direction_from_locale/1" translate="no">script_direction_from_locale(locale)</a>
</div>
<div class="summary-synopsis"><p>Returns the script direction for a locale.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#territory_from_host/1" translate="no">territory_from_host(host)</a>
</div>
<div class="summary-synopsis"><p>Returns the last segment of a host that might
be a territory.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#territory_from_locale/1" translate="no">territory_from_locale(locale)</a>
</div>
<div class="summary-synopsis"><p>Returns the territory from a language tag or
locale name.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#timezone_from_locale/1" translate="no">timezone_from_locale(locale)</a>
</div>
<div class="summary-synopsis"><p>Returns the time zone from a language tag or
locale name.</p></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>
Functions
</a>
</h1>
<div class="functions-list">
<section class="detail" id="fallback_locale_names/1">
<div class="detail-header">
<a href="#fallback_locale_names/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">fallback_locale_names(locale)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.26.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> fallback_locale_names(<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>() | <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_reference/0">Cldr.Locale.locale_reference</a>()) ::
{:ok, [<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_name/0">Cldr.Locale.locale_name</a>(), ...]} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns the list of fallback locale names, starting
with the provided locale name.</p><p>Fallbacks are a list of locate names which can
be used to resolve translation or other localization
data if such localised data does not exist for
this specific locale..</p><h2 id="fallback_locale_names/1-arguments" class="section-heading">
<a href="#fallback_locale_names/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">locale_name</code> is any locale name returned by
<a href="Plausible.Cldr.html#known_locale_names/0"><code class="inline">Plausible.Cldr.known_locale_names/0</code></a></li></ul><h2 id="fallback_locale_names/1-returns" class="section-heading">
<a href="#fallback_locale_names/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p><code class="inline">{:ok, list_of_locale_names}</code> or</p></li><li><p><code class="inline">{:error, {exception, reason}}</code></p></li></ul><h2 id="fallback_locale_names/1-examples" class="section-heading">
<a href="#fallback_locale_names/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">fallback_locale_names</span><span class="p" data-group-id="4414090342-1">(</span><span class="ss">:&quot;fr-CA&quot;</span><span class="p" data-group-id="4414090342-1">)</span><span class="w">
</span><span class="p" data-group-id="4414090342-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="4414090342-3">[</span><span class="ss">:&quot;fr-CA&quot;</span><span class="p">,</span><span class="w"> </span><span class="ss">:fr</span><span class="p">,</span><span class="w"> </span><span class="ss">:und</span><span class="p" data-group-id="4414090342-3">]</span><span class="p" data-group-id="4414090342-2">}</span><span class="w">
</span><span class="c1"># Fallbacks are typically formed by progressively</span><span class="w">
</span><span class="c1"># stripping variant, territory and script from the</span><span class="w">
</span><span class="c1"># given locale name. But not always - there are</span><span class="w">
</span><span class="c1"># certain fallbacks that take a different path.</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">fallback_locale_names</span><span class="p" data-group-id="4414090342-4">(</span><span class="ss">:nb</span><span class="p" data-group-id="4414090342-4">)</span><span class="w">
</span><span class="p" data-group-id="4414090342-5">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="4414090342-6">[</span><span class="ss">:nb</span><span class="p">,</span><span class="w"> </span><span class="ss">:no</span><span class="p">,</span><span class="w"> </span><span class="ss">:und</span><span class="p" data-group-id="4414090342-6">]</span><span class="p" data-group-id="4414090342-5">}</span></code></pre>
</section>
</section>
<section class="detail" id="fallback_locales/1">
<div class="detail-header">
<a href="#fallback_locales/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">fallback_locales(locale)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.26.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> fallback_locales(<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>() | <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_reference/0">Cldr.Locale.locale_reference</a>()) ::
{:ok, [<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>(), ...]} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns the list of fallback locales, starting
with the provided locale name.</p><p>Fallbacks are a list of locate names which can
be used to resolve translation or other localization
data if such localised data does not exist for
this specific locale.</p><h2 id="fallback_locales/1-arguments" class="section-heading">
<a href="#fallback_locales/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">locale_name</code> is any locale name returned by
<a href="Plausible.Cldr.html#known_locale_names/0"><code class="inline">Plausible.Cldr.known_locale_names/0</code></a></li></ul><h2 id="fallback_locales/1-returns" class="section-heading">
<a href="#fallback_locales/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p><code class="inline">{:ok, list_of_locales}</code> or</p></li><li><p><code class="inline">{:error, {exception, reason}}</code></p></li></ul><h2 id="fallback_locales/1-examples" class="section-heading">
<a href="#fallback_locales/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">fallback_locales</span><span class="p" data-group-id="8783066591-1">(</span><span class="ss">:&quot;fr-CA&quot;</span><span class="p" data-group-id="8783066591-1">)</span><span class="w">
</span><span class="p">=&gt;</span><span class="w"> </span><span class="p" data-group-id="8783066591-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8783066591-3">[</span><span class="p" data-group-id="8783066591-4">#</span><span class="nc" data-group-id="8783066591-4">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-4">&lt;</span><span class="n">fr</span><span class="o">-</span><span class="nc">CA</span><span class="w"> </span><span class="p" data-group-id="8783066591-5">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-5">]</span><span class="p" data-group-id="8783066591-4">&gt;</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="8783066591-6">#</span><span class="nc" data-group-id="8783066591-6">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-6">&lt;</span><span class="n">fr</span><span class="w"> </span><span class="p" data-group-id="8783066591-7">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-7">]</span><span class="p" data-group-id="8783066591-6">&gt;</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8783066591-8">#</span><span class="nc" data-group-id="8783066591-8">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-8">&lt;</span><span class="n">und</span><span class="w"> </span><span class="p" data-group-id="8783066591-9">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-9">]</span><span class="p" data-group-id="8783066591-8">&gt;</span><span class="p" data-group-id="8783066591-3">]</span><span class="p" data-group-id="8783066591-2">}</span><span class="w">
</span><span class="c1"># Fallbacks are typically formed by progressively</span><span class="w">
</span><span class="c1"># stripping variant, territory and script from the</span><span class="w">
</span><span class="c1"># given locale name. But not always - there are</span><span class="w">
</span><span class="c1"># certain fallbacks that take a different path.</span><span class="w">
</span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">fallback_locales</span><span class="p" data-group-id="8783066591-10">(</span><span class="ss">:nb</span><span class="p" data-group-id="8783066591-10">)</span><span class="p">)</span><span class="w">
</span><span class="p">=&gt;</span><span class="w"> </span><span class="p" data-group-id="8783066591-11">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8783066591-12">[</span><span class="p" data-group-id="8783066591-13">#</span><span class="nc" data-group-id="8783066591-13">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-13">&lt;</span><span class="n">nb</span><span class="w"> </span><span class="p" data-group-id="8783066591-14">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-14">]</span><span class="p" data-group-id="8783066591-13">&gt;</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="8783066591-15">#</span><span class="nc" data-group-id="8783066591-15">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-15">&lt;</span><span class="n">no</span><span class="w"> </span><span class="p" data-group-id="8783066591-16">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-16">]</span><span class="p" data-group-id="8783066591-15">&gt;</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8783066591-17">#</span><span class="nc" data-group-id="8783066591-17">Cldr.LanguageTag</span><span class="p" data-group-id="8783066591-17">&lt;</span><span class="n">und</span><span class="w"> </span><span class="p" data-group-id="8783066591-18">[</span><span class="n">validated</span><span class="p" data-group-id="8783066591-18">]</span><span class="p" data-group-id="8783066591-17">&gt;</span><span class="p" data-group-id="8783066591-12">]</span><span class="p" data-group-id="8783066591-11">}</span></code></pre>
</section>
</section>
<section class="detail" id="locale_for_territory/1">
<div class="detail-header">
<a href="#locale_for_territory/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">locale_for_territory(territory)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.26.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> locale_for_territory(<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:territory_code/0">Cldr.Locale.territory_code</a>()) ::
{:ok, <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns the &quot;best fit&quot; locale for a given territory.</p><p>Using the population percentage data from CLDR, the
language most commonly spoken in the given territory
is used to form a locale name which is then validated
against the given backend.</p><p>First a territory-specific locale is validated and if
that fails, the base language only is validate.</p><p>For example, if the territory is <code class="inline">AU</code> then then the
language most spoken is &quot;en&quot;. First, the locale &quot;en-AU&quot;
is validated and if that fails, &quot;en&quot; is validated.</p><h2 id="locale_for_territory/1-arguments" class="section-heading">
<a href="#locale_for_territory/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">territory</code> is any ISO 3166 Alpha-2 territory
code that can be validated by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#validate_territory/1"><code class="inline">Cldr.validate_territory/1</code></a></li></ul><h2 id="locale_for_territory/1-returns" class="section-heading">
<a href="#locale_for_territory/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p><code class="inline">{:ok, language_tag}</code> or</p></li><li><p><code class="inline">{:error, {exception, reason}}</code></p></li></ul><h2 id="locale_for_territory/1-examples" class="section-heading">
<a href="#locale_for_territory/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<p> iex&gt; Plausible.Cldr.Locale.locale_for_territory(:AU)
Elixir.Plausible.Cldr.validate_locale(:&quot;en-AU&quot;)</p><p> iex&gt; Plausible.Cldr.Locale.locale_for_territory(:US)
Elixir.Plausible.Cldr.validate_locale(:&quot;en-US&quot;)</p><p> iex&gt; Plausible.Cldr.Locale.locale_for_territory(:ZZ)
{:error, {Cldr.UnknownTerritoryError, &quot;The territory :ZZ is unknown&quot;}}</p>
</section>
</section>
<section class="detail" id="locale_from_host/2">
<span id="locale_from_host/1"></span>
<div class="detail-header">
<a href="#locale_from_host/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">locale_from_host(host, options \\ [])</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.26.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> locale_from_host(<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>()) ::
{:ok, <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns a &quot;best fit&quot; locale for a host name.</p><h2 id="locale_from_host/2-arguments" class="section-heading">
<a href="#locale_from_host/2-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><p><code class="inline">host</code> is any valid host name</p></li><li><p><code class="inline">options</code> is a keyword list of options. The default
is <code class="inline">[]</code>.</p></li></ul><h2 id="locale_from_host/2-options" class="section-heading">
<a href="#locale_from_host/2-options">
<i class="ri-link-m" aria-hidden="true"></i>
Options
</a>
</h2>
<ul><li><code class="inline">:tlds</code> is a list of territory codes as upper-cased
atoms that are to be considered as top-level domains.
See <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#locale_from_host/2"><code class="inline">Cldr.Locale.locale_from_host/2</code></a> for the default
list.</li></ul><h2 id="locale_from_host/2-returns" class="section-heading">
<a href="#locale_from_host/2-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p><code class="inline">{:ok, langauge_tag}</code> or</p></li><li><p><code class="inline">{:error, {exception, reason}}</code></p></li></ul><h2 id="locale_from_host/2-notes" class="section-heading">
<a href="#locale_from_host/2-notes">
<i class="ri-link-m" aria-hidden="true"></i>
Notes
</a>
</h2>
<p>Certain top-level domains have become associated with content
underlated to the territory for who the domain is registered.
Therefore Google (and perhaps others) do not associate these
TLDs as belonging to the territory but rather are considered
generic top-level domain names.</p><h2 id="locale_from_host/2-examples" class="section-heading">
<a href="#locale_from_host/2-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">locale_from_host</span><span class="w"> </span><span class="s">&quot;a.b.com.au&quot;</span><span class="w">
</span><span class="nc">Elixir.Plausible.Cldr</span><span class="o">.</span><span class="n">validate_locale</span><span class="p" data-group-id="8187976307-1">(</span><span class="ss">:&quot;en-AU&quot;</span><span class="p" data-group-id="8187976307-1">)</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">locale_from_host</span><span class="p" data-group-id="8187976307-2">(</span><span class="s">&quot;a.b.com.tv&quot;</span><span class="p" data-group-id="8187976307-2">)</span><span class="w">
</span><span class="p" data-group-id="8187976307-3">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8187976307-4">{</span><span class="nc">Cldr.UnknownLocaleError</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;No locale was identified for territory </span><span class="se">\&quot;</span><span class="s">tv</span><span class="se">\&quot;</span><span class="s">&quot;</span><span class="p" data-group-id="8187976307-4">}</span><span class="p" data-group-id="8187976307-3">}</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">locale_from_host</span><span class="p" data-group-id="8187976307-5">(</span><span class="s">&quot;a.b.com&quot;</span><span class="p" data-group-id="8187976307-5">)</span><span class="w">
</span><span class="p" data-group-id="8187976307-6">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="8187976307-7">{</span><span class="nc">Cldr.UnknownLocaleError</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;No locale was identified for territory </span><span class="se">\&quot;</span><span class="s">com</span><span class="se">\&quot;</span><span class="s">&quot;</span><span class="p" data-group-id="8187976307-7">}</span><span class="p" data-group-id="8187976307-6">}</span></code></pre>
</section>
</section>
<section class="detail" id="new/1">
<div class="detail-header">
<a href="#new/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">new(locale_name)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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="new!/1">
<div class="detail-header">
<a href="#new!/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">new!(locale_name)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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="script_direction_from_locale/1">
<div class="detail-header">
<a href="#script_direction_from_locale/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">script_direction_from_locale(locale)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.37.0)</span>
</div>
<section class="docstring">
<p>Returns the script direction for a locale.</p><h2 id="script_direction_from_locale/1-arguments" class="section-heading">
<a href="#script_direction_from_locale/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">language_tag</code> is any language tag returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new/2"><code class="inline">Cldr.Locale.new/2</code></a>
or any <code class="inline">locale_name</code> returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>.</li></ul><h2 id="script_direction_from_locale/1-returns" class="section-heading">
<a href="#script_direction_from_locale/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li>The script direction which is either <code class="inline">:ltr</code> (for left-to-right
scripts) or <code class="inline">:rtl</code> (for right-to-left scripts).</li></ul><h2 id="script_direction_from_locale/1-examples" class="section-heading">
<a href="#script_direction_from_locale/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">script_direction_from_locale</span><span class="w"> </span><span class="s">&quot;en-US&quot;</span><span class="w">
</span><span class="ss">:ltr</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">script_direction_from_locale</span><span class="w"> </span><span class="ss">:ar</span><span class="w">
</span><span class="ss">:rtl</span></code></pre>
</section>
</section>
<section class="detail" id="territory_from_host/1">
<div class="detail-header">
<a href="#territory_from_host/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">territory_from_host(host)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.26.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> territory_from_host(<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()) ::
{:ok, <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:territory_code/0">Cldr.Locale.territory_code</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns the last segment of a host that might
be a territory.</p><h2 id="territory_from_host/1-arguments" class="section-heading">
<a href="#territory_from_host/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">host</code> is any valid host name</li></ul><h2 id="territory_from_host/1-returns" class="section-heading">
<a href="#territory_from_host/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p><code class="inline">{:ok, territory}</code> or</p></li><li><p><code class="inline">{:error, {exception, reason}}</code></p></li></ul><h2 id="territory_from_host/1-examples" class="section-heading">
<a href="#territory_from_host/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Cldr.Locale</span><span class="o">.</span><span class="n">territory_from_host</span><span class="p" data-group-id="0244033150-1">(</span><span class="s">&quot;a.b.com.au&quot;</span><span class="p" data-group-id="0244033150-1">)</span><span class="w">
</span><span class="p" data-group-id="0244033150-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="ss">:AU</span><span class="p" data-group-id="0244033150-2">}</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Cldr.Locale</span><span class="o">.</span><span class="n">territory_from_host</span><span class="p" data-group-id="0244033150-3">(</span><span class="s">&quot;a.b.com&quot;</span><span class="p" data-group-id="0244033150-3">)</span><span class="w">
</span><span class="p" data-group-id="0244033150-4">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
</span><span class="p" data-group-id="0244033150-5">{</span><span class="nc">Cldr.UnknownLocaleError</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;No locale was identified for territory </span><span class="se">\&quot;</span><span class="s">com</span><span class="se">\&quot;</span><span class="s">&quot;</span><span class="p" data-group-id="0244033150-5">}</span><span class="p" data-group-id="0244033150-4">}</span></code></pre>
</section>
</section>
<section class="detail" id="territory_from_locale/1">
<div class="detail-header">
<a href="#territory_from_locale/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">territory_from_locale(locale)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.18.2)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> territory_from_locale(<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>() | <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_name/0">Cldr.Locale.locale_name</a>()) ::
<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:territory_code/0">Cldr.Locale.territory_code</a>()</pre>
</div>
<p>Returns the territory from a language tag or
locale name.</p><h2 id="territory_from_locale/1-arguments" class="section-heading">
<a href="#territory_from_locale/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">locale</code> is any language tag returned by
<a href="#new/1"><code class="inline">Plausible.Cldr.Locale.new/1</code></a>
or a locale name in the list returned by
<a href="Plausible.Cldr.html#known_locale_names/0"><code class="inline">Plausible.Cldr.known_locale_names/0</code></a></li></ul><h2 id="territory_from_locale/1-returns" class="section-heading">
<a href="#territory_from_locale/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li>A territory code as an atom</li></ul><h2 id="territory_from_locale/1-examples" class="section-heading">
<a href="#territory_from_locale/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">territory_from_locale</span><span class="w"> </span><span class="s">&quot;en-US&quot;</span><span class="w">
</span><span class="ss">:US</span><span class="w">
</span><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">territory_from_locale</span><span class="w"> </span><span class="s">&quot;en-US-u-rg-GBzzzz&quot;</span><span class="w">
</span><span class="ss">:GB</span></code></pre>
</section>
</section>
<section class="detail" id="timezone_from_locale/1">
<div class="detail-header">
<a href="#timezone_from_locale/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">timezone_from_locale(locale)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" 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>
<span class="note">(since 2.19.0)</span>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> timezone_from_locale(<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>() | <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_name/0">Cldr.Locale.locale_name</a>()) ::
<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>() | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
</div>
<p>Returns the time zone from a language tag or
locale name.</p><h2 id="timezone_from_locale/1-arguments" class="section-heading">
<a href="#timezone_from_locale/1-arguments">
<i class="ri-link-m" aria-hidden="true"></i>
Arguments
</a>
</h2>
<ul><li><code class="inline">locale</code> is any language tag returned by
<a href="#new/1"><code class="inline">Plausible.Cldr.Locale.new/1</code></a>
or a locale name in the list returned by
<a href="Plausible.Cldr.html#known_locale_names/0"><code class="inline">Plausible.Cldr.known_locale_names/0</code></a></li></ul><h2 id="timezone_from_locale/1-returns" class="section-heading">
<a href="#timezone_from_locale/1-returns">
<i class="ri-link-m" aria-hidden="true"></i>
Returns
</a>
</h2>
<ul><li><p>A time zone ID as a string or</p></li><li><p><code class="inline">:error</code> if no time zone can be determined</p></li></ul><h2 id="timezone_from_locale/1-examples" class="section-heading">
<a href="#timezone_from_locale/1-examples">
<i class="ri-link-m" aria-hidden="true"></i>
Examples
</a>
</h2>
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex&gt; </span><span class="nc">Plausible.Cldr.Locale</span><span class="o">.</span><span class="n">timezone_from_locale</span><span class="w"> </span><span class="s">&quot;en-US-u-tz-ausyd&quot;</span><span class="w">
</span><span class="s">&quot;Australia/Sydney&quot;</span></code></pre>
</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="Plausible.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.30.3) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad: true})</script>
</body>
</html>