-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
## `msgid`s in this file come from POT (.pot) files. Do not add, change, or | ||
## remove `msgid`s manually here as they're tied to the ones in the | ||
## corresponding POT file (with the same domain). Use `mix gettext.extract | ||
## --merge` or `mix gettext.merge` to merge POT files into PO files. | ||
msgid "" | ||
msgstr "" | ||
"Language: en\n" | ||
|
||
## From Ecto.Changeset.cast/4 | ||
msgid "can't be blank" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.put_change/3 | ||
msgid "is invalid" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_format/3 | ||
msgid "has invalid format" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_subset/3 | ||
msgid "has an invalid entry" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_exclusion/3 | ||
msgid "is reserved" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_confirmation/3 | ||
msgid "does not match confirmation" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.no_assoc_constraint/3 | ||
msgid "is still associated to this entry" | ||
msgstr "" | ||
|
||
msgid "are still associated to this entry" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_length/3 | ||
msgid "should be %{count} character(s)" | ||
msgid_plural "should be %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have %{count} item(s)" | ||
msgid_plural "should have %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should be at least %{count} character(s)" | ||
msgid_plural "should be at least %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have at least %{count} item(s)" | ||
msgid_plural "should have at least %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should be at most %{count} character(s)" | ||
msgid_plural "should be at most %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have at most %{count} item(s)" | ||
msgid_plural "should have at most %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
## From Ecto.Changeset.validate_number/3 | ||
msgid "must be less than %{count}" | ||
msgid_plural "must be less than %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be greater than %{count}" | ||
msgid_plural "must be greater than %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be less than or equal to %{count}" | ||
msgid_plural "must be less than or equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be greater than or equal to %{count}" | ||
msgid_plural "must be greater than or equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be equal to %{count}" | ||
msgid_plural "must be equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
## This file is a PO Template file. `msgid`s here are often extracted from | ||
## source code; add new translations manually only if they're dynamic | ||
## translations that can't be statically extracted. Run `mix | ||
## gettext.extract` to bring this file up to date. Leave `msgstr`s empty as | ||
## changing them here as no effect; edit them in PO (`.po`) files instead. | ||
## From Ecto.Changeset.cast/4 | ||
msgid "can't be blank" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.put_change/3 | ||
msgid "is invalid" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_format/3 | ||
msgid "has invalid format" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_subset/3 | ||
msgid "has an invalid entry" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_exclusion/3 | ||
msgid "is reserved" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_confirmation/3 | ||
msgid "does not match confirmation" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.no_assoc_constraint/3 | ||
msgid "is still associated to this entry" | ||
msgstr "" | ||
|
||
msgid "are still associated to this entry" | ||
msgstr "" | ||
|
||
## From Ecto.Changeset.validate_length/3 | ||
msgid "should be %{count} character(s)" | ||
msgid_plural "should be %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have %{count} item(s)" | ||
msgid_plural "should have %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should be at least %{count} character(s)" | ||
msgid_plural "should be at least %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have at least %{count} item(s)" | ||
msgid_plural "should have at least %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should be at most %{count} character(s)" | ||
msgid_plural "should be at most %{count} character(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "should have at most %{count} item(s)" | ||
msgid_plural "should have at most %{count} item(s)" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
## From Ecto.Changeset.validate_number/3 | ||
msgid "must be less than %{count}" | ||
msgid_plural "must be less than %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be greater than %{count}" | ||
msgid_plural "must be greater than %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be less than or equal to %{count}" | ||
msgid_plural "must be less than or equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be greater than or equal to %{count}" | ||
msgid_plural "must be greater than or equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgid "must be equal to %{count}" | ||
msgid_plural "must be equal to %{count}" | ||
msgstr[0] "" | ||
msgstr[1] "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule ElixirStatus.Gettext do | ||
@moduledoc """ | ||
A module providing Internationalization with a gettext-based API. | ||
By using [Gettext](http://hexdocs.pm/gettext), | ||
your module gains a set of macros for translations, for example: | ||
import ElixirStatus.Gettext | ||
# Simple translation | ||
gettext "Here is the string to translate" | ||
# Plural translation | ||
ngettext "Here is the string to translate", | ||
"Here are the strings to translate", | ||
3 | ||
# Domain-based translation | ||
dgettext "errors", "Here is the error message to translate" | ||
See the [Gettext Docs](http://hexdocs.pm/gettext) for detailed usage. | ||
""" | ||
use Gettext, otp_app: :elixir_status | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule ElixirStatus.ChangesetView do | ||
use ElixirStatus.Web, :view | ||
|
||
@doc """ | ||
Traverses and translates changeset errors. | ||
See `Ecto.Changeset.traverse_errors/2` and | ||
`ElixirStatus.ErrorHelpers.translate_error/1` for more details. | ||
""" | ||
def translate_errors(changeset) do | ||
Ecto.Changeset.traverse_errors(changeset, &translate_error/1) | ||
end | ||
|
||
def render("error.json", %{changeset: changeset}) do | ||
# When encoded, the changeset returns its errors | ||
# as a JSON object. So we just pass it forward. | ||
%{errors: translate_errors(changeset)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule ElixirStatus.ErrorHelpers do | ||
@moduledoc """ | ||
Conveniences for translating and building error messages. | ||
""" | ||
use Phoenix.HTML | ||
|
||
@doc """ | ||
Generates tag for inlined form input errors. | ||
""" | ||
def error_tag(form, field) do | ||
if error = form.errors[field] do | ||
content_tag :span, translate_error(error), class: "help-block" | ||
end | ||
end | ||
|
||
@doc """ | ||
Translates an error message using gettext. | ||
""" | ||
def translate_error({msg, opts}) do | ||
# Because error messages were defined within Ecto, we must | ||
# call the Gettext module passing our Gettext backend. We | ||
# also use the "errors" domain as translations are placed | ||
# in the errors.po file. On your own code and templates, | ||
# this could be written simply as: | ||
# | ||
# dngettext "errors", "1 file", "%{count} files", count | ||
# | ||
Gettext.dngettext(ElixirStatus.Gettext, "errors", msg, msg, opts[:count], opts) | ||
end | ||
|
||
def translate_error(msg) do | ||
Gettext.dgettext(ElixirStatus.Gettext, "errors", msg) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters