Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hex linguist package in Phoenix Framework

How can I use the linguist package with Phoenix? I'm trying to have internationalization in a web page. I have added the package to mix.exs and ran mix deps.get with success.

Now, I don't know where in which folder to write the module file of the package as well as if it should be ex or exs in extension like the other country language file in the Usage case (fr.exs).

Also, after writing the module, how exactly would I apply it to my HTML tags?

like image 308
mesosteros Avatar asked Dec 24 '22 17:12

mesosteros


2 Answers

Quickly looking at the readme it seems you specify the path to the local file in the locale declaration when writing your I18n module. It's this line:

locale "fr", Path.join([__DIR__, "fr.exs"])

In this case it says "look into the current directory for a file named 'fr.exs'", but you can specify whatever you want, for example something like this:

locale "fr", Path.join(["lib", "translations", "fr.exs"])

Then in your views you just call the functions on the I18n module you defined, like the readme says:

<%=  I18n.t!("fr", "greeting") %>
like image 111
Paweł Obrok Avatar answered Dec 27 '22 05:12

Paweł Obrok


Have you looked at the sample code at the Linguist GitHub Page? You may also want to look at the phoenix_linguist github page as well.

like image 31
Onorio Catenacci Avatar answered Dec 27 '22 06:12

Onorio Catenacci