Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,39 +190,23 @@ You can change which corner the toasts are anchored to by passing the `corner` s

### Internationalization

You can provide translations for the defaul error toasts by adding the following to your `config.exs`:
You can provide translations for the default error toasts by adding the following to your `config.exs`:

```elixir
config :live_toast,
gettext_backend: MyApp.Gettext
```

You have to create a `live_toast.po` file, inside the `priv/gettext/<language>/LC_MESSAGES/` folder for each language you want to support.
Copy the provided template and translations:

For example, if you want to support spanish, you would create the file `live_toast.po` in the `priv/gettext/es/LC_MESSAGES/` folder, with the following content:

```po
msgid ""
msgstr ""
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "We can't find the internet"
msgstr "Nosotros no podemos encontrar internet"

msgid "Attempting to reconnect"
msgstr "Intentando reconectar"

msgid "Something went wrong!"
msgstr "¡Algo salió mal!"

msgid "Hang in there while we get back on track"
msgstr "Aguanta mientras volvemos a la normalidad"
```sh
cp -rv deps/live_toast/i18n/gettext/* priv/gettext
# optionally create missing (empty) translation files (.po) based on the template (.pot):
mix gettext.extract --merge
```

You have to provide a `live_toast.po` file, inside the `priv/gettext/<language>/LC_MESSAGES/` folder for each language you want to support.

### Function Options

[`send_toast`](https://hexdocs.pm/live_toast/LiveToast.html#send_toast/3) takes a number of arguments to control it's behavior. They are currently:
Expand Down
33 changes: 33 additions & 0 deletions i18n/gettext/de/LC_MESSAGES/live_toast.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## "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: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Info"
msgstr "Info"

msgid "Error"
msgstr "Fehler"

msgid "We can't find the internet"
msgstr "Keine Internet-Verbindung"

msgid "Attempting to reconnect"
msgstr "Verbindung wird wiederhergestellt"

msgid "Something went wrong!"
msgstr "Etwas ist schiefgelaufen!"

msgid "Hang in there while we get back on track"
msgstr "Bitte warten Sie, während wir das Problem beheben"
33 changes: 33 additions & 0 deletions i18n/gettext/es/LC_MESSAGES/live_toast.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## "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: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Info"
msgstr "Información"

msgid "Error"
msgstr "Error"

msgid "We can't find the internet"
msgstr "Nosotros no podemos encontrar internet"

msgid "Attempting to reconnect"
msgstr "Intentando reconectar"

msgid "Something went wrong!"
msgstr "¡Algo salió mal!"

msgid "Hang in there while we get back on track"
msgstr "Aguanta mientras volvemos a la normalidad"
30 changes: 30 additions & 0 deletions i18n/gettext/live_toast.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## This file is a PO Template file.
##
## "msgid"s here are often extracted from source code.
## Add new messages manually only if they're dynamic
## messages 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 has no
## effect: edit them in PO (.po) files instead.
#
msgid ""
msgstr ""

msgid "Info"
msgstr ""

msgid "Error"
msgstr ""

msgid "We can't find the internet"
msgstr ""

msgid "Attempting to reconnect"
msgstr ""

msgid "Something went wrong!"
msgstr ""

msgid "Hang in there while we get back on track"
msgstr ""
2 changes: 1 addition & 1 deletion lib/live_toast/components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ defmodule LiveToast.Components do
flash_duration={@flash_duration}
duration={0}
kind={level}
title={String.capitalize(to_string(level))}
title={Utility.translate(String.capitalize(to_string(level)))}
phx-update="ignore"
flash={@f}
/>
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ defmodule LiveToast.MixProject do
mix.exs
package.json
README.md
i18n
"""
end

Expand Down