Closed tflori closed 7 years ago
@BorntraegerMarc you see how this is affecting the interface: see the changes to translate and the return value from instant. I also need to adjust the return value of the observe method... And of course we need documentation for it...
@BorntraegerMarc for this "problem" we need to change the whole interface. currently it is typesafe already: you give an array of keys - you get an array of translations; you give a single key - you get a translation. With this proposal it changes to string or object - so it is not typesafe anymore.
So one thing is the methods that accepts string|string[]
(observe, translate, instant). Unfortunately it's not like java where you write two times the same method name with different parameters and the app is using which fits best. For this they have to be changed to instant and instantArray, translate and translateArray, observe and observeArray.
The other thing is to search when a key is not found - this results to objects instead of string (either in an array or a single object). To pop this out we would need to add translateSearch and observeSearch.
For backward compatibility we can not remove string|string[]
from translate, instant or observe. We can mark them deprecated and remove them in next major release. But we can already create the Array methods. And we can remove the search functionality from them when key is not found and create the Search methods.
@tflori I agree with every point you made except the part where you stated "so it is not typesafe anymore"
why wouldn't passing a interface or a TS pre determined object be typesafe? And I also don't really understand how passing a string is more typesafe?
if you call translate('trans.de')
you can't do any check at compilation time if this object really exists or if it the right one. You always need to execute the code and check in the frontend if you definitely got the correct value.
With translate(IMPORTED_TRANS.trans.de)
the compile will throw an error if an object does not exist.
But anyway: Just wanted to have a open discussion 😄 do you think we should create an issue and plan it for v3
? Or you're not a fan of the idea at all?
@BorntraegerMarc I'm not sure if I understand you correct.. what do you mean to pass an interface or a TS object?
when you call translate('string')
you get string back - always.
when you call translate(['string'])
you get array back - always.
I implemented now a different method and added a deprecation information in the translate, observe and instant method doc-comment. https://github.com/tflori/angular-translator/pull/59/commits/b750a0c40f33bc952bb413837aa626ecc37abb82
The functions need to be tested before I can merge it for version 2.3 but then you will be type safe - and we remove the |string[]
from translate, observe and instant we are absolutley typesafe.
Well, to sum it up my suggestion would be to change the method translate(keys: string|string[],
to translate(keys: any|any[],
...
this will solve #58