angular-translate icon indicating copy to clipboard operation
angular-translate copied to clipboard

Doc suggestions for $translate.preferredLanguage and $translate.use

Open jcalfee opened this issue 10 years ago • 3 comments

It says "Returns the language key" but language key is a parameter so it is confusing to me. Then is says that is returns the preferred language key. I'm investigating a bug in our code and came across this method. I wonder if having a bit more docs on this method would have helped avoid the bug..

See: http://angular-translate.github.io/docs/#/api/pascalprecht.translate.$translate

preferredLanguage(langKey)

Returns the language key for the preferred language.

Parameters
Param   Type    Details
langKey string  
language String or Array to be used as preferredLanguage (changing at runtime)

Returns
preferred language key

jcalfee avatar Mar 17 '15 16:03 jcalfee

It is correct. The method both sets (if provided) and returns the language key of the preferred language. https://github.com/angular-translate/angular-translate/blob/2.6.1/src/service/translate.js#L1377-L1382

However, you are right. It is not clear from docs, that this method can set a preferred language.

DWand avatar Mar 17 '15 17:03 DWand

We had calls in our code to try and change the preference via calls to $translate.use("...") .. I changed those call to $translate.preferredLanguage("...") and got much better behaviour. Maybe a small note under "use" that says call preferredLanguage to actually change the preferredLanguage. Your suggested update sounds great too. Thank you..

jcalfee avatar Mar 17 '15 17:03 jcalfee

I fixed the title .. sorry about that ;)

jcalfee avatar Mar 17 '15 17:03 jcalfee