Skip to content

Commit d1a8c86

Browse files
committed
Release v1.0.0
1 parent e1df334 commit d1a8c86

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

CHANGELOG.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# Changelog
22

3+
## v1.0.0
4+
5+
This is the first 1.0 release of Gettext, a silly 10 years (and 6 months) after we started working on it. There are *very few changes* from the latest 0.26 release, and none of them are breaking.
6+
7+
Here are the new goodies:
8+
9+
* Add support for concatenating sigils if all parts are known at compile time (such as `"Hello " <> ~s(world)`).
10+
* Significantly increase the timeout for `mix gettext.extract` to two minutes.
11+
* Add `Gettext.put_locale!/1`.
12+
13+
Happy 10+ years of Elixir translations everyone! 🎉
14+
315
## v0.26.2
416

5-
* Introduces warning if plural messages are defined with the same singular
6-
message and conflicting plural messages.
7-
* Improves performance by striping not required metadata when compiling the
8-
Gettext backend.
17+
* Introduces warning if plural messages are defined with the same singular
18+
message and conflicting plural messages.
19+
* Improves performance by striping not required metadata when compiling the
20+
Gettext backend.
921

1022
## v0.26.1
1123

lib/gettext.ex

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,20 @@ defmodule Gettext do
700700
end
701701

702702
@doc """
703-
Sets the global Gettext locale for the current process.
703+
Sets the **global** Gettext locale for the current process.
704704
705705
The locale is stored in the process dictionary. `locale` must be a string; if
706706
it's not, an `ArgumentError` exception is raised.
707707
708708
The return value is the previous value of the current
709709
process's locale.
710710
711+
> #### Unknown Locales {: .warning}
712+
>
713+
> Since this function sets the *global* locale, it cannot check whether that
714+
> local is supported against a particular backend. For that, use `put_locale/2`
715+
> or `put_locale!/2`.
716+
711717
## Examples
712718
713719
Gettext.put_locale("pt_BR")
@@ -765,9 +771,7 @@ defmodule Gettext do
765771
766772
The current process's locale will change even if the passed `locale` is not
767773
supported. If you think this can cause an issue consider using `known_locales/1`
768-
to handle unsupported locales.
769-
770-
## Example
774+
to handle unsupported locales:
771775
772776
# Handle unsupported locales based on your requirements
773777
defp handle_locale(locale, true, backend), do: {:ok, Process.put(backend, locale)}
@@ -776,6 +780,8 @@ defmodule Gettext do
776780
# In your main function
777781
is_in_allowed_locale = locale in known_locales(backend)
778782
handle_locale(locale, is_in_allowed_locale, backend)
783+
784+
Alternatively, use `put_locale!/2` which raises if the locale is not supported.
779785
"""
780786
@doc section: :locale
781787
@spec put_locale(backend, locale) :: locale | nil
@@ -785,15 +791,31 @@ defmodule Gettext do
785791
do: raise(ArgumentError, "put_locale/2 only accepts binary locales, got: #{inspect(locale)}")
786792

787793
@doc """
788-
Similar to `put_locale/2`, but it raises an error if the passed locale doesn't exist in the known_locales.
794+
Like `put_locale/2`, but it raises an error if the passed locale doesn't exist in the known locales.
795+
796+
## Examples
797+
798+
Gettext.put_locale(MyApp.Gettext, "pt_BR")
799+
#=> nil
800+
Gettext.get_locale(MyApp.Gettext)
801+
#=> "pt_BR"
802+
789803
"""
790804
@doc section: :locale
805+
@doc since: "1.0.0"
791806
@spec put_locale!(backend, locale) :: locale | nil
792-
def put_locale!(backend, locale) when is_binary(locale),
793-
do: put_locale_with_fallback(backend, locale)
807+
def put_locale!(backend, locale) when is_binary(locale) do
808+
cond do
809+
not is_binary(locale) ->
810+
raise ArgumentError, "put_locale/2 only accepts binary locales, got: #{inspect(locale)}"
794811

795-
def put_locale!(_backend, locale),
796-
do: raise(ArgumentError, "put_locale/2 only accepts binary locales, got: #{inspect(locale)}")
812+
locale in known_locales(backend) ->
813+
put_locale(backend, locale)
814+
815+
true ->
816+
raise ArgumentError, "put_locale!/2 only support known locales, got: #{inspect(locale)}"
817+
end
818+
end
797819

798820
@doc """
799821
Returns the message of the given string with a given context in the given domain.
@@ -1178,18 +1200,4 @@ defmodule Gettext do
11781200

11791201
defp domain_or_default(backend, :default), do: backend.__gettext__(:default_domain)
11801202
defp domain_or_default(_backend, domain) when is_binary(domain), do: domain
1181-
1182-
@spec put_locale_with_fallback(backend, locale) :: binary() | nil
1183-
defp put_locale_with_fallback(backend, locale) do
1184-
allowed_locales = known_locales(backend)
1185-
is_allowed_locale = locale in allowed_locales
1186-
1187-
case is_allowed_locale do
1188-
true ->
1189-
put_locale(backend, locale)
1190-
1191-
false ->
1192-
raise(ArgumentError, "put_locale!/2 only support known locales, got: #{inspect(locale)}")
1193-
end
1194-
end
11951203
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Gettext.Mixfile do
22
use Mix.Project
33

4-
@version "0.26.2"
4+
@version "1.0.0"
55

66
@description "Internationalization and localization through gettext"
77
@repo_url "https://github.com/elixir-gettext/gettext"

0 commit comments

Comments
 (0)