diff --git a/demos/prefsFramework/html/SeparatedPanelPrefsEditor.html b/demos/prefsFramework/html/SeparatedPanelPrefsEditor.html index daec1cae2a..775ea606ef 100644 --- a/demos/prefsFramework/html/SeparatedPanelPrefsEditor.html +++ b/demos/prefsFramework/html/SeparatedPanelPrefsEditor.html @@ -1,6 +1,7 @@
diff --git a/demos/prefsFramework/index.html b/demos/prefsFramework/index.html index 3834e1d7d0..775aa5c2a4 100644 --- a/demos/prefsFramework/index.html +++ b/demos/prefsFramework/index.html @@ -61,11 +61,13 @@ + + @@ -77,6 +79,7 @@ + @@ -103,6 +106,7 @@ "fluid.prefs.auxSchema.letterSpace", // this will add the letter space adjuster and enactor "fluid.prefs.auxSchema.wordSpace", // this will add the word space adjuster and enactor "demo.prefsEditor.auxSchema.syllabification", // this will add the syllabification adjuster and enactor + "fluid.prefs.auxSchema.localization", // this will add the localization adjuster and enactor "demo.prefsEditor.auxSchema.simplify", // this will add the simplify adjuster and enactor "demo.prefsEditor.progressiveEnhancement" // progressive enhancement - may add selfVoicing ], diff --git a/examples/framework/preferences/captionsPreference/index.html b/examples/framework/preferences/captionsPreference/index.html index f1dc25f2de..ae4f98c442 100644 --- a/examples/framework/preferences/captionsPreference/index.html +++ b/examples/framework/preferences/captionsPreference/index.html @@ -10,16 +10,17 @@ - Preferences Editor: Using Grades + Preferences Editor: Captions Preference + + - diff --git a/examples/framework/preferences/localizationPreference/urlPath/en/index.html b/examples/framework/preferences/localizationPreference/urlPath/en/index.html new file mode 100644 index 0000000000..da00681a25 --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/en/index.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + Preferences Editor: Localization Preference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ + +
+ + + + +
+
+ + +

Hello World!

+ + + + diff --git a/examples/framework/preferences/localizationPreference/urlPath/es/index.html b/examples/framework/preferences/localizationPreference/urlPath/es/index.html new file mode 100644 index 0000000000..3a9771f5ae --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/es/index.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + Editor de preferencias: Preferencia de localización + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ + +
+ + + + +
+
+ + +

Hola Mundo!

+ + + + diff --git a/examples/framework/preferences/localizationPreference/urlPath/fa/index.html b/examples/framework/preferences/localizationPreference/urlPath/fa/index.html new file mode 100644 index 0000000000..2883803f13 --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/fa/index.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + ویرایشگر ترجیحات: اولویت محلی سازی + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ + +
+ + + + +
+
+ + +

سلام دنیا!

+ + + + diff --git a/examples/framework/preferences/localizationPreference/urlPath/fr/index.html b/examples/framework/preferences/localizationPreference/urlPath/fr/index.html new file mode 100644 index 0000000000..699adaf36b --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/fr/index.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + Editeur de préférences: Préférence de localisation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ + +
+ + + + +
+
+ + +

Bonjour le monde!

+ + + + diff --git a/examples/framework/preferences/localizationPreference/urlPath/html/prefsEditor.html b/examples/framework/preferences/localizationPreference/urlPath/html/prefsEditor.html new file mode 100644 index 0000000000..3151a4f650 --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/html/prefsEditor.html @@ -0,0 +1,7 @@ +
+
+ +
+
diff --git a/examples/framework/preferences/localizationPreference/urlPath/index.html b/examples/framework/preferences/localizationPreference/urlPath/index.html new file mode 100644 index 0000000000..b85b307676 --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/index.html @@ -0,0 +1,113 @@ + + + + + + + + + + + + + Preferences Editor: Localization Preference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ + +
+ + + + +
+
+ + +

Hello World!

+ + + + diff --git a/examples/framework/preferences/localizationPreference/urlPath/js/localization.js b/examples/framework/preferences/localizationPreference/urlPath/js/localization.js new file mode 100644 index 0000000000..ee811945b9 --- /dev/null +++ b/examples/framework/preferences/localizationPreference/urlPath/js/localization.js @@ -0,0 +1,68 @@ +/* +Copyright 2018-2019 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +/* global fluid */ + +var example = example || {}; +(function ($, fluid) { + "use strict"; + + fluid.defaults("example.prefs.localization", { + gradeNames: ["fluid.prefs.constructed.localizationPrefsEditorConfig"], + localizationScheme: "urlPath", + localeNames: ["localization-default", "localization-en", "localization-fr", "localization-es", "localization-fa"], + locales: ["", "en", "fr", "es", "fa"], + langMap: { + "en": "en", + "es": "es", + "fa": "fa", + "fr": "fr" + }, + langSegIndex: { + expander: { + funcName: "example.prefs.localization.getLangSegIndex", + args: ["{that}.options.langMap"] + } + } + }); + + /** + * Used as an expander to find the `langSegIndex`. For most implementations this would actually refer to 1; which is + * the default `langSegIndex` set in the component's defaults. Meaning a scheme such as this would not be required. + * However, the way this example is constructed, the `langSegIndex` is at the end of the path. + * Because we don't know ahead of time how this example will be served, we don't know the full path and must + * dynamically calculate the index. + * + * @param {Object} langMap - a mapping of language code to URL path resource. + * + * @return {Integer} - The `lagSegIndex`. Defaults to 1 if none of the values from the langMap are found in the + * current location's pathname. + */ + example.prefs.localization.getLangSegIndex = function (langMap) { + var langVals = fluid.values(langMap); + var pathSegs = location.pathname.split("/"); + var index = 1; + + // Add an empty string to capture the case where no language has been set in the URL. + langVals.unshift(""); + + fluid.each(langVals, function (langVal) { + // we use `lastIndexOf` because we know the language code is set at the end of the URL in this example + var foundIndex = pathSegs.lastIndexOf(langVal); + if (foundIndex >= 0) { + index = foundIndex; + } + }); + + return index; + }; + +})(jQuery, fluid); diff --git a/package.json b/package.json index 6e50d786ff..f9f14f2e1b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test:vagrant": "vagrant up && vagrant ssh -c 'cd /home/vagrant/sync/; DISPLAY=:0 npm test'", "test:vagrantBrowser": "vagrant up && vagrant ssh -c 'cd /home/vagrant/sync/; DISPLAY=:0 npm run test:browser'", "test:vagrantNode": "vagrant up && vagrant ssh -c 'cd /home/vagrant/sync/; DISPLAY=:0 npm run test:node'", - "posttest": "node node_modules/nyc/bin/nyc.js report -r text-summary -r html --report-dir reports --temp-directory coverage", + "posttest": "node node_modules/nyc/bin/nyc.js report -r text-summary -r html", "buildDists": "grunt buildDists", "buildStylus": "grunt buildStylus", "loadDependencies": "grunt loadDependencies" @@ -42,7 +42,7 @@ "devDependencies": { "eslint-config-fluid": "1.3.0", "gpii-grunt-lint-all": "1.0.5", - "gpii-testem": "2.1.5", + "gpii-testem": "2.1.7", "grunt": "1.0.2", "grunt-contrib-clean": "2.0.0", "grunt-contrib-compress": "1.4.3", @@ -52,7 +52,7 @@ "grunt-contrib-uglify": "4.0.0", "grunt-contrib-watch": "1.1.0", "grunt-modulefiles": "0.4.0", - "grunt-shell": "2.1.0", + "grunt-shell": "3.0.1", "hypher": "0.2.5", "@fluid-project/hyphenation-patterns": "0.2.2-dev.20181115T221631Z.b2d0651", "jquery": "3.3.1", @@ -63,13 +63,13 @@ "jquery.scrollto": "2.1.2", "lodash": "4.17.11", "ncp": "2.0.0", - "normalize.css": "8.0.0", - "nyc": "13.0.1", - "opensans-webkit": "1.0.1", - "rimraf": "2.6.2", + "normalize.css": "8.0.1", + "nyc": "13.1.0", + "opensans-webkit": "1.1.0", + "rimraf": "2.6.3", "roboto-fontface": "0.10.0", - "sinon": "6.3.3", - "testem": "2.9.3", - "url-polyfill": "1.1.0" + "sinon": "7.2.2", + "testem": "2.12.0", + "url-polyfill": "1.1.3" } } diff --git a/src/framework/preferences/css/stylus/PrefsEditor.styl b/src/framework/preferences/css/stylus/PrefsEditor.styl index 2fa0ba94de..5e1c44f578 100644 --- a/src/framework/preferences/css/stylus/PrefsEditor.styl +++ b/src/framework/preferences/css/stylus/PrefsEditor.styl @@ -211,7 +211,7 @@ .fl-icon-line-space-condensed, .fl-icon-contrast, .fl-icon-undo, .fl-icon-line-space, .fl-icon-inputs, .fl-icon-simplify, .fl-icon-font, .fl-icon-size, .fl-icon-text-to-speech, .fl-icon-toc, .fl-icon-letter-space, .fl-icon-letter-space-expanded, .fl-icon-letter-space-condensed, .fl-icon-captions, .fl-icon-word-space, - .fl-icon-word-space-condensed, .fl-icon-word-space-expanded, .fl-icon-syllabification { + .fl-icon-word-space-condensed, .fl-icon-word-space-expanded, .fl-icon-syllabification, .fl-icon-language { font-family: 'PrefsFramework-Icons'; speak: none; font-style: normal; @@ -325,6 +325,9 @@ .fl-icon-syllabification:before { content: "\e017"; } + .fl-icon-language:before { + content: "\e018"; + } } // Theming build-themes-prefsEditor(themes); diff --git a/src/framework/preferences/fonts/PrefsFramework-Icons-config.json b/src/framework/preferences/fonts/PrefsFramework-Icons-config.json index e187a57f62..f987ccdd9c 100644 --- a/src/framework/preferences/fonts/PrefsFramework-Icons-config.json +++ b/src/framework/preferences/fonts/PrefsFramework-Icons-config.json @@ -9,6 +9,7 @@ "svg/infusion/infusion-crossout-diag-dotted-line.svg", "svg/infusion/infusion-font-style.svg", "svg/infusion/infusion-indicator-arrow-triangle.svg", + "svg/infusion/infusion-language.svg", "svg/infusion/infusion-line-space.svg", "svg/infusion/infusion-line-space-condensed.svg", "svg/infusion/infusion-line-space-expanded.svg", @@ -51,7 +52,8 @@ "infusion-word-space": "0xE014", "infusion-word-space-condensed": "0xE015", "infusion-word-space-expanded": "0xE016", - "infusion-syllabification": "0xE017" + "infusion-syllabification": "0xE017", + "infusion-language": "0xE018" }, "templateOptions": { "classPrefix": "fl-icon-" diff --git a/src/framework/preferences/fonts/PrefsFramework-Icons.woff b/src/framework/preferences/fonts/PrefsFramework-Icons.woff index 756c7b6b7b..f0da76944f 100644 Binary files a/src/framework/preferences/fonts/PrefsFramework-Icons.woff and b/src/framework/preferences/fonts/PrefsFramework-Icons.woff differ diff --git a/src/framework/preferences/html/PrefsEditorTemplate-localization.html b/src/framework/preferences/html/PrefsEditorTemplate-localization.html new file mode 100644 index 0000000000..85042b8595 --- /dev/null +++ b/src/framework/preferences/html/PrefsEditorTemplate-localization.html @@ -0,0 +1,6 @@ +

+ + +

+

+ diff --git a/src/framework/preferences/js/LocalizationEnactor.js b/src/framework/preferences/js/LocalizationEnactor.js new file mode 100644 index 0000000000..5ff4a4bac3 --- /dev/null +++ b/src/framework/preferences/js/LocalizationEnactor.js @@ -0,0 +1,160 @@ +/* +Copyright 2018-2019 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +var fluid_3_0_0 = fluid_3_0_0 || {}; + +(function ($, fluid) { + "use strict"; + + /******************************************************************************* + * Localization + * + * The enactor to change the locale shown according to the value + * + * This grade is resolvable from the root to allow for setting up of model relays + * from other components on a page that may want to be notified of a language + * change and update their own UI automatically. + *******************************************************************************/ + + fluid.defaults("fluid.prefs.enactor.localization", { + gradeNames: ["fluid.prefs.enactor", "fluid.contextAware", "fluid.resolveRoot"], + preferenceMap: { + "fluid.prefs.localization": { + "model.lang": "value" + } + }, + contextAwareness: { + localeChange: { + checks: { + // This check determines if the enactor is being run inside of the separated panel's iframe. + // At the moment, all enactors are copied into the iframe to apply settings to the panel as well. + // However, the strings for the panel will be localized through the prefsEditorLoader and do not + // require the iframe URL to change. When in the panel, we do not run the urlPathLocale changes. + inPanel: { + contextValue: "{iframeRenderer}.id", + // The following undefined grade is needed to prevent the `urlPath` check from supplying its + // grade even when the `inPanel` check passes. + gradeNames: "fluid.prefs.enactor.localization.inPanel" + }, + urlPath: { + contextValue: "{localization}.options.localizationScheme", + equals: "urlPath", + gradeNames: "fluid.prefs.enactor.localization.urlPathLocale", + priority: "after:inPanel" + } + } + } + } + }); + + /******************************************************************************* + * URL Path + * + * Changes the URL path to specify which language should be displayed. Useful + * if languages are served at different URLs based on a language resource. + * E.g. www.example.com/about/ -> www.example.com/fr/about/ + *******************************************************************************/ + fluid.defaults("fluid.prefs.enactor.localization.urlPathLocale", { + langMap: {}, // must be supplied by integrator + langSegValues: { + expander: { + funcName: "fluid.values", + args: ["{that}.options.langMap"] + } + }, + // langSegIndex: 1, should be supplied by the integrator. Will default to 1 in `fluid.prefs.enactor.localization.urlPathLocale.updatePathname` + modelRelay: [{ + target: "urlLangSeg", + singleTransform: { + type: "fluid.transforms.valueMapper", + defaultInput: "{that}.model.lang", + match: "{that}.options.langMap" + } + }], + modelListeners: { + urlLangSeg: { + funcName: "{that}.updatePathname", + args: ["{change}.value"], + namespace: "updateURLPathname" + } + }, + invokers: { + updatePathname: { + funcName: "fluid.prefs.enactor.localization.urlPathLocale.updatePathname", + args: ["{that}", "{arguments}.0", "{that}.options.langSegValues", "{that}.options.langSegIndex"] + }, + getPathname: "fluid.prefs.enactor.localization.urlPathLocale.getPathname", + setPathname: "fluid.prefs.enactor.localization.urlPathLocale.setPathname" + } + }); + + /** + * A simple wrapper around the location.pathname getter. + * + * @return {String} - If the `pathname` argument is not provided, the current pathname is returned + */ + fluid.prefs.enactor.localization.urlPathLocale.getPathname = function () { + return location.pathname; + }; + + /** + * A simple wrapper around the location.pathname setter. + * + * @param {String} pathname - The pathname to set. + */ + fluid.prefs.enactor.localization.urlPathLocale.setPathname = function (pathname) { + location.pathname = pathname; + }; + + /** + * Modifies the URL Path to navigate to the specified localized version of the page. If the "default" language is + * selected. The function exits without modifying the URL. This allows for the server to automatically, or the user + * to manually, navigate to a localized page when a language preference hasn't been set. + * + * @param {Component} that - an instance of `fluid.prefs.enactor.localization.urlPathLocale` + * @param {String} urlLangSeg - a language value used in the URL pathname + * @param {Object} langSegValues - An array of the potential `urlLangSeg` values that can be set. + * @param {Integer} langSegIndex - (Optional) An index into the path where the language resource identifier is held. + * By default this value is 1, which represents the first path segment. + */ + fluid.prefs.enactor.localization.urlPathLocale.updatePathname = function (that, urlLangSeg, langSegValues, langSegIndex) { + + if (fluid.isValue(urlLangSeg)) { + langSegIndex = langSegIndex || 1; + var pathname = that.getPathname(); + var pathSegs = pathname.split("/"); + + var currentLang = pathSegs[langSegIndex]; + var hasLang = !!currentLang && langSegValues.indexOf(currentLang) >= 0; + + if (hasLang) { + if (urlLangSeg) { + pathSegs[langSegIndex] = urlLangSeg; + } else { + if (langSegIndex === pathSegs.length - 1) { + pathSegs.pop(); + } else { + pathSegs.splice(langSegIndex, 1); + } + } + } else if (urlLangSeg) { + pathSegs.splice(langSegIndex, 0, urlLangSeg); + } + + var newPathname = pathSegs.join("/"); + + if (newPathname !== pathname) { + that.setPathname(newPathname); + } + } + }; + +})(jQuery, fluid_3_0_0); diff --git a/src/framework/preferences/js/LocalizationPanel.js b/src/framework/preferences/js/LocalizationPanel.js new file mode 100644 index 0000000000..279b05c898 --- /dev/null +++ b/src/framework/preferences/js/LocalizationPanel.js @@ -0,0 +1,60 @@ +/* +Copyright 2018 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +var fluid_3_0_0 = fluid_3_0_0 || {}; + +(function ($, fluid) { + "use strict"; + + /*********************************** + * Preferences Editor Localization * + ***********************************/ + + /** + * A sub-component of fluid.prefs that renders the "localization" panel of the user preferences interface. + */ + fluid.defaults("fluid.prefs.panel.localization", { + gradeNames: ["fluid.prefs.panel"], + preferenceMap: { + "fluid.prefs.localization": { + "model.value": "value", + "controlValues.localization": "enum" + } + }, + mergePolicy: { + "controlValues.localization": "replace", + "stringArrayIndex.localization": "replace" + }, + selectors: { + header: ".flc-prefsEditor-localization-header", + localization: ".flc-prefsEditor-localization", + label: ".flc-prefsEditor-localization-label", + localizationDescr: ".flc-prefsEditor-localization-descr" + }, + selectorsToIgnore: ["header"], + stringArrayIndex: { + localization: ["localization-default", "localization-en", "localization-fr", "localization-es", "localization-fa"] + }, + protoTree: { + label: {messagekey: "label"}, + localizationDescr: {messagekey: "description"}, + localization: { + optionnames: "${{that}.msgLookup.localization}", + optionlist: "${{that}.options.controlValues.localization}", + selection: "${value}" + } + }, + controlValues: { + localization: ["default", "en", "fr", "es", "fa"] + } + }); + +})(jQuery, fluid_3_0_0); diff --git a/src/framework/preferences/js/LocalizationPrefsEditor.js b/src/framework/preferences/js/LocalizationPrefsEditor.js new file mode 100644 index 0000000000..52fb9b4a69 --- /dev/null +++ b/src/framework/preferences/js/LocalizationPrefsEditor.js @@ -0,0 +1,71 @@ +/* +Copyright 2019 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +var fluid_3_0_0 = fluid_3_0_0 || {}; + +(function (fluid) { + "use strict"; + + /******************************************************************************* + * Starter auxiliary schema grade + * + * Contains the settings for the localization preference + *******************************************************************************/ + + // Fine-tune the starter aux schema and add localization preference + fluid.defaults("fluid.prefs.constructed.localizationPrefsEditorConfig", { + gradeNames: ["fluid.contextAware"], + contextAwareness: { + localeChange: { + checks: { + urlPath: { + contextValue: "{localizationPrefsEditorConfig}.options.localizationScheme", + equals: "urlPath", + gradeNames: "fluid.prefs.constructed.localizationPrefsEditorConfig.urlPathLocale" + } + } + } + }, + distributeOptions: { + // When FLUID-6322 is complete, the default locale will be specifiable directly from the aux schema + "prefsEditor.localization.defaultLocale": { + source: "{that}.options.defaultLocale", + target: "{that prefsEditorLoader}.options.defaultLocale" + }, + "prefsEditor.localization.enactor.localizationScheme": { + source: "{that}.options.localizationScheme", + target: "{that uiEnhancer fluid.prefs.enactor.localization}.options.localizationScheme" + }, + "prefsEditor.localization.panel.locales": { + source: "{that}.options.locales", + target: "{that prefsEditor fluid.prefs.panel.localization}.options.controlValues.localization" + }, + "prefsEditor.localization.panel.localeNames": { + source: "{that}.options.localeNames", + target: "{that prefsEditor fluid.prefs.panel.localization}.options.stringArrayIndex.localization" + } + } + }); + + fluid.defaults("fluid.prefs.constructed.localizationPrefsEditorConfig.urlPathLocale", { + distributeOptions: { + "prefsEditor.localization.enactor.langMap": { + source: "{that}.options.langMap", + target: "{that uiEnhancer fluid.prefs.enactor.localization}.options.langMap" + }, + "prefsEditor.localization.enactor.langSegIndex": { + source: "{that}.options.langSegIndex", + target: "{that uiEnhancer fluid.prefs.enactor.localization}.options.langSegIndex" + } + } + }); + +})(fluid_3_0_0); diff --git a/src/framework/preferences/js/LocalizationSchemas.js b/src/framework/preferences/js/LocalizationSchemas.js new file mode 100644 index 0000000000..ec356f489a --- /dev/null +++ b/src/framework/preferences/js/LocalizationSchemas.js @@ -0,0 +1,65 @@ +/* +Copyright 2018 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +var fluid_3_0_0 = fluid_3_0_0 || {}; + +(function (fluid) { + "use strict"; + + /******************************************************************************* + * Starter auxiliary schema grade + * + * Contains the settings for the localization preference + *******************************************************************************/ + + // Fine-tune the starter aux schema and add localization preference + fluid.defaults("fluid.prefs.auxSchema.localization", { + gradeNames: ["fluid.prefs.auxSchema"], + auxiliarySchema: { + "terms": { + "templatePrefix": "../../framework/preferences/html/", + "messagePrefix": "../../framework/preferences/messages/" + }, + "template": "%templatePrefix/SeparatedPanelPrefsEditor.html", + "message": "%messagePrefix/prefsEditor.json", + localization: { + "type": "fluid.prefs.localization", + "enactor": { + "type": "fluid.prefs.enactor.localization" + }, + "panel": { + "type": "fluid.prefs.panel.localization", + "container": ".flc-prefsEditor-localization", // the css selector in the template where the panel is rendered + "template": "%templatePrefix/PrefsEditorTemplate-localization.html", + "message": "%messagePrefix/localization.json" + } + } + } + }); + + /******************************************************************************* + * Primary Schema + *******************************************************************************/ + + // add extra prefs to the starter primary schemas + + fluid.defaults("fluid.prefs.schemas.localization", { + gradeNames: ["fluid.prefs.schemas"], + schema: { + "fluid.prefs.localization": { + "type": "string", + "default": "", + "enum": ["", "en", "en_CA", "en_US", "fr", "es", "fa"] + } + } + }); + +})(fluid_3_0_0); diff --git a/src/framework/preferences/js/SeparatedPanelPrefsEditor.js b/src/framework/preferences/js/SeparatedPanelPrefsEditor.js index a8d63d410b..e17bd589b1 100644 --- a/src/framework/preferences/js/SeparatedPanelPrefsEditor.js +++ b/src/framework/preferences/js/SeparatedPanelPrefsEditor.js @@ -131,7 +131,8 @@ var fluid_3_0_0 = fluid_3_0_0 || {}; options: { gradeNames: ["{pageEnhancer}.uiEnhancer.options.userGrades"], jQuery: "{iframeRenderer}.jQuery", - tocTemplate: "{pageEnhancer}.uiEnhancer.options.tocTemplate" + tocTemplate: "{pageEnhancer}.uiEnhancer.options.tocTemplate", + inSeparatedPanel: true } } } diff --git a/src/framework/preferences/messages/localization.json b/src/framework/preferences/messages/localization.json new file mode 100644 index 0000000000..6996c13604 --- /dev/null +++ b/src/framework/preferences/messages/localization.json @@ -0,0 +1,11 @@ +{ + "localization-default": "Default", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localization", + "description": "Change the locale and/or language" +} diff --git a/src/framework/preferences/messages/localization_en.json b/src/framework/preferences/messages/localization_en.json new file mode 100644 index 0000000000..5f096508f7 --- /dev/null +++ b/src/framework/preferences/messages/localization_en.json @@ -0,0 +1,11 @@ +{ + "localization-default": "No Preference", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localization", + "description": "Change the locale and/or language" +} diff --git a/src/framework/preferences/messages/localization_en_CA.json b/src/framework/preferences/messages/localization_en_CA.json new file mode 100644 index 0000000000..5f096508f7 --- /dev/null +++ b/src/framework/preferences/messages/localization_en_CA.json @@ -0,0 +1,11 @@ +{ + "localization-default": "No Preference", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localization", + "description": "Change the locale and/or language" +} diff --git a/src/framework/preferences/messages/localization_en_US.json b/src/framework/preferences/messages/localization_en_US.json new file mode 100644 index 0000000000..5f096508f7 --- /dev/null +++ b/src/framework/preferences/messages/localization_en_US.json @@ -0,0 +1,11 @@ +{ + "localization-default": "No Preference", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localization", + "description": "Change the locale and/or language" +} diff --git a/src/framework/preferences/messages/localization_es.json b/src/framework/preferences/messages/localization_es.json new file mode 100644 index 0000000000..51d4cae27d --- /dev/null +++ b/src/framework/preferences/messages/localization_es.json @@ -0,0 +1,11 @@ +{ + "localization-default": "Sin preferencias", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localisation", + "description": "Ajustar la localización o el idioma" +} diff --git a/src/framework/preferences/messages/localization_fa.json b/src/framework/preferences/messages/localization_fa.json new file mode 100644 index 0000000000..3b19f9896b --- /dev/null +++ b/src/framework/preferences/messages/localization_fa.json @@ -0,0 +1,11 @@ +{ + "localization-default": "عدم ارجحیت", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "بومی سازی", + "description": "تغییر گویش و / یا زبان" +} diff --git a/src/framework/preferences/messages/localization_fr.json b/src/framework/preferences/messages/localization_fr.json new file mode 100644 index 0000000000..2834f4ac98 --- /dev/null +++ b/src/framework/preferences/messages/localization_fr.json @@ -0,0 +1,11 @@ +{ + "localization-default": "Pas de préférence", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Español", + "localization-fa": "فارسی", + "localization-fr": "Français", + "label": "Localisation", + "description": "Ajuster la localisation ou la langue" +} diff --git a/src/framework/preferences/preferencesDependencies.json b/src/framework/preferences/preferencesDependencies.json index bb439956da..e2b7286c8f 100644 --- a/src/framework/preferences/preferencesDependencies.json +++ b/src/framework/preferences/preferencesDependencies.json @@ -21,12 +21,14 @@ "./js/LetterSpacePanel.js", "./js/SelfVoicingPanel.js", "./js/SyllabificationPanel.js", + "./js/LocalizationPanel.js", "./js/WordSpacePanel.js", "./js/Enactors.js", "./js/CaptionsEnactor.js", "./js/LetterSpaceEnactor.js", "./js/SelfVoicingEnactor.js", "./js/SyllabificationEnactor.js", + "./js/LocalizationEnactor.js", "./js/WordSpaceEnactor.js", "./js/StarterGrades.js", "./js/ArrowScrolling.js", @@ -40,6 +42,8 @@ "./js/LetterSpaceSchemas.js", "./js/SelfVoicingSchemas.js", "./js/SyllabificationSchemas.js", + "./js/LocalizationSchemas.js", + "./js/LocalizationPrefsEditor.js", "./js/WordSpaceSchemas.js", "./js/Builder.js" ], diff --git a/tests/all-tests.html b/tests/all-tests.html index e8003d8a52..edcd160ffc 100644 --- a/tests/all-tests.html +++ b/tests/all-tests.html @@ -51,7 +51,6 @@ "/framework-tests/preferences/html/Enactors-test.html", "/framework-tests/preferences/html/FullNoPreviewPrefsEditor-test.html", "/framework-tests/preferences/html/FullPreviewPrefsEditor-test.html", - "/framework-tests/preferences/html/PageEnhancer-test.html", "/framework-tests/preferences/html/Panels-test.html", "/framework-tests/preferences/html/PrefsEditor-test.html", "/framework-tests/preferences/html/PrimaryBuilder-test.html", @@ -59,6 +58,8 @@ "/framework-tests/preferences/html/CaptionsPanel-test.html", "/framework-tests/preferences/html/LetterSpaceEnactor-test.html", "/framework-tests/preferences/html/LetterSpacePanel-test.html", + "/framework-tests/preferences/html/LocalizationEnactor-test.html", + "/framework-tests/preferences/html/LocalizationPanel-test.html", "/framework-tests/preferences/html/SelfVoicingEnactor-test.html", "/framework-tests/preferences/html/SyllabificationEnactor-test.html", "/framework-tests/preferences/html/SelfVoicingPanel-test.html", @@ -67,8 +68,10 @@ "/framework-tests/preferences/html/WordSpacePanel-test.html", "/framework-tests/preferences/html/SeparatedPanelPrefsEditor-test.html", "/framework-tests/preferences/html/SeparatedPanelPrefsEditorResponsive-test.html", + "/framework-tests/preferences/html/LocalizationPrefsEditor-test.html", "/framework-tests/preferences/html/Store-test.html", "/framework-tests/preferences/html/UIEnhancer-test.html", + "/framework-tests/preferences/html/PageEnhancer-test.html", "/framework-tests/preferences/html/URLUtilities-test.html", "/framework-tests/renderer/html/Renderer-test.html", "/framework-tests/renderer/html/RendererUtilities-test.html" diff --git a/tests/framework-tests/preferences/all-tests.html b/tests/framework-tests/preferences/all-tests.html index 6fedd2895a..2eb2598c7c 100644 --- a/tests/framework-tests/preferences/all-tests.html +++ b/tests/framework-tests/preferences/all-tests.html @@ -19,22 +19,25 @@ "./html/LetterSpaceEnactor-test.html", "./html/SelfVoicingEnactor-test.html", "./html/SyllabificationEnactor-test.html", + "./html/LocalizationEnactor-test.html", "./html/WordSpaceEnactor-test.html", - "./html/SeparatedPanelPrefsEditor-test.html", - "./html/SeparatedPanelPrefsEditorResponsive-test.html", - "./html/FullNoPreviewPrefsEditor-test.html", - "./html/FullPreviewPrefsEditor-test.html", - "./html/PageEnhancer-test.html", "./html/Panels-test.html", "./html/CaptionsPanel-test.html", "./html/LetterSpacePanel-test.html", "./html/SelfVoicingPanel-test.html", "./html/SyllabificationPanel-test.html", + "./html/LocalizationPanel-test.html", "./html/WordSpacePanel-test.html", "./html/PrimaryBuilder-test.html", "./html/Store-test.html", "./html/UIEnhancer-test.html", + "./html/PageEnhancer-test.html", "./html/PrefsEditor-test.html", + "./html/SeparatedPanelPrefsEditor-test.html", + "./html/SeparatedPanelPrefsEditorResponsive-test.html", + "./html/FullNoPreviewPrefsEditor-test.html", + "./html/FullPreviewPrefsEditor-test.html", + "./html/LocalizationPrefsEditor-test.html", "./html/URLUtilities-test.html" ]); diff --git a/tests/framework-tests/preferences/html/LocalizationEnactor-test.html b/tests/framework-tests/preferences/html/LocalizationEnactor-test.html new file mode 100644 index 0000000000..5e4b2ebcfb --- /dev/null +++ b/tests/framework-tests/preferences/html/LocalizationEnactor-test.html @@ -0,0 +1,56 @@ + + + + + Localization Enactor Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Localization Enactor Test Suite

+

+
+

+
    + + diff --git a/tests/framework-tests/preferences/html/LocalizationPanel-test.html b/tests/framework-tests/preferences/html/LocalizationPanel-test.html new file mode 100644 index 0000000000..454d10b5dc --- /dev/null +++ b/tests/framework-tests/preferences/html/LocalizationPanel-test.html @@ -0,0 +1,62 @@ + + + + + Localization Panel Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Localization Panel Test Suite

    +

    +
    +

    +
      + +
      + +
      + + + diff --git a/tests/framework-tests/preferences/html/LocalizationPrefsEditor-template.html b/tests/framework-tests/preferences/html/LocalizationPrefsEditor-template.html new file mode 100644 index 0000000000..3151a4f650 --- /dev/null +++ b/tests/framework-tests/preferences/html/LocalizationPrefsEditor-template.html @@ -0,0 +1,7 @@ +
      +
      + +
      +
      diff --git a/tests/framework-tests/preferences/html/LocalizationPrefsEditor-test.html b/tests/framework-tests/preferences/html/LocalizationPrefsEditor-test.html new file mode 100644 index 0000000000..e1e54ef875 --- /dev/null +++ b/tests/framework-tests/preferences/html/LocalizationPrefsEditor-test.html @@ -0,0 +1,98 @@ + + + + + Localization Prefs Editor Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

      Localization Prefs Editor Test Suite

      +

      +
      +

      +
        + + +
        + +
        +
        + +
        + + +
        +
        + +
        +
        + +
        +

        Some Sample Title

        +

        Some content with a link and .

        +
        + +
        + + + diff --git a/tests/framework-tests/preferences/js/LocalizationEnactorTests.js b/tests/framework-tests/preferences/js/LocalizationEnactorTests.js new file mode 100644 index 0000000000..4e3b6b5619 --- /dev/null +++ b/tests/framework-tests/preferences/js/LocalizationEnactorTests.js @@ -0,0 +1,236 @@ +/* +Copyright 2018-2019 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +/* global fluid, jqUnit */ + +(function ($) { + "use strict"; + + fluid.registerNamespace("fluid.tests"); + + /******************************************************************************* + * Unit tests for fluid.prefs.enactor.localization + *******************************************************************************/ + + fluid.defaults("fluid.tests.prefs.enactor.localizationEnactor", { + gradeNames: ["fluid.prefs.enactor.localization"], + model: { + lang: "" + }, + langMap: { + en: "", + "en-US": "en-US", + fr: "fr-CA" + }, + pathnames: { + default: "/about/", + english: "/about/en-US/", + french: "/about/fr-CA/" + }, + localizationScheme: "urlPath", + langSegIndex: 2 + }); + + fluid.tests.prefs.enactor.localizationEnactor.getPathname = function (that) { + return that.options.recordedPathname || that.options.pathnames["default"]; + }; + + fluid.tests.prefs.enactor.localizationEnactor.setPathname = function (that, pathname) { + that.options.recordedPathname = pathname; + }; + + fluid.defaults("fluid.tests.localizationTests", { + gradeNames: ["fluid.test.testEnvironment"], + components: { + localization: { + type: "fluid.tests.prefs.enactor.localizationEnactor", + createOnEvent: "{localizationTester}.events.onTestCaseStart", + options: { + invokers: { + getPathname: { + funcName: "fluid.tests.prefs.enactor.localizationEnactor.getPathname", + args: ["{that}"] + }, + setPathname: { + funcName: "fluid.tests.prefs.enactor.localizationEnactor.setPathname", + args: ["{that}", "{arguments}.0"] + } + } + } + }, + localizationTester: { + type: "fluid.tests.localizationTester" + } + } + }); + + fluid.defaults("fluid.tests.localizationTester", { + gradeNames: ["fluid.test.testCaseHolder"], + modules: [{ + name: "fluid.prefs.enactor.localization", + tests: [{ + expect: 10, + name: "Localization", + sequence: [{ + listener: "jqUnit.assert", + event: "{localizationTests localization}.events.onCreate", + args: ["The localization enactor was created"] + }, + { + func: "fluid.tests.localizationTester.assertLocale", + args: ["Init", "{localization}", { + lang: "" + }] + }, + { + // Change to en-US + func: "{localization}.applier.change", + args: ["lang", "en-US"] + }, + { + changeEvent: "{localization}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + listener: "fluid.tests.localizationTester.assertLocale", + args: ["English", "{localization}", { + lang: "en-US", + urlLangSeg: "en-US" + }, "{localization}.options.pathnames.english"] + }, + { + // Change to fr + func: "{localization}.applier.change", + args: ["lang", "fr"] + }, + { + changeEvent: "{localization}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + listener: "fluid.tests.localizationTester.assertLocale", + args: ["French", "{localization}", { + lang: "fr", + urlLangSeg: "fr-CA" + }, "{localization}.options.pathnames.french"] + }, + { + // Change to en + func: "{localization}.applier.change", + args: ["lang", "en"] + }, + { + changeEvent: "{localization}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + listener: "fluid.tests.localizationTester.assertLocale", + args: ["English", "{localization}", { + lang: "en", + urlLangSeg: "" + }, "{localization}.options.pathnames.default"] + }, + { + // Change to default + func: "{localization}.applier.change", + args: ["lang", "default"] + }, + { + changeEvent: "{localization}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + listener: "fluid.tests.localizationTester.assertLocale", + args: ["Set to Default", "{localization}", { + lang: "default", + urlLangSeg: "" + }] + }, + { + // Change to es + func: "{localization}.applier.change", + args: ["lang", "es"] + }, + { + changeEvent: "{localization}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + listener: "fluid.tests.localizationTester.assertLocale", + args: ["Unsupported Language", "{localization}", { + lang: "es", + urlLangSeg: "" + }] + }] + }] + }] + }); + + fluid.tests.localizationTester.assertLocale = function (prefix, that, expectedModel, pathname) { + jqUnit.assertDeepEq(prefix + ": The model property is set correctly: " + expectedModel.lang, expectedModel, that.model); + + if (pathname) { + jqUnit.assertEquals(prefix + ": The correct URL pathname is set", pathname, that.options.recordedPathname); + } + }; + + /********************************************************************************* + *Tests for referencing a global fluid.prefs.enactor.localization via model relay + ********************************************************************************/ + + fluid.defaults("fluid.tests.localizationExistingTests", { + gradeNames: ["fluid.test.testEnvironment"], + events: { + onLocalizationReady: null + }, + components: { + testComponent: { + type: "fluid.modelComponent", + createOnEvent: "onLocalizationReady", + options: { + model: { + lang: "{localization}.model.lang" + } + } + }, + tester: { + type: "fluid.tests.localizationExistingTester" + } + } + }); + + fluid.tests.localizationExistingTests.initLocalization = function (that) { + that.localization = fluid.prefs.enactor.localization(); + that.events.onDestroy.addListener(that.localization.destroy, "destroyLocalization"); + that.events.onLocalizationReady.fire(); + }; + + fluid.defaults("fluid.tests.localizationExistingTester", { + gradeNames: ["fluid.test.testCaseHolder"], + modules: [{ + name: "Global Localization", + tests: [{ + expect: 1, + name: "Model Relay", + sequence: [{ + funcName: "fluid.tests.localizationExistingTests.initLocalization", + args: ["{localizationExistingTests}"] + }, { + func: "{localizationExistingTests}.localization.applier.change", + args: ["lang", "en"] + }, { + changeEvent: "{testComponent}.applier.modelChanged", + spec: {path: "lang", priority: "last:testing"}, + func: "jqUnit.assertDeepEq", + args: ["The model relay to the global localization component should have updated the test component's model", {lang: "en"}, "{testComponent}.model"] + }] + }] + }] + }); + + $(document).ready(function () { + fluid.test.runTests([ + "fluid.tests.localizationTests", + "fluid.tests.localizationExistingTests" + ]); + }); + +})(jQuery); diff --git a/tests/framework-tests/preferences/js/LocalizationPanelTests.js b/tests/framework-tests/preferences/js/LocalizationPanelTests.js new file mode 100644 index 0000000000..3dc03578fa --- /dev/null +++ b/tests/framework-tests/preferences/js/LocalizationPanelTests.js @@ -0,0 +1,110 @@ +/* +Copyright 2018 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +/* global fluid, jqUnit */ + +(function ($) { + "use strict"; + + fluid.registerNamespace("fluid.tests"); + + fluid.defaults("fluid.tests.prefs.panel.localization", { + gradeNames: ["fluid.prefs.panel.localization", "fluid.tests.panels.utils.defaultTestPanel", "fluid.tests.panels.utils.injectTemplates"], + messageBase: { + "label": "Localization", + "description": "Change the locale and/or language", + "localization-default": "Default", + "localization-en": "English", + "localization-en_CA": "English (Canada)", + "localization-en_US": "English (USA)", + "localization-es": "Spanish", + "localization-fa": "Farsi", + "localization-fr": "French" + }, + model: { + value: "en" + }, + resources: { + template: { + href: "../../../../src/framework/preferences/html/PrefsEditorTemplate-localization.html" + } + } + }); + + fluid.defaults("fluid.tests.localizationPanelTests", { + gradeNames: ["fluid.test.testEnvironment"], + components: { + localization: { + type: "fluid.tests.prefs.panel.localization", + container: ".flc-localization", + createOnEvent: "{localizationTester}.events.onTestCaseStart" + }, + localizationTester: { + type: "fluid.tests.localizationTester" + } + } + }); + + fluid.defaults("fluid.tests.localizationTester", { + gradeNames: ["fluid.test.testCaseHolder"], + testOptions: { + expectedNumOfOptions: 5, + defaultValue: "en", + newValue: "fr" + }, + modules: [{ + name: "Test the localization settings panel", + tests: [{ + expect: 15, + name: "Test the rendering of the localization panel", + sequence: [{ + event: "{fluid.tests.localizationPanelTests localization}.events.afterRender", + priority: "last:testing", + listener: "fluid.tests.localizationTester.testDefault", + args: ["{localization}", "{that}.options.testOptions.expectedNumOfOptions", "{that}.options.testOptions.defaultValue"] + }, + { + func: "fluid.changeElementValue", + args: ["{localization}.dom.localization", "{that}.options.testOptions.newValue"] + }, + { + listener: "fluid.tests.panels.utils.checkModel", + args: ["value", "{localization}.model", "{that}.options.testOptions.newValue"], + spec: {path: "value", priority: "last:testing"}, + changeEvent: "{localization}.applier.modelChanged" + }] + }] + }] + }); + + fluid.tests.localizationTester.testDefault = function (that, expectedNumOfOptions, expectedLocale) { + var selectOptions = that.container.find("option"); + var messageBase = that.options.messageBase; + jqUnit.assertEquals("There are " + expectedNumOfOptions + " locales in the control", expectedNumOfOptions, selectOptions.length); + selectOptions.each(function (index, elm) { + elm = $(elm); + jqUnit.assertEquals("The language option at index: " + index + " has the correct value", that.options.controlValues.localization[index], elm.val()); + var stringArrayIndex = that.options.stringArrayIndex.localization[index]; + jqUnit.assertEquals("The language option at index: " + index + " has the correct text", messageBase[stringArrayIndex], elm.text()); + }); + + jqUnit.assertEquals("The selected locale is " + expectedLocale, expectedLocale, selectOptions.filter(":selected").val()); + jqUnit.assertEquals("The label text is " + messageBase.label, messageBase.label, that.locate("label").text()); + jqUnit.assertEquals("The description text is " + messageBase.description, messageBase.description, that.locate("localizationDescr").text()); + }; + + $(document).ready(function () { + fluid.test.runTests([ + "fluid.tests.localizationPanelTests" + ]); + }); + +})(jQuery); diff --git a/tests/framework-tests/preferences/js/LocalizationPrefsEditorTests.js b/tests/framework-tests/preferences/js/LocalizationPrefsEditorTests.js new file mode 100644 index 0000000000..befbdcfc97 --- /dev/null +++ b/tests/framework-tests/preferences/js/LocalizationPrefsEditorTests.js @@ -0,0 +1,149 @@ +/* +Copyright 2019 OCAD University + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt +*/ + +/* global fluid */ + +(function ($) { + "use strict"; + + fluid.registerNamespace("fluid.tests"); + + + // Using the builder to create an instance of a prefs editor from the `fluid.prefs.auxSchema.localization` schema. + // The assembled grade is `fluid.tests.prefs.localization.prefsEditor`. + fluid.prefs.builder({ + gradeNames: ["fluid.prefs.auxSchema.localization"], + auxiliarySchema: { + "namespace": "fluid.tests.prefs.localization", + "terms": { + "templatePrefix": "../../../../src/framework/preferences/html", + "messagePrefix": "../../../../src/framework/preferences/messages" + }, + "template": "LocalizationPrefsEditor-template.html" + } + }); + + fluid.defaults("fluid.tests.localizationPrefsEditor", { + gradeNames: ["fluid.tests.prefs.localization.prefsEditor", "fluid.prefs.constructed.localizationPrefsEditorConfig"], + localizationScheme: "urlPath", + localeNames: ["localization-default", "localization-en", "localization-fr", "localization-es", "localization-fa"], + locales: ["", "en", "en-ca", "fr", "es", "fa"], + langMap: { + "en": "", + "en-ca": "en-Ca", + "es": "es", + "fa": "fa", + "fr": "fr" + }, + langSegIndex: 2, + defaultLocale: "fr" + }); + + fluid.defaults("fluid.tests.localizationPrefsEditorTests", { + gradeNames: ["fluid.test.testEnvironment"], + components: { + localizationPrefsEditor: { + type: "fluid.tests.localizationPrefsEditor", + container: ".flc-prefsEditor-separatedPanel", + createOnEvent: "{localizationPrefsEditorTester}.events.onTestCaseStart" + }, + localizationPrefsEditorTester: { + type: "fluid.tests.localizationPrefsEditorTester" + } + } + }); + + fluid.defaults("fluid.tests.localizationPrefsEditorTester", { + gradeNames: ["fluid.test.testCaseHolder"], + testOpts: { + localizationScheme: "urlPath", + localeNames: ["localization-default", "localization-en", "localization-fr", "localization-es", "localization-fa"], + locales: ["", "en", "en-ca", "fr", "es", "fa"], + langMap: { + "en": "", + "en-ca": "en-Ca", + "es": "es", + "fa": "fa", + "fr": "fr" + }, + langSegIndex: 2, + defaultLocale: "fr" + }, + modules: [{ + name: "fluid.prefs.constructed.localizationPrefsEditorConfig", + tests: [{ + expect: 7, + name: "Options Distributions", + sequence: [{ + // Init + listener: "jqUnit.assert", + event: "{localizationPrefsEditorTests localizationPrefsEditor}.events.onReady", + args: ["The prefs editor was created"] + }, { + // `defaultLocale` distributed to prefsEditorLoader + func: "jqUnit.assertEquals", + args: [ + "The defaultLocale is passed to the prefsEditorLoader", + "{that}.options.testOpts.defaultLocale", + "{localizationPrefsEditor}.prefsEditorLoader.options.defaultLocale" + ] + }, { + // `locales` distributed to localization panel + func: "jqUnit.assertDeepEq", + args: [ + "The localization panel's control values are set", + "{that}.options.testOpts.locales", + "{localizationPrefsEditor}.prefsEditorLoader.prefsEditor.fluid_prefs_panel_localization.options.controlValues.localization" + ] + }, { + // `localeNames` distributed to localization panel + func: "jqUnit.assertDeepEq", + args: [ + "The localization panel's localization options have been set", + "{that}.options.testOpts.localeNames", + "{localizationPrefsEditor}.prefsEditorLoader.prefsEditor.fluid_prefs_panel_localization.options.stringArrayIndex.localization" + ] + }, { + // `localizationScheme` distributed to localization enactor + func: "jqUnit.assertEquals", + args: [ + "The localization enactor's localizationScheme is set", + "{that}.options.testOpts.localizationScheme", + "{localizationPrefsEditor}.enhancer.uiEnhancer.fluid_prefs_enactor_localization.options.localizationScheme" + ] + }, { + // `langMap` distributed to localization enactor + func: "jqUnit.assertDeepEq", + args: [ + "The localization enactor's langMap is set", + "{that}.options.testOpts.langMap", + "{localizationPrefsEditor}.enhancer.uiEnhancer.fluid_prefs_enactor_localization.options.langMap" + ] + }, { + // `langSegIndex` distributed to localization enactor + func: "jqUnit.assertEquals", + args: [ + "The localization enactor's langSegIndex is set", + "{that}.options.testOpts.langSegIndex", + "{localizationPrefsEditor}.enhancer.uiEnhancer.fluid_prefs_enactor_localization.options.langSegIndex" + ] + }] + }] + }] + }); + + $(document).ready(function () { + fluid.test.runTests([ + "fluid.tests.localizationPrefsEditorTests" + ]); + }); + +})(jQuery);