forked from shibao/cannery
improve locale
This commit is contained in:
parent
8dd471afa8
commit
5b6bd00047
@ -15,17 +15,18 @@ end
|
|||||||
config :cannery, CanneryWeb.ViewHelpers, shibao_mode: System.get_env("SHIBAO_MODE") == "true"
|
config :cannery, CanneryWeb.ViewHelpers, shibao_mode: System.get_env("SHIBAO_MODE") == "true"
|
||||||
|
|
||||||
# Set default locale
|
# Set default locale
|
||||||
config :gettext, :default_locale, System.get_env("LOCALE") || "en_US"
|
config :gettext, :default_locale, System.get_env("LOCALE", "en_US")
|
||||||
|
|
||||||
maybe_ipv6 = if System.get_env("ECTO_IPV6") == "true", do: [:inet6], else: []
|
maybe_ipv6 = if System.get_env("ECTO_IPV6") == "true", do: [:inet6], else: []
|
||||||
|
|
||||||
database_url =
|
database_url =
|
||||||
if config_env() == :test do
|
if config_env() == :test do
|
||||||
System.get_env("TEST_DATABASE_URL") ||
|
System.get_env(
|
||||||
|
"TEST_DATABASE_URL",
|
||||||
"ecto://postgres:postgres@localhost/cannery_test#{System.get_env("MIX_TEST_PARTITION")}"
|
"ecto://postgres:postgres@localhost/cannery_test#{System.get_env("MIX_TEST_PARTITION")}"
|
||||||
|
)
|
||||||
else
|
else
|
||||||
System.get_env("DATABASE_URL") ||
|
System.get_env("DATABASE_URL", "ecto://postgres:postgres@cannery-db/cannery")
|
||||||
"ecto://postgres:postgres@cannery-db/cannery"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
host =
|
host =
|
||||||
@ -40,7 +41,7 @@ interface =
|
|||||||
config :cannery, Cannery.Repo,
|
config :cannery, Cannery.Repo,
|
||||||
# ssl: true,
|
# ssl: true,
|
||||||
url: database_url,
|
url: database_url,
|
||||||
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
|
pool_size: String.to_integer(System.get_env("POOL_SIZE", "10")),
|
||||||
socket_options: maybe_ipv6
|
socket_options: maybe_ipv6
|
||||||
|
|
||||||
config :cannery, CanneryWeb.Endpoint,
|
config :cannery, CanneryWeb.Endpoint,
|
||||||
@ -49,10 +50,10 @@ config :cannery, CanneryWeb.Endpoint,
|
|||||||
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
|
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
|
||||||
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
|
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
|
||||||
ip: interface,
|
ip: interface,
|
||||||
port: String.to_integer(System.get_env("PORT") || "4000")
|
port: String.to_integer(System.get_env("PORT", "4000"))
|
||||||
],
|
],
|
||||||
server: true,
|
server: true,
|
||||||
registration: System.get_env("REGISTRATION") || "invite"
|
registration: System.get_env("REGISTRATION", "invite")
|
||||||
|
|
||||||
if config_env() == :prod do
|
if config_env() == :prod do
|
||||||
# The secret key base is used to sign/encrypt cookies and other secrets.
|
# The secret key base is used to sign/encrypt cookies and other secrets.
|
||||||
@ -76,12 +77,12 @@ if config_env() == :prod do
|
|||||||
config :cannery, Cannery.Mailer,
|
config :cannery, Cannery.Mailer,
|
||||||
adapter: Swoosh.Adapters.SMTP,
|
adapter: Swoosh.Adapters.SMTP,
|
||||||
relay: System.get_env("SMTP_HOST") || raise("No SMTP_HOST set!"),
|
relay: System.get_env("SMTP_HOST") || raise("No SMTP_HOST set!"),
|
||||||
port: System.get_env("SMTP_PORT") || 587,
|
port: System.get_env("SMTP_PORT", 587),
|
||||||
username: System.get_env("SMTP_USERNAME") || raise("No SMTP_USERNAME set!"),
|
username: System.get_env("SMTP_USERNAME") || raise("No SMTP_USERNAME set!"),
|
||||||
password: System.get_env("SMTP_PASSWORD") || raise("No SMTP_PASSWORD set!"),
|
password: System.get_env("SMTP_PASSWORD") || raise("No SMTP_PASSWORD set!"),
|
||||||
ssl: System.get_env("SMTP_SSL") == "true",
|
ssl: System.get_env("SMTP_SSL") == "true",
|
||||||
email_from: System.get_env("EMAIL_FROM") || "no-reply@#{System.get_env("HOST")}",
|
email_from: System.get_env("EMAIL_FROM", "no-reply@#{System.get_env("HOST")}"),
|
||||||
email_name: System.get_env("EMAIL_NAME") || "Cannery"
|
email_name: System.get_env("EMAIL_NAME", "Cannery")
|
||||||
|
|
||||||
# ## Using releases
|
# ## Using releases
|
||||||
#
|
#
|
||||||
|
@ -11,15 +11,17 @@ defmodule CanneryWeb.Router do
|
|||||||
plug :protect_from_forgery
|
plug :protect_from_forgery
|
||||||
plug :put_secure_browser_headers
|
plug :put_secure_browser_headers
|
||||||
plug :fetch_current_user
|
plug :fetch_current_user
|
||||||
plug :put_user_locale, default: Application.compile_env(:gettext, :default_locale, "en_US")
|
plug :put_user_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, default: default) do
|
defp put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, _opts) do
|
||||||
|
default = Application.fetch_env!(:gettext, :default_locale)
|
||||||
Gettext.put_locale(locale || default)
|
Gettext.put_locale(locale || default)
|
||||||
conn |> put_session(:locale, locale || default)
|
conn |> put_session(:locale, locale || default)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_user_locale(conn, default: default) do
|
defp put_user_locale(conn, _opts) do
|
||||||
|
default = Application.fetch_env!(:gettext, :default_locale)
|
||||||
Gettext.put_locale(default)
|
Gettext.put_locale(default)
|
||||||
conn |> put_session(:locale, default)
|
conn |> put_session(:locale, default)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user