ChristophP / elm-i18next

https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest
BSD 3-Clause "New" or "Revised" License
66 stars 12 forks source link

Added tc function #7

Closed synalysis closed 5 years ago

synalysis commented 6 years ago

Added tc function that outputs only the last part of the key if no translation is found.

Would be nice if you could add this function to your package, it allows to display the raw key without the "category" part if no translation is available. This means that only translations have to be transmitted that differ from the "original" text.

While I guess you are using different names for what I called "category" and "key" in the comment above the function I wanted to provide a complete change request including comment.

ChristophP commented 5 years ago

So like we discussed a while ago. I don't think that is a functionality that many people need, so I would suggest to just write this as a helper function in your application code:

tc (Translations translations) category key =
    let
        val = t translations (category ++ "." ++ key) 
    in if val == (category ++ "." key) then key else val

If I am totally wrong about this and this a use case that is very common and lot of people use in their workflow, please open an issue again with that information.

synalysis commented 5 years ago

We'll never know if people would have used a function if it would exist and if that way of using your lib is not mentioned.

There are environments where the English version of some text is used as a key for the translated one. And especially in a web environment it makes sense to send only differences and display something nice in case of a network error.

I'll continue to use my patched version of the library so it's fine for me to have this pull request closed. Probably it doesn't harm performance significantly to do the additional string comparison (in the function you proposed) for each string output, I just hesitate to do it less performant if there's an elegant alternative.

synalysis commented 5 years ago

Btw: Maybe it would be good to modify the sample code not to use an English text as a key: div [] [ text (t model.translations "hello") ] -- "Hallo"

This could lead also other people to use the lib this way just to be stuck when using the dot notation for keys and they want to send only texts to the client where the strings differ from the key.

ChristophP commented 5 years ago

@synalysis Thanks, I'll put editing the example a bit on the list to make the difference more clear. Like I said, I don't see a strong use case for this right now. Maybe there are some use cases I am not aware of. Knowing more about those cases would help change my mind. If you would like to continue investigating this please don't replay here but create an issue about it and I will revisit it. My main questions are: