-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcp47.php
47 lines (34 loc) · 1.33 KB
/
bcp47.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>BCP 47</title>
<script type="text/javascript" src="bcp47.js"></script>
<script type="text/javascript">
var acceptLanguage = '<?php print @$_SERVER['HTTP_ACCEPT_LANGUAGE']; ?>';
var acceptLangs = BCP47.parseAcceptLanguage( acceptLanguage );
console.log( acceptLangs );
var priorityList = [];
var availableList = [ 'en-GB', 'en-US', 'en-ZA', 'es-AR', 'es-CL', 'es-ES', 'es-MX', 'ga-IE', 'zh-Hant', 'zh-Hans' ];
for( var i = 0; i < acceptLangs.length; i++ ) {
var tag = BCP47.parseTag( acceptLangs[i].tag );
console.log( tag );
priorityList.push( tag.tag );
}
var testTag = 'zh-gan-hak-Hans-CN-1901-rozaj-2abc-t-fonipa-u-islamcal-myext-testing-x-private-testing';
console.log( BCP47.parseTag( testTag ) );
// BCP47.runTests();
console.log( availableList );
console.log( priorityList, BCP47.lookup( priorityList, availableList ) );
priorityList.shift();
console.log( priorityList, BCP47.lookup( priorityList, availableList ) );
priorityList.unshift( testTag );
console.log( priorityList, BCP47.lookup( priorityList, availableList ) );
priorityList.unshift( 'zh-Hans-CN' );
console.log( priorityList, BCP47.lookup( priorityList, availableList ) );
console.log( [], BCP47.lookup( [], availableList ) );
</script>
</head>
<body>
</body>
</html>