intl.html revision 30551f406370f7c8bf461a833205311de720886d
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Internationalization Tests</title>
<script type="text/javascript" src="/build/yui/yui.js"></script>
<style type="text/css">
#console .yui3-console-entry {
padding:2px;
margin:0px;
min-height:0;
}
#console .yui3-console-entry-fail .yui3-console-entry-cat {
background-color:red;
}
#console .yui3-console-entry-pass .yui3-console-entry-cat {
background-color:green;
}
#console .yui3-console-entry-perf .yui3-console-entry-cat {
background-color:blue;
}
#console {
position:static;
}
html, body {
height:100%;
}
</style>
</head>
<body class="yui3-skin-sam">
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
<script type="text/javascript">
YUI({
useBrowserConsole:false
}).use("console", "test", "intl", function(Y) {
// Set up the page
var LANG = Y.Lang,
ASSERT = Y.Assert,
ARRAYASSERT = Y.ArrayAssert,
btnRun = Y.get("#btnRun"),
areObjectsReallyEqual = function (o1, o2) {
Y.ObjectAssert.areEqual(o1, o2);
Y.ObjectAssert.areEqual(o2, o1);
};
new Y.Console({
id:"console",
width:"100%",
height:"90%",
verbose : false,
printTimeout: 0,
newestOnTop : false,
entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
'<span class="{entry_cat_class}">{label}</span>'+
'<span class="{entry_content_class}">{message}</span>'+
'</pre>'
}).render();
btnRun.set("disabled", false);
Y.on("click", function() {
Y.Test.Runner.run();
}, btnRun);
var testLookupBestLanguage = new Y.Test.Case({
name: "Lookup Best Language Tests",
testArray: function() {
var language = Y.Intl.lookupBestLang(["de-DE", "en-SG", "ja-JP"], ["fr-FR", "en", "en-SG"]);
ASSERT.areSame(language, "en-SG", "Expected en-SG.");
},
testString: function() {
var language = Y.Intl.lookupBestLang("de-DE,en-SG,ja-JP", ["fr-FR", "en", "en-SG"]);
ASSERT.areSame(language, "en-SG", "Expected en-SG.");
},
testStar: function() {
var language = Y.Intl.lookupBestLang("de-DE,*,en-SG,ja-JP", ["fr-FR", "en", "en-SG"]);
ASSERT.areSame(language, "en-SG", "Expected en-SG.");
},
testPrivate: function() {
var language = Y.Intl.lookupBestLang("de-DE,zh-Hant-CN-x-private1-private2", ["fr-FR", "zh-Hant-CN", "zh-Hant-CN-x"]);
ASSERT.areSame(language, "zh-Hant-CN", "Expected zh-Hant-CN.");
}
});
var testStore = new Y.Test.Case({
name: "Basic Intl Language Store Tests",
testAdd: function() {
Y.Intl.add("modA", "en-US", {
hello:"Hello"
});
ASSERT.areSame(Y.Intl.get("modA").hello, "Hello");
Y.Intl.add("modA", "fr", {
hello:"Bonjour"
});
ASSERT.areSame(Y.Intl.get("modA").hello, "Bonjour");
Y.Intl.add("modA", "ja-JP", {
hello: "こんにちは"
});
ASSERT.areSame(Y.Intl.get("modA").hello, "こんにちは");
Y.Intl._setLang("modA", "fr");
ASSERT.areSame(Y.Intl.get("modA").hello, "Bonjour");
},
testRoot : function() {
Y.Intl.add("modB", "fr", {
hello:"Bonjour"
});
ASSERT.areSame(Y.Intl.getLang("modB"), "fr");
Y.Intl.add("modB", "", {
hello:"HELLO"
});
ASSERT.areSame(Y.Intl.getLang("modB"), "");
ASSERT.areSame(Y.Intl.get("modB").hello, "HELLO");
Y.Intl._setLang("modB", "fr");
ASSERT.areSame(Y.Intl.get("modB").hello, "Bonjour");
ASSERT.areSame(Y.Intl.getLang("modB"), "fr");
},
testGet : function() {
var origSet = {
hello : "Hello",
world : "World"
};
Y.Intl.add("modC", "en", {
hello : "Hello",
world : "World"
});
var strs = Y.Intl.get("modC");
areObjectsReallyEqual(strs, origSet);
ASSERT.areSame(Y.Intl.get("modC", "hello"), origSet.hello);
ASSERT.areSame(Y.Intl.get("modC", "world"), origSet.world);
}
});
Y.Test.Runner.add(testLookupBestLanguage);
Y.Test.Runner.add(testStore);
Y.Test.Runner.run();
});
</script>
</body>
</html>