FLUID-6303: Implement a panel, adjuster and enactor for locale

Metadata

Source
FLUID-6303
Type
Task
Priority
Major
Status
Closed
Resolution
Fixed
Assignee
Gregor Moss
Reporter
Gregor Moss
Created
2018-07-17T16:51:33.501-0400
Updated
2019-01-23T16:19:21.825-0500
Versions
N/A
Fixed Versions
N/A
Component
  1. UI Options

Description

Implement a panel, adjuster and enactor for locale selection

The enactor need not be fully implemented. It could simply offer a point of integration that is left to the developer's discretion.

Some prior art in https://github.com/GPII/first-discovery (note that the page reloads every time the locale is changed in this project)

Comments

  • Justin Obara commented 2018-12-17T07:50:44.673-0500

    I spoke with @@Antranig Basman in the fluid-work channel today ( http://irc-logs.fluidproject.org/%23fluid-work/%23fluid-work.2018-12-17.log ) about the issue of configuring the language panel with the schema version of the prefs framework. Typically when using the schemas, a primary schema is created that contains the potential values of a preference. For language this is problematic because each integration would have their own set of supported languages. It seems the best we can do now is to have the integrator configure the panel settings against the built prefs editor, that is after the schemas have been compiled and a  prefs editor grade is generated. Antranig, suggested that we could add a helpful utility for it.

  • Justin Obara commented 2018-12-18T08:44:38.515-0500

    Also from my discussion with @@Antranig Basman in the fluid-work channel yesterday ( http://irc-logs.fluidproject.org/%23fluid-work/%23fluid-work.2018-12-17.log ), we will setup the enactor to use contextAwareness to switch between the various methods for applying the language change.

  • Justin Obara commented 2018-12-20T12:28:19.963-0500

    Was going to add code to modify the query parameters to change the locale. However, it seems that the "fluid.prefs.enactor.localization.queryParamLocale.search" method held much of the logic and would need to be mocked out in a test. Because we don't actually have a use case for this type of locale change, and the difficulty in testing, I've decided to leave it out, but the code is provided below if we'd like to implement it later.

    /*******************************************************************************
         * Query Parameter
         *
         * Changes a query parameter to specify which language should be displayed.
         * E.g. www.example.com?lang=en
         *******************************************************************************/
        fluid.defaults("fluid.prefs.enactor.localization.queryParamLocale", {
            langMap: {}, // must be supplied by integrator
            langParam: "lang",
            model: {
                langParam: {
                    expander: {
                        func: "{that}.search"
                    }
                }
            },
            modelRelay: {
                "setLangParam": {
                    source: "lang",
                    target: "langParam",
                    singleTransform: {
                        type: "fluid.transforms.valueMapper",
                        match: "{that}.options.langMap"
                    }
                }
            },
            modelListeners: {
                langParam: {
                    funcName: "{that}.search",
                    args: ["{change}.value"],
                    namespace: "setLangParam"
                }
            },
            listeners: {
                "onCreate.setURLPath": {
                    changePath: "urlPathname",
                    value: {
                        expander: {
                            func: "{that}.pathname"
                        }
                    },
                    source: "initialURLPathname"
                }
            },
            invokers: {
                search: {
                    funcName: "fluid.prefs.enactor.localization.queryParamLocale.search",
                    args: ["{that}.options.langParam", "{arguments}.0"]
                }
            }
        });    /**
         * A simple wrapper around the location.search setter/getter property. However, it does not simply set and return
         * the entire search/query string, but rather takes in a specific property to act upon.
         *
         * @param {String} searchString - (Optional) searchString to set. If not supplied the current searchString will be returned
         * @return {String} - If the `searchString` argument is not provided, the current searchString is returned
         */
        fluid.prefs.enactor.localization.queryParamLocale.search = function (property, value) {
            var params = new URLSearchParams(location.search);
            var currentValue = params.get(property);        if (!value) {
                return params.get(property);
            } else if (currentValue !== value) {
                params.set(property, value);
                location.search = params.toString();
            }
        };
    
  • Cindy Li commented 2019-01-23T16:18:20.259-0500

    @@Justin Obara issued the initial pull request that was based off for the 2nd pull request, which was to address the last minor code review comment on the initial pull request when @@Justin Obara is on vacation. The 2nd pull request has been merged into the project repo master branch at this commit.

    FLUID-6363 is recreated for @@Justin Obara to re-visit the change made in the 2nd pull request.

    FLUID-6364 is created for the re-examination of the user experience of setting languages thru the localization panel.