admin管理员组

文章数量:1332873

If navigator.language returns en-US, but I only want en because I don't care about the locale, is there a preferred way to do this? Does angular have anything built in for this or should I just split on the -?

If navigator.language returns en-US, but I only want en because I don't care about the locale, is there a preferred way to do this? Does angular have anything built in for this or should I just split on the -?

Share Improve this question asked Nov 27, 2017 at 14:36 xaisoftxaisoft 3,4518 gold badges46 silver badges78 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

use js String.prototype.slice() method.

navigator.language.slice(0,2);

This will do:

navigator.language.substring(0,2);

本文标签: angularGetting 2 letter language code with javascriptStack Overflow