Skip to content

Commit

Permalink
feat: rename PlugLocale.WebBrowser to PlugLocale.Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
c4710n committed Dec 30, 2023
1 parent c02d394 commit 8b5b69f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Breaking changes:

- rename `:sanitize_locale_by` option `:cast_locale_by`
- rename `PlugLocale.WebBrowser.build_localized_path` to `PlugLocale.WebBrowser.build_locale_path`
- rename `PlugLocale.WebBrowser` to `PlugLocale.Browser`

New Features:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Different from [`set_locale`](https://hex.pm/packages/set_locale), [`ex_cldr_plu
- only does one simple thing - setting a locale-related assign (by default, it is `conn.assigns.locale`).
- does not make any assumptions about the localization strategy, so it is not tightly bound to packages like [`gettext`](https://hex.pm/packages/gettext) or [`ex_cldr`](https://hex.pm/packages/ex_cldr).

Check out `PlugLocale.WebBrowser`, `PlugLocale.Header` in [documentation](https://hexdocs.pm/plug_locale) for more details.
Check out `PlugLocale.Browser`, `PlugLocale.Header` in [documentation](https://hexdocs.pm/plug_locale) for more details.

## Thanks

Expand Down
12 changes: 6 additions & 6 deletions lib/plug_locale/web_browser.ex → lib/plug_locale/browser.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PlugLocale.WebBrowser do
defmodule PlugLocale.Browser do
@moduledoc """
Puts locale into `assigns` storage for Web browser environment.
Expand Down Expand Up @@ -28,10 +28,10 @@ defmodule PlugLocale.WebBrowser do
is useless. All you need is to construct a plug pipeline through
`Plug.Builder`. For example:
defmodule DemoWeb.PlugWebBrowserLocalization do
defmodule DemoWeb.PlugBrowserLocalization do
use Plug.Builder
plug PlugLocale.WebBrowser,
plug PlugLocale.Browser,
default_locale: "en",
locales: ["en", "zh"],
route_identifier: :locale,
Expand Down Expand Up @@ -60,7 +60,7 @@ defmodule PlugLocale.WebBrowser do
# ...
plug DemoWeb.PlugWebBrowserLocalization
plug DemoWeb.PlugBrowserLocalization
# ...
end
Expand Down Expand Up @@ -156,15 +156,15 @@ defmodule PlugLocale.WebBrowser do
<ul>
<li>
<a
href={PlugLocale.WebBrowser.build_locale_path(@conn, "en")}
href={PlugLocale.Browser.build_locale_path(@conn, "en")}
aria-label="switch to locale - en"
>
English
</a>
</li>
<li>
<a
href={PlugLocale.WebBrowser.build_locale_path(@conn, "zh")}
href={PlugLocale.Browser.build_locale_path(@conn, "zh")}
aria-label="switch to locale - zh"
>
中文
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PlugLocale.WebBrowser.AcceptLanguage do
defmodule PlugLocale.Browser.AcceptLanguage do
@moduledoc false

def extract_locales(line) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PlugLocale.WebBrowser.Config do
defmodule PlugLocale.Browser.Config do
@moduledoc false

@opts_schema [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule PlugLocale.WebBrowser.AcceptLanguageTest do
defmodule PlugLocale.Browser.AcceptLanguageTest do
use ExUnit.Case, async: true
alias PlugLocale.WebBrowser.AcceptLanguage
alias PlugLocale.Browser.AcceptLanguage

describe "extract_locales/1" do
test "works for normal languages" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PlugLocale.WebBrowserTest do
defmodule PlugLocale.BrowserTest do
use ExUnit.Case, async: true
use Plug.Test
import ExUnit.CaptureLog
Expand All @@ -11,7 +11,7 @@ defmodule PlugLocale.WebBrowserTest do
plug Plug.Parsers,
parsers: [:urlencoded]

plug PlugLocale.WebBrowser,
plug PlugLocale.Browser,
default_locale: "en",
locales: ["en", "zh-Hans"],
detect_locale_from: [:query, :cookie, :referrer, :accept_language]
Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule PlugLocale.WebBrowserTest do

plug :match

plug PlugLocale.WebBrowser,
plug PlugLocale.Browser,
default_locale: "en",
locales: ["en", "zh-Hans"],
detect_locale_from: [:query, :cookie, :referrer, :accept_language]
Expand Down Expand Up @@ -67,7 +67,7 @@ defmodule PlugLocale.WebBrowserTest do

plug :match

plug PlugLocale.WebBrowser,
plug PlugLocale.Browser,
default_locale: "en",
locales: ["en", "zh-Hans"],
detect_locale_from: [:query, :cookie, :referrer, :accept_language]
Expand All @@ -78,7 +78,7 @@ defmodule PlugLocale.WebBrowserTest do

def put_cookie(conn, _opts) do
if locale = conn.assigns[:locale] do
PlugLocale.WebBrowser.put_locale_resp_cookie(conn, locale, max_age: 3600)
PlugLocale.Browser.put_locale_resp_cookie(conn, locale, max_age: 3600)
else
conn
end
Expand Down Expand Up @@ -227,7 +227,7 @@ defmodule PlugLocale.WebBrowserTest do
test "build_locale_path/2" do
conn = conn(:get, "/en/posts/7")
conn = DemoRouter.call(conn, @opts)
assert "/zh-Hans/posts/7" == PlugLocale.WebBrowser.build_locale_path(conn, "zh-Hans")
assert "/zh-Hans/posts/7" == PlugLocale.Browser.build_locale_path(conn, "zh-Hans")
end

test "put_locale_resp_cookie/2" do
Expand Down

0 comments on commit 8b5b69f

Please sign in to comment.