anmolitor/travelm-agency

Links in translations

Closed this issue · 2 comments

Use case:

You create an error overlay in case something unexpected happens, the server is down or something.
Adding a contact url for a single error and a single language is pretty easy, you just write the HTML in Elm.

errorMessage : Html msg
errorMessage = div [ ] [ text "Oh no! Please contact me ", a [ href "..." ] [ text "here" ], text "." ] 

But when you have different error messages with multiple languages, right now with this package, you can only something like this:

errorMessage : I18n -> Html msg
errorMessage i18n = div [ ] [ text <| Translations.errorMsgBeforeLink i18n, a [ href "..." ] [ text <| Translations.errorMsgLinkText ], text <| Translations.errorMsgAfterLink ] 

which is pretty ugly and not very readable when reading the i18n files (Translations.errorMsgAfterLink would be "." in this scenario).
It also gets a LOT worse if some language do not have the link or have a different link. You could theoretically solve this with the current functionality but I would not want to read that code.

Proposal:

Instead, What this package could do, is parse the given translations (which it does anyways to resolve placeholders)
and convert HTML tags like to HTML generating functions.

The following translation:

Oh no! Please contact me <a href="">here</a>.

would be converted to a function

someTranslation : I18n -> List (Html msg)
someTranslation i18n = [ text "Oh no! Please contact me ", a [ href "" ] [ text "here" ], text "." ]

As a consequence, corresponding messages in other languages would have the same type even if they do not contain any HTML tags (they would then produce a one-element List (Html msg)).

I have made a lot of progress on this topic, while rewriting my test suite and fixing a couple of bugs that I caught.
I will soon release V3 of travelm-agency, which will contain this feature and also a complete interactive documentation website written with travelm-agency itself! 🤯

Released version 3.0.0 where this feature is included 🚀