gettext icon indicating copy to clipboard operation
gettext copied to clipboard

Custom plural module depends on filesystem location

Open dkuku opened this issue 1 year ago • 4 comments

I've been debugging a simple issue too long, It may be more related to elixir compiler but as I found it in this project so I'm posting here. I created a plural module in /lib/myapp/gettext/plural.ex and referenced it from config. No matter what I did It ended up with :nofile error. I started to remove the nested namespaces. First I moved it to lib/myapp/plural.ex but no luck and then I created a minimal app with just gettext and plural in lib folder. It worked ok. So I moved it to lib in my app where it also worked ok!!!. Then I moved it back to lib/myapp/plural.ex removed the build folder and again it's not working.

20:48:48.018 [error] Task #PID<0.463.0> started from #PID<0.95.0> terminating
** (ArgumentError) could not load module Gtx.Plural due to reason :nofile
    (elixir 1.18.0) lib/code.ex:2005: Code.ensure_compiled!/1
    (gettext 0.26.2) lib/gettext/plural.ex:365: Gettext.Plural.plural_info/3
    (gettext 0.26.2) lib/gettext/merger.ex:301: Gettext.Merger.put_plural_forms_opt/3
    (gettext 0.26.2) lib/gettext/merger.ex:57: Gettext.Merger.merge/5
    (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:238: Mix.Tasks.Gettext.Merge.merge_files/5
    (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:206: anonymous fn/5 in Mix.Tasks.Gettext.Merge.merge_dirs/5
    (elixir 1.18.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.18.0) lib/task/supervised.ex:36: Task.Supervised.reply/4
Function: &:erlang.apply/2
    Args: [#Function<2.97866325/1 in Mix.Tasks.Gettext.Merge.merge_dirs/5>, ["priv/gettext/default.pot"]]

Minimal example repo - in this state it's failing for me with the error above.

Another terminal output where the plural.ex is in lib folder - here rerunning the mix gettext.extract fixed it somehow. But it was extracted previously so running it was not needed and the error points to missing Gtx.Plural module:

    ~/Projects/gtx    master !2 ?1  mix gettext.merge priv/gettext --locale=xx                                                     ✔ 
==> expo
Compiling 2 files (.erl)
Compiling 22 files (.ex)
Generated expo app
==> gettext
Compiling 18 files (.ex)
Generated gettext app

21:11:29.430 [error] Task #PID<0.463.0> started from #PID<0.95.0> terminating
** (ArgumentError) could not load module Gtx.Plural due to reason :nofile
    (elixir 1.18.0) lib/code.ex:2005: Code.ensure_compiled!/1
    (gettext 0.26.2) lib/gettext/plural.ex:365: Gettext.Plural.plural_info/3
    (gettext 0.26.2) lib/gettext/merger.ex:301: Gettext.Merger.put_plural_forms_opt/3
    (gettext 0.26.2) lib/gettext/merger.ex:222: Gettext.Merger.new_po_file/4
    (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:228: Mix.Tasks.Gettext.Merge.merge_or_create/5
    (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:206: anonymous fn/5 in Mix.Tasks.Gettext.Merge.merge_dirs/5
    (elixir 1.18.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.18.0) lib/task/supervised.ex:36: Task.Supervised.reply/4
Function: &:erlang.apply/2
    Args: [#Function<2.97866325/1 in Mix.Tasks.Gettext.Merge.merge_dirs/5>, ["priv/gettext/default.pot"]]
** (EXIT from #PID<0.95.0>) an exception was raised:
    ** (ArgumentError) could not load module Gtx.Plural due to reason :nofile
        (elixir 1.18.0) lib/code.ex:2005: Code.ensure_compiled!/1
        (gettext 0.26.2) lib/gettext/plural.ex:365: Gettext.Plural.plural_info/3
        (gettext 0.26.2) lib/gettext/merger.ex:301: Gettext.Merger.put_plural_forms_opt/3
        (gettext 0.26.2) lib/gettext/merger.ex:222: Gettext.Merger.new_po_file/4
        (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:228: Mix.Tasks.Gettext.Merge.merge_or_create/5
        (gettext 0.26.2) lib/mix/tasks/gettext.merge.ex:206: anonymous fn/5 in Mix.Tasks.Gettext.Merge.merge_dirs/5
        (elixir 1.18.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
        (elixir 1.18.0) lib/task/supervised.ex:36: Task.Supervised.reply/4

    ~/Projects/gtx    master !2 ?1  mix gettext.extract                                                                          1 ✘ 
Compiling 3 files (.ex)
Generated gtx app
    ~/Projects/gtx    master !2 ?1  mix gettext.merge priv/gettext --locale=xx                                                     ✔ 
Wrote priv/gettext/xx/LC_MESSAGES/default.po (1 new message, 0 removed, 0 unchanged, 0 reworded (fuzzy), 0 marked as obsolete)
    ~/Projects/gtx    master !1 ?1                                                                                    

dkuku avatar Dec 26 '24 20:12 dkuku

@dkuku Is your plural module defined inside your application or in a dependency?

We could have an issue with unmet dependencies if the plural module is defined in your application and needs to be present while compiling your application.

maennchen avatar Jan 07 '25 16:01 maennchen

Yes, it's in my app.

dkuku avatar Jan 07 '25 16:01 dkuku

Can you try if the problem persists if you put it into a separate app?

(Simply start a new mix project and install it in your application via {:my_app_name_plural, path: "path on your disk"})

maennchen avatar Jan 07 '25 16:01 maennchen

Tbh I did that and it works in this case. But it was after I created the issue. I created a package, since then no problems. https://hex.pm/packages/gettext_pseudolocalize

dkuku avatar Jan 07 '25 17:01 dkuku