@@ -11,7 +11,8 @@ defmodule Trans do
1111 should take a look at this module**.
1212 * `Trans.QueryBuilder` - provides functions that can be chained in queries and
1313 allow filtering by translated values. **If you want to filter queries using
14- translated fields you should take a look at this module**.
14+ translated fields you should take a look at this module**. To use this module
15+ you must have `Ecto` among your dependencies.
1516
1617 ## What does this package do?
1718
@@ -91,17 +92,19 @@ defmodule Trans do
9192
9293 defp setup_convenience_functions ( defaults , translatables ) do
9394 quote do
94- # Wrapper of Trans.QueryBuilder.with_translations/3
95- def with_translations ( query , locale , opts \\ [ ] ) do
96- Trans.QueryBuilder . with_translations ( query , locale , opts ++ unquote ( defaults ) )
97- end
95+ if Code . ensure_compiled? ( Trans.QueryBuilder ) do
96+ # Wrapper of Trans.QueryBuilder.with_translations/3
97+ def with_translations ( query , locale , opts \\ [ ] ) do
98+ Trans.QueryBuilder . with_translations ( query , locale , opts ++ unquote ( defaults ) )
99+ end
98100
99- # Wrapper of Trans.QueryBuilder.with_translations
100- def with_translation ( query , locale , field , expected , opts \\ [ ] ) do
101- if not Enum . member? ( unquote ( translatables ) , field ) do
102- raise ArgumentError , "The field `#{ field } ` is not declared as translatable"
101+ # Wrapper of Trans.QueryBuilder.with_translations
102+ def with_translation ( query , locale , field , expected , opts \\ [ ] ) do
103+ if not Enum . member? ( unquote ( translatables ) , field ) do
104+ raise ArgumentError , "The field `#{ field } ` is not declared as translatable"
105+ end
106+ Trans.QueryBuilder . with_translation ( query , locale , field , expected , opts ++ unquote ( defaults ) )
103107 end
104- Trans.QueryBuilder . with_translation ( query , locale , field , expected , opts ++ unquote ( defaults ) )
105108 end
106109 end
107110 end
0 commit comments