diff --git a/README.md b/README.md index 4942c86..65c1c82 100644 --- a/README.md +++ b/README.md @@ -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//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//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: diff --git a/i18n/gettext/de/LC_MESSAGES/live_toast.po b/i18n/gettext/de/LC_MESSAGES/live_toast.po new file mode 100644 index 0000000..45228a8 --- /dev/null +++ b/i18n/gettext/de/LC_MESSAGES/live_toast.po @@ -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" diff --git a/i18n/gettext/es/LC_MESSAGES/live_toast.po b/i18n/gettext/es/LC_MESSAGES/live_toast.po new file mode 100644 index 0000000..62811dc --- /dev/null +++ b/i18n/gettext/es/LC_MESSAGES/live_toast.po @@ -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" diff --git a/i18n/gettext/live_toast.pot b/i18n/gettext/live_toast.pot new file mode 100644 index 0000000..b82bf44 --- /dev/null +++ b/i18n/gettext/live_toast.pot @@ -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 "" diff --git a/lib/live_toast/components.ex b/lib/live_toast/components.ex index 2755327..ac2b138 100644 --- a/lib/live_toast/components.ex +++ b/lib/live_toast/components.ex @@ -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} /> diff --git a/mix.exs b/mix.exs index 42828ad..2f35cc6 100644 --- a/mix.exs +++ b/mix.exs @@ -80,6 +80,7 @@ defmodule LiveToast.MixProject do mix.exs package.json README.md + i18n """ end