@@ -598,6 +598,16 @@ defmodule Gettext do
598
598
@ type backend :: module
599
599
@ type bindings :: map ( ) | Keyword . t ( )
600
600
601
+ @ typedoc """
602
+ A Gettext domain.
603
+
604
+ See [*Domains*](#module-domains) in the module documentation for more information.
605
+ """
606
+ @ typedoc since: "0.26.0"
607
+ @ type domain ( ) :: :default | binary ( )
608
+
609
+ defguardp is_domain ( domain ) when domain == :default or is_binary ( domain )
610
+
601
611
@ doc false
602
612
defmacro __using__ ( opts ) do
603
613
opts =
@@ -775,15 +785,16 @@ defmodule Gettext do
775
785
776
786
"""
777
787
@ doc section: :translation
778
- @ spec dpgettext ( module , binary , binary | nil , binary , bindings ) :: binary
788
+ @ spec dpgettext ( module , domain , binary | nil , binary , bindings ) :: binary
779
789
def dpgettext ( backend , domain , msgctxt , msgid , bindings \\ % { } )
780
790
781
791
def dpgettext ( backend , domain , msgctxt , msgid , bindings ) when is_list ( bindings ) do
782
792
dpgettext ( backend , domain , msgctxt , msgid , Map . new ( bindings ) )
783
793
end
784
794
785
795
def dpgettext ( backend , domain , msgctxt , msgid , bindings )
786
- when is_atom ( backend ) and is_binary ( domain ) and is_binary ( msgid ) and is_map ( bindings ) do
796
+ when is_atom ( backend ) and is_domain ( domain ) and is_binary ( msgid ) and is_map ( bindings ) do
797
+ domain = domain_or_default ( backend , domain )
787
798
locale = get_locale ( backend )
788
799
result = backend . lgettext ( locale , domain , msgctxt , msgid , bindings )
789
800
handle_backend_result ( result , backend , locale , domain , msgctxt , msgid )
@@ -820,7 +831,7 @@ defmodule Gettext do
820
831
821
832
"""
822
833
@ doc section: :translation
823
- @ spec dgettext ( module , binary , binary , bindings ) :: binary
834
+ @ spec dgettext ( module , domain , binary , bindings ) :: binary
824
835
def dgettext ( backend , domain , msgid , bindings \\ % { } ) do
825
836
dpgettext ( backend , domain , nil , msgid , bindings )
826
837
end
@@ -900,7 +911,7 @@ defmodule Gettext do
900
911
901
912
"""
902
913
@ doc section: :translation
903
- @ spec dpngettext ( module , binary , binary | nil , binary , binary , non_neg_integer , bindings ) ::
914
+ @ spec dpngettext ( module , domain , binary | nil , binary , binary , non_neg_integer , bindings ) ::
904
915
binary
905
916
def dpngettext ( backend , domain , msgctxt , msgid , msgid_plural , n , bindings \\ % { } )
906
917
@@ -910,8 +921,9 @@ defmodule Gettext do
910
921
end
911
922
912
923
def dpngettext ( backend , domain , msgctxt , msgid , msgid_plural , n , bindings )
913
- when is_atom ( backend ) and is_binary ( domain ) and is_binary ( msgid ) and is_binary ( msgid_plural ) and
924
+ when is_atom ( backend ) and is_domain ( domain ) and is_binary ( msgid ) and is_binary ( msgid_plural ) and
914
925
is_integer ( n ) and n >= 0 and is_map ( bindings ) do
926
+ domain = domain_or_default ( backend , domain )
915
927
locale = get_locale ( backend )
916
928
result = backend . lngettext ( locale , domain , msgctxt , msgid , msgid_plural , n , bindings )
917
929
handle_backend_result ( result , backend , locale , domain , msgctxt , msgid )
@@ -943,7 +955,7 @@ defmodule Gettext do
943
955
944
956
"""
945
957
@ doc section: :translation
946
- @ spec dngettext ( module , binary , binary , binary , non_neg_integer , bindings ) :: binary
958
+ @ spec dngettext ( module , domain , binary , binary , non_neg_integer , bindings ) :: binary
947
959
def dngettext ( backend , domain , msgid , msgid_plural , n , bindings \\ % { } ) ,
948
960
do: dpngettext ( backend , domain , nil , msgid , msgid_plural , n , bindings )
949
961
@@ -1125,4 +1137,7 @@ defmodule Gettext do
1125
1137
1126
1138
backend . handle_missing_bindings ( exception , incomplete )
1127
1139
end
1140
+
1141
+ defp domain_or_default ( backend , :default ) , do: backend . __gettext__ ( :default_domain )
1142
+ defp domain_or_default ( _backend , domain ) when is_binary ( domain ) , do: domain
1128
1143
end
0 commit comments