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