Using hex linguist package in Phoenix Framework

时间:2015-07-08 15:41:05

标签: internationalization elixir 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?

2 个答案:

答案 0 :(得分:8)

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") %>

答案 1 :(得分:2)

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.