Hermanverschooten

Hermanverschooten

Is there a way to see what version of a depency is loaded?

Gettext released a new version (0.26) that breaks compatibiliy, the way you need to add/use Gettext has been changed.

While it isn’t a problem for my project to make the necessary changes, it also breaks compilation for Timex.

Now I was wondering how one can distinguish in library code what version of Gettext is loaded, so the correct import vs use can be compiled.

Most Liked

Hermanverschooten

Hermanverschooten

Yes I saw it too.

Although I must admit that I took the opportunity to remove Timex from my project and replace it with Elixir native functions and modules.

The only thing missing was Timex.between? and that was easily resolved.

allenmaxd

allenmaxd

you can check the version of a dependency like Gettext that’s loaded at runtime using the Application.spec/2 function. Here’s how you can do it:

defmodule VersionCheck do
  def gettext_version do
    case Application.spec(:gettext, :vsn) do
      '0.26.0' -> :new_version
      _ -> :old_version
    end
  end
end

This function retrieves the version of Gettext and allows you to distinguish between different versions, enabling you to conditionally apply the necessary changes in your code.

kip

kip

ex_cldr Core Team

@carlgleisner, you’ll still need to bring gettext/1 into scope by importing it - the message suggests it isn’t imported into that module. ie I don’t think the error is coming from ex_cldr in this case (but hey, wouldn’t be the first time I’ve been wrong!).

Somewhere you’ve got a module MyApp.Gettext. Then in MyAppWeb.Layouts there should be an import for MyApp.Gettext module I believe.

(thanks for the kind words)

wojtekmach

wojtekmach

Hex Core Team
if Version.match?(to_string(Application.spec(:app, :vsn)), ">= x.y.z") do
Hermanverschooten

Hermanverschooten

So you can do something like

if Version.match?(to_string(Application.spec(:gettet, :vsn), ">= 0.26") do
  use Gettext.Backend, otp_app: :my_app
else
  use Gettext, otp_app: :my_app
end

and then

if Version.match?(to_string(Application.spec(:gettet, :vsn), ">= 0.26") do
  use Gettext, backend: MyApp.Gettext
else
  import MyApp.Gettext
end

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement