3 ms·
Thank you very much for your comments guys! I am definitely learning a lot. I was encouraged to write the post just in case someone happened to have the same p
by zaldih 3y ago
Thank you very much for your comments guys! I am definitely learning a lot.
I was encouraged to write the post just in case someone happened to have the same problem, hopefully ended up on the site and could find some light here.
Now thanks to you I realise that I made the mistake of using getDisplayLanguage() instead of getLanguage(). The former returns the text of the language. The second one returns the universal code of the language.
As I said at the end, I'm not an Android developer and I guess in my haste and tiredness I settled for the first thing that seemed to work without much thought to good practice or whether I was actually getting the language code or not. A very silly bug but as it worked most of the time for some reason, it was almost impossible to find the first time. And of course, snipped was a simplification of a more complex system with persistence handling and so on, which made it not so obvious.
I certainly think all of us here won't make this mistake in the future :)
- vintagedave 3y agoKudos. We’ve all solved bugs with the wrong code. It was an interesting post and I found the unexpected secondary followup just as interesting. (Why did it work for, eg, Chinese, do you know?) See, I am not an Android developer either. I could have made the same mistake. To me it comes down to — why string types?
- moi2388 3y agoThis is always the issue. It’s why Python and JavaScript are so terrible, and the cause of so many bugs, yet so readily available in apis and cicd pipelines. Why people insist on keep using strings instead of typesafe variants is beyond me
- ficklepickle 3y agoTypeScript is nice here because you can specify the specific strings you accept in a union. Eg. `unit: 'AC'|'DC'`