elixir-gettext / gettext

Internationalization and localization support for Elixir.
https://hexdocs.pm/gettext
469 stars 86 forks source link

Fix extractor crash in case of conflicting backends #352

Closed benoawfu closed 1 year ago

benoawfu commented 1 year ago

I have in the same app 2 gettext backends, each one having its own domain. I want both backend translation files to live in the same usual priv/gettext folder: the different domain name ensures they will not overwrite each other.

When extracting translations the warn_on_conflicting_backends/1 function issues a warning about that case but then it also crashes:

warning: the Gettext backend Blog.Gettext has the same :priv directory as Marketplace.Gettext, which means they will override each other. Please set the :priv option to different directories or use Gettext inside each backend
  (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
  (gettext 0.22.0) lib/gettext/extractor.ex:103: Gettext.Extractor.pot_files/2
  (gettext 0.22.0) lib/mix/tasks/gettext.extract.ex:109: Mix.Tasks.Gettext.Extract.extract/2
  (gettext 0.22.0) lib/mix/tasks/gettext.extract.ex:68: Mix.Tasks.Gettext.Extract.run/1
  (mix 1.14.3) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
  (mix 1.14.3) lib/mix/project.ex:397: Mix.Project.in_project/4

** (CaseClauseError) no case clause matching: :ok
    (gettext 0.22.0) lib/gettext/extractor.ex:116: anonymous fn/2 in Gettext.Extractor.warn_on_conflicting_backends/1
    (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (gettext 0.22.0) lib/gettext/extractor.ex:103: Gettext.Extractor.pot_files/2
    (gettext 0.22.0) lib/mix/tasks/gettext.extract.ex:109: Mix.Tasks.Gettext.Extract.extract/2
    (gettext 0.22.0) lib/mix/tasks/gettext.extract.ex:68: Mix.Tasks.Gettext.Extract.run/1
    (mix 1.14.3) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
    (mix 1.14.3) lib/mix/project.ex:397: Mix.Project.in_project/4
    (elixir 1.14.3) lib/file.ex:1607: File.cd!/2

This prevents the crash, the warning is still there but my gettext.extract command is working.

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 17168749f03f3c2f675b962878f1a2a0d0a32673-PR-352

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 60ac67425aa1501fd2d51d8a54baac9d403cef7a: 0.02%
Covered Lines: 524
Relevant Lines: 578

💛 - Coveralls
whatyouhide commented 1 year ago

Thanks @benoawfu, great catch!