]> git.openstreetmap.org Git - rails.git/commitdiff
Update to iD v2.18.1
authorQuincy Morgan <2046746+quincylvania@users.noreply.github.com>
Mon, 20 Jul 2020 20:12:50 +0000 (16:12 -0400)
committerQuincy Morgan <2046746+quincylvania@users.noreply.github.com>
Mon, 20 Jul 2020 20:12:50 +0000 (16:12 -0400)
vendor/assets/iD/iD.js
vendor/assets/iD/iD/locales/en.json

index 337d13faeee6fac0b5b19e5de225941960f4696f..72e021e610db566a7dff62349e2a07971bac14a3 100644 (file)
            localizer.scriptNames = () => _scriptNames;
 
 
+           // The client app may want to manually set the locale, regardless of the
+           // settings provided by the browser
+           let _preferredLocaleCodes = [];
+           localizer.preferredLocaleCodes = function(codes) {
+               if (!arguments.length) return _preferredLocaleCodes;
+               if (typeof codes === 'string') {
+                   // be generous and accept delimited strings as input
+                   _preferredLocaleCodes = codes.split(/,|;| /gi).filter(Boolean);
+               } else {
+                   _preferredLocaleCodes = codes;
+               }
+               return localizer;
+           };
+
+
            var _loadPromise;
 
            localizer.ensureLoaded = () => {
                        _dataLocales = results[1];
                    })
                    .then(() => {
-                       const hash = utilStringQs(window.location.hash);
-
-                       if (hash.locale && _dataLocales[hash.locale]) {
-                           // the locale can be manually set in the URL hash
-                           _localeCode = hash.locale;
-                       } else {
-                           // otherwise use the locale specified by the browser
-                           _localeCode = supportedBrowserLocale();
-                       }
+                       let requestedLocales = (_preferredLocaleCodes || [])
+                           // list of locales preferred by the browser in priority order
+                           .concat(utilDetect().browserLocales);
+                       _localeCode = bestSupportedLocale(requestedLocales);
 
                        return Promise.all([
                            // always load the English locale strings as fallbacks
                    .catch(err => console.error(err));  // eslint-disable-line
            };
 
-           // Returns the best locale requested by the browser supported by iD, if any
-           function supportedBrowserLocale() {
-               // list of locales preferred by the browser in priority order
-               let browserLocales = utilDetect().browserLocales;
+           // Returns the best locale from `locales` supported by iD, if any
+           function bestSupportedLocale(locales) {
                let supportedLocales = _dataLocales;
 
-               for (let i in browserLocales) {
-                   let browserLocale = browserLocales[i];
-                   if (browserLocale.includes('-')) { // full locale ('es-ES')
+               for (let i in locales) {
+                   let locale = locales[i];
+                   if (locale.includes('-')) { // full locale ('es-ES')
 
-                       if (supportedLocales[browserLocale]) return browserLocale;
+                       if (supportedLocales[locale]) return locale;
 
                        // If full locale not supported ('es-FAKE'), fallback to the base ('es')
-                       let langPart = browserLocale.split('-')[0];
+                       let langPart = locale.split('-')[0];
                        if (supportedLocales[langPart]) return langPart;
 
                    } else { // base locale ('es')
 
                        // prefer a lower-priority full locale with this base ('es' < 'es-ES')
-                       let fullLocale = browserLocales.find((locale, index) => {
+                       let fullLocale = locales.find((locale2, index) => {
                            return index > i &&
-                               locale !== browserLocale &&
-                               locale.split('-')[0] === browserLocale &&
-                               supportedLocales[locale];
+                               locale2 !== locale &&
+                               locale2.split('-')[0] === locale &&
+                               supportedLocales[locale2];
                        });
                        if (fullLocale) return fullLocale;
 
-                       if (supportedLocales[browserLocale]) return browserLocale;
+                       if (supportedLocales[locale]) return locale;
                    }
                }
 
            if (sawVersion === null && matchedVersion !== null) {
                if (corePreferences('sawVersion')) {
                    isNewUser = false;
-                   isNewVersion = corePreferences('sawVersion') !== currVersion;
+                   isNewVersion = corePreferences('sawVersion') !== currVersion && currVersion.indexOf('-') === -1;
                } else {
                    isNewUser = true;
                    isNewVersion = true;
          let context = utilRebind({}, dispatch$1, 'on');
          let _deferred = new Set();
 
-         context.version = '2.18.0';
+         context.version = '2.18.1';
          context.privacyVersion = '20200407';
 
          // iD will alter the hash so cache the parameters intended to setup the session
          };
 
 
+         // A string or array or locale codes to prefer over the browser's settings
+         context.locale = function(locale) {
+           if (!arguments.length) return _mainLocalizer.localeCode();
+           _mainLocalizer.preferredLocaleCodes(locale);
+           return context;
+         };
+
+
          function afterLoad(cid, callback) {
            return (err, result) => {
              if (err) {
                _mainPresetIndex.addablePresetIDs(new Set(context.initialHashParams.presets.split(',')));
              }
 
+             if (context.initialHashParams.locale) {
+               _mainLocalizer.preferredLocaleCodes(context.initialHashParams.locale);
+             }
+
              // kick off some async work
              _mainLocalizer.ensureLoaded();
              _background.ensureLoaded();
index 035a67642f9fe8270749992d7fd9c4079957f716..5f051d1dafd21908e538266ad7cff92f209614fa 100644 (file)
                 },
                 "shop/craft": {
                     "name": "Arts & Crafts Store",
-                    "terms": "art*,paint*,frame"
+                    "terms": "art*,paint*,frame,hobby"
                 },
                 "shop/curtain": {
                     "name": "Curtain Store",