Skip to content

Commit cf78355

Browse files
committed
Merge branch 'releases/1.1.0'
2 parents 43018c0 + f381dda commit cf78355

File tree

6 files changed

+213
-200
lines changed

6 files changed

+213
-200
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
erl_crash.dump
55
*.ez
66
/doc
7+
8+
# Ignore test configuration.
9+
config/test.exs

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ gem for Ruby.
1212
`Trans` is published on [hex.pm](https://hex.pm/packages/trans) and the documentation
1313
is also [available online](https://hexdocs.pm/trans/).
1414

15-
## Requirements
15+
## Optional Requirements
16+
17+
Having Ecto and Postgrex in your application will allow you to use the `Trans.QueryBuilder`
18+
component to generate database queries based on translated data. You can still
19+
use the `Trans.Translator` component without those dependencies though.
1620

1721
- Ecto 2.0 or higher
1822
- PostgreSQL 9.4 or higher (since `Trans` leverages the JSONB datatype)
File renamed without changes.

lib/trans.ex

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)