sfusato

sfusato

How to organize Gettext .pot files in sub-folders?

I’m using Gettext’s dgettext(domain, msgid) function to organize my translation files (referred to as “domains” in the documentation).

I want to go further and also organize the domain files into sub-folders.

Using dgettext("path/domain", msgid) does create gettext/path/domain.pot. It doesn’t create the file in gettext/en/LC_MESSAGES/path/domain.pot or in any of the other locales and also gives this error:

18:35:43.237 [error] Task #PID<0.433.0> started from #PID<0.88.0> terminating
** (Gettext.Plural.UnknownLocaleError) unknown locale "path". If this is a locale you need to handle,
consider using a custom pluralizer module instead of the default
Gettext.Plural. You can read more about this on the Gettext docs at
https://hexdocs.pm/gettext/Gettext.Plural.html

    (gettext) lib/gettext/plural.ex:658: Gettext.Plural.recall_if_country_or_raise/2
    (elixir) lib/keyword.ex:603: Keyword.put_new_lazy/3
    (gettext) lib/gettext/merger.ex:163: Gettext.Merger.new_po_file/5
    (gettext) lib/mix/tasks/gettext.merge.ex:184: anonymous fn/5 in Mix.Tasks.Gettext.Merge.merge_dirs/5
    (elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:38: Task.Supervised.reply/5

    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: &:erlang.apply/2
    Args: [#Function<2.80905071/1 in Mix.Tasks.Gettext.Merge.merge_dirs/5>, ["priv/gettext/default.pot"]]

I have a mix task that I run when generating .pot files:
translate: ["gettext.extract", "gettext.merge priv/gettext"]

So, is it possible to organize .pot files in sub-folders as I’m trying to do ?

Marked As Solved

A-Legg

A-Legg

@sfusato Yes it is possible. For example you can house a .pot file in priv/gettext/foo/bar.pot and the .po files in priv/gettext/foo/locale/LC_messages/bar.po and then exact and merge via mix gettext.extract && mix gettext.merge priv/gettext/foo using dgettext("foo/bar", "string to translate").

Here is an example repo where the translated strings are in lib/gettext_example_web/controllers/page_controller.ex:
https://github.com/A-Legg/gettext_example

Personally I would probably just get creative with my domain naming and keep the default file structure. nav_sidebar in your case, for example.

Also Liked

A-Legg

A-Legg

It looks like the error you’re seeing is due to path being in the directory in place of a valid locale. By default you should house the .pot file in priv/gettext/domain.pot and the .po files in priv/gettext/locale/LC_MESSAGES/domain.po.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement