Will the following module attribute work as expected?

@msg gettext(
         "Sorry, your account must first be validated by our admins before " <>
           "you can access the requested page. Once this is the case, you will " <>
           "receive an email notification."
       )

Please I would like to know if using the string concatenation operator <> like that, will prevent Gettext from extracting the full string when adding translations.

I’m not yet at this step, but I would better know not relying on that before having a bunch of this to fix later.

Thanks.

It’s very quick to spin up a new Phoenix project with Gettext infrastructure and see for yourself.

However, I would guess not, but not for the reasons you think… Gettext is evaluated at run-time based on a locale set for the current active process, whereas module attributes are evaluated at compile-time.

Building a long string as a module attribute will work, e.g.:

@msg "Sorry, your account must first be validated by our admins before " <>
           "you can access the requested page. Once this is the case, you will " <>
           "receive an email notification."

But then your calls to Gettext need to be made in your run-time code.

4 Likes