go-aah / aah

A secure, flexible, rapid Go web framework
https://aahframework.org
MIT License
690 stars 33 forks source link

I18n.Lookup return value #237

Closed vcraescu closed 5 years ago

vcraescu commented 5 years ago

Lookup function should return the key value if there's no translation for that key. Much easier to debug and there are cases when you need that where you pass a string to that method which is a translation key or just need to print it. There's no way to check if a translation key is valid or not.

jeevatkm commented 5 years ago

@vcraescu Currently function returns empty string and logs key not found as a warning.

https://github.com/go-aah/aah/blob/0bb36e017ede1b452eb1aa8c256bd5a7860b2563/i18n/i18n.go#L149-L151

I thought log message would be enough for key not found cases. Seems like its not.

I have a question for you: just a key should be returned or key with some wrapped value. e.g.: ???key.not.found???

vcraescu commented 5 years ago

@jeevatkm Key should be enough. That's how most of the translators are implemented at least in PHP world :smile:

Is very helpful when you need to display a text but you don't know if it's a translation key or just a value. There are cases when you would put a translation key into a db field (fast translatable entities :smile:) and sometimes you just need to display the value as it is. If the translation function returns the key if no translation found it makes possible to create generic template function which will display either the translation or the raw value.

Not very good at explaining stuff just hope it makes sense.

jeevatkm commented 5 years ago

@vcraescu understood 😄

jeevatkm commented 5 years ago

Its done 😄

vcraescu commented 5 years ago

thanks! :+1:

jeevatkm commented 5 years ago

@vcraescu You're welcome. You could try the implementation and please share your feedback.

Add to go.mod

replace aahframe.work => aahframe.work v0.0.0-20190111183604-b1a2826abfb3