@edx/frontend-platform 3.6.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analytics/MockAnalyticsService.js +31 -19
- package/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js +53 -57
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/analytics/index.js.map +1 -1
- package/analytics/interface.js +9 -9
- package/analytics/interface.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js +36 -58
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js +105 -150
- package/auth/AxiosJwtAuthService.js.map +1 -1
- package/auth/AxiosJwtTokenService.js +101 -148
- package/auth/AxiosJwtTokenService.js.map +1 -1
- package/auth/LocalForageCache.js +89 -108
- package/auth/LocalForageCache.js.map +1 -1
- package/auth/MockAuthService.js +114 -43
- package/auth/MockAuthService.js.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js +35 -50
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.js +33 -47
- package/auth/interceptors/createJwtTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js +15 -27
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +1 -1
- package/auth/interceptors/createRetryInterceptor.js +75 -105
- package/auth/interceptors/createRetryInterceptor.js.map +1 -1
- package/auth/interface.js +41 -58
- package/auth/interface.js.map +1 -1
- package/auth/utils.js +22 -40
- package/auth/utils.js.map +1 -1
- package/config.js +6 -7
- package/config.js.map +1 -1
- package/constants.js +8 -8
- package/constants.js.map +1 -1
- package/i18n/countries.js +9 -15
- package/i18n/countries.js.map +1 -1
- package/i18n/index.js +1 -0
- package/i18n/index.js.map +1 -1
- package/i18n/injectIntlWithShim.js +4 -28
- package/i18n/injectIntlWithShim.js.map +1 -1
- package/i18n/languages.js +11 -17
- package/i18n/languages.js.map +1 -1
- package/i18n/lib.js +64 -56
- package/i18n/lib.js.map +1 -1
- package/i18n/scripts/transifex-utils.js +5 -20
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/index.js.map +1 -1
- package/initialize.js +176 -228
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js +15 -9
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js +9 -33
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/index.js.map +1 -1
- package/logging/interface.js +7 -6
- package/logging/interface.js.map +1 -1
- package/package.json +4 -4
- package/pubSub.js +4 -3
- package/pubSub.js.map +1 -1
- package/react/AppContext.js +1 -1
- package/react/AppContext.js.map +1 -1
- package/react/AppProvider.js +13 -23
- package/react/AppProvider.js.map +1 -1
- package/react/AuthenticatedPageRoute.js +5 -13
- package/react/AuthenticatedPageRoute.js.map +1 -1
- package/react/ErrorBoundary.js +4 -21
- package/react/ErrorBoundary.js.map +1 -1
- package/react/ErrorPage.js +7 -17
- package/react/ErrorPage.js.map +1 -1
- package/react/LoginRedirect.js +1 -1
- package/react/LoginRedirect.js.map +1 -1
- package/react/OptionalReduxProvider.js +2 -4
- package/react/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js +3 -3
- package/react/PageRoute.js.map +1 -1
- package/react/hooks.js +2 -6
- package/react/hooks.js.map +1 -1
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/testing/index.js +1 -0
- package/testing/index.js.map +1 -1
- package/testing/initializeMockApp.js +11 -11
- package/testing/initializeMockApp.js.map +1 -1
- package/testing/mockMessages.js.map +1 -1
- package/utils.js +15 -24
- package/utils.js.map +1 -1
package/i18n/lib.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
|
|
3
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
4
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
-
|
|
9
5
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
|
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
|
-
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
7
|
import PropTypes from 'prop-types';
|
|
14
8
|
import Cookies from 'universal-cookie';
|
|
15
9
|
import merge from 'lodash.merge';
|
|
@@ -44,32 +38,53 @@ import '@formatjs/intl-relativetimeformat/locale-data/ru';
|
|
|
44
38
|
import '@formatjs/intl-relativetimeformat/locale-data/th';
|
|
45
39
|
import '@formatjs/intl-relativetimeformat/locale-data/uk';
|
|
46
40
|
var cookies = new Cookies();
|
|
47
|
-
var supportedLocales = ['ar',
|
|
41
|
+
var supportedLocales = ['ar',
|
|
42
|
+
// Arabic
|
|
48
43
|
// NOTE: 'en' is not included in this list intentionally, since it's the fallback.
|
|
49
|
-
'es-419',
|
|
50
|
-
|
|
51
|
-
'fa
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
|
|
55
|
-
'
|
|
56
|
-
|
|
57
|
-
'
|
|
58
|
-
|
|
59
|
-
'
|
|
60
|
-
|
|
61
|
-
'
|
|
44
|
+
'es-419',
|
|
45
|
+
// Spanish, Latin American
|
|
46
|
+
'fa',
|
|
47
|
+
// Farsi
|
|
48
|
+
'fa-ir',
|
|
49
|
+
// Farsi, Iran
|
|
50
|
+
'fr',
|
|
51
|
+
// French
|
|
52
|
+
'zh-cn',
|
|
53
|
+
// Chinese, Simplified
|
|
54
|
+
'ca',
|
|
55
|
+
// Catalan
|
|
56
|
+
'he',
|
|
57
|
+
// Hebrew
|
|
58
|
+
'id',
|
|
59
|
+
// Indonesian
|
|
60
|
+
'ko-kr',
|
|
61
|
+
// Korean (Korea)
|
|
62
|
+
'pl',
|
|
63
|
+
// Polish
|
|
64
|
+
'pt-br',
|
|
65
|
+
// Portuguese (Brazil)
|
|
66
|
+
'ru',
|
|
67
|
+
// Russian
|
|
68
|
+
'th',
|
|
69
|
+
// Thai
|
|
62
70
|
'uk' // Ukrainian
|
|
63
71
|
];
|
|
64
|
-
|
|
65
|
-
'
|
|
66
|
-
|
|
67
|
-
'
|
|
72
|
+
|
|
73
|
+
var rtlLocales = ['ar',
|
|
74
|
+
// Arabic
|
|
75
|
+
'he',
|
|
76
|
+
// Hebrew
|
|
77
|
+
'fa',
|
|
78
|
+
// Farsi (not currently supported)
|
|
79
|
+
'fa-ir',
|
|
80
|
+
// Farsi Iran
|
|
68
81
|
'ur' // Urdu (not currently supported)
|
|
69
82
|
];
|
|
83
|
+
|
|
70
84
|
var config = null;
|
|
71
85
|
var loggingService = null;
|
|
72
86
|
var messages = null;
|
|
87
|
+
|
|
73
88
|
/**
|
|
74
89
|
* @memberof module:Internationalization
|
|
75
90
|
*
|
|
@@ -80,36 +95,36 @@ var messages = null;
|
|
|
80
95
|
*
|
|
81
96
|
* @deprecated
|
|
82
97
|
*/
|
|
83
|
-
|
|
84
98
|
export var intlShape = PropTypes.object;
|
|
99
|
+
|
|
85
100
|
/**
|
|
86
101
|
*
|
|
87
102
|
* @ignore
|
|
88
103
|
* @returns {LoggingService}
|
|
89
104
|
*/
|
|
90
|
-
|
|
91
105
|
export var getLoggingService = function getLoggingService() {
|
|
92
106
|
return loggingService;
|
|
93
107
|
};
|
|
108
|
+
|
|
94
109
|
/**
|
|
95
110
|
* @memberof module:Internationalization
|
|
96
111
|
*/
|
|
97
|
-
|
|
98
112
|
export var LOCALE_TOPIC = 'LOCALE';
|
|
113
|
+
|
|
99
114
|
/**
|
|
100
115
|
* @memberof module:Internationalization
|
|
101
116
|
*/
|
|
102
|
-
|
|
103
117
|
export var LOCALE_CHANGED = "".concat(LOCALE_TOPIC, ".CHANGED");
|
|
118
|
+
|
|
104
119
|
/**
|
|
105
120
|
*
|
|
106
121
|
* @memberof module:Internationalization
|
|
107
122
|
* @returns {Cookies}
|
|
108
123
|
*/
|
|
109
|
-
|
|
110
124
|
export function getCookies() {
|
|
111
125
|
return cookies;
|
|
112
126
|
}
|
|
127
|
+
|
|
113
128
|
/**
|
|
114
129
|
* Some of our dependencies function on primary language subtags, rather than full locales.
|
|
115
130
|
* This function strips a locale down to that first subtag. Depending on the code, this
|
|
@@ -118,10 +133,10 @@ export function getCookies() {
|
|
|
118
133
|
* @param {string} code
|
|
119
134
|
* @memberof module:Internationalization
|
|
120
135
|
*/
|
|
121
|
-
|
|
122
136
|
export function getPrimaryLanguageSubtag(code) {
|
|
123
137
|
return code.split('-')[0];
|
|
124
138
|
}
|
|
139
|
+
|
|
125
140
|
/**
|
|
126
141
|
* Finds the closest supported locale to the one provided. This is done in three steps:
|
|
127
142
|
*
|
|
@@ -134,18 +149,16 @@ export function getPrimaryLanguageSubtag(code) {
|
|
|
134
149
|
* @returns {string}
|
|
135
150
|
* @memberof module:Internationalization
|
|
136
151
|
*/
|
|
137
|
-
|
|
138
152
|
export function findSupportedLocale(locale) {
|
|
139
153
|
if (messages[locale] !== undefined) {
|
|
140
154
|
return locale;
|
|
141
155
|
}
|
|
142
|
-
|
|
143
156
|
if (messages[getPrimaryLanguageSubtag(locale)] !== undefined) {
|
|
144
157
|
return getPrimaryLanguageSubtag(locale);
|
|
145
158
|
}
|
|
146
|
-
|
|
147
159
|
return 'en';
|
|
148
160
|
}
|
|
161
|
+
|
|
149
162
|
/**
|
|
150
163
|
* Get the locale from the cookie or, failing that, the browser setting.
|
|
151
164
|
* Gracefully fall back to a more general primary language subtag or to English (en)
|
|
@@ -156,30 +169,26 @@ export function findSupportedLocale(locale) {
|
|
|
156
169
|
* @returns {string}
|
|
157
170
|
* @memberof module:Internationalization
|
|
158
171
|
*/
|
|
159
|
-
|
|
160
172
|
export function getLocale(locale) {
|
|
161
173
|
if (messages === null) {
|
|
162
174
|
throw new Error('getLocale called before configuring i18n. Call configure with messages first.');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
175
|
+
}
|
|
176
|
+
// 1. Explicit application request
|
|
166
177
|
if (locale !== undefined) {
|
|
167
178
|
return findSupportedLocale(locale);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
}
|
|
180
|
+
// 2. User setting in cookie
|
|
171
181
|
var cookieLangPref = cookies.get(config.LANGUAGE_PREFERENCE_COOKIE_NAME);
|
|
172
|
-
|
|
173
182
|
if (cookieLangPref) {
|
|
174
183
|
return findSupportedLocale(cookieLangPref.toLowerCase());
|
|
175
|
-
}
|
|
184
|
+
}
|
|
185
|
+
// 3. Browser language (default)
|
|
176
186
|
// Note that some browers prefer upper case for the region part of the locale, while others don't.
|
|
177
187
|
// Thus the toLowerCase, for consistency.
|
|
178
188
|
// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language
|
|
179
|
-
|
|
180
|
-
|
|
181
189
|
return findSupportedLocale(global.navigator.language.toLowerCase());
|
|
182
190
|
}
|
|
191
|
+
|
|
183
192
|
/**
|
|
184
193
|
* Returns messages for the provided locale, or the user's preferred locale if no argument is
|
|
185
194
|
* provided.
|
|
@@ -187,28 +196,27 @@ export function getLocale(locale) {
|
|
|
187
196
|
* @param {string} [locale=getLocale()]
|
|
188
197
|
* @memberof module:Internationalization
|
|
189
198
|
*/
|
|
190
|
-
|
|
191
199
|
export function getMessages() {
|
|
192
200
|
var locale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getLocale();
|
|
193
201
|
return messages[locale];
|
|
194
202
|
}
|
|
203
|
+
|
|
195
204
|
/**
|
|
196
205
|
* Determines if the provided locale is a right-to-left language.
|
|
197
206
|
*
|
|
198
207
|
* @param {string} locale
|
|
199
208
|
* @memberof module:Internationalization
|
|
200
209
|
*/
|
|
201
|
-
|
|
202
210
|
export function isRtl(locale) {
|
|
203
211
|
return rtlLocales.includes(locale);
|
|
204
212
|
}
|
|
213
|
+
|
|
205
214
|
/**
|
|
206
215
|
* Handles applying the RTL stylesheet and "dir=rtl" attribute to the html tag if the current locale
|
|
207
216
|
* is a RTL language.
|
|
208
217
|
*
|
|
209
218
|
* @memberof module:Internationalization
|
|
210
219
|
*/
|
|
211
|
-
|
|
212
220
|
export function handleRtl() {
|
|
213
221
|
if (isRtl(getLocale())) {
|
|
214
222
|
global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');
|
|
@@ -243,8 +251,8 @@ var messagesShape = {
|
|
|
243
251
|
th: PropTypes.objectOf(PropTypes.string),
|
|
244
252
|
// Thai
|
|
245
253
|
uk: PropTypes.objectOf(PropTypes.string) // Ukrainian
|
|
246
|
-
|
|
247
254
|
};
|
|
255
|
+
|
|
248
256
|
var optionsShape = {
|
|
249
257
|
config: PropTypes.object.isRequired,
|
|
250
258
|
loggingService: PropTypes.shape({
|
|
@@ -252,6 +260,7 @@ var optionsShape = {
|
|
|
252
260
|
}).isRequired,
|
|
253
261
|
messages: PropTypes.oneOfType([PropTypes.shape(messagesShape), PropTypes.arrayOf(PropTypes.shape(messagesShape))]).isRequired
|
|
254
262
|
};
|
|
263
|
+
|
|
255
264
|
/**
|
|
256
265
|
*
|
|
257
266
|
*
|
|
@@ -259,11 +268,11 @@ var optionsShape = {
|
|
|
259
268
|
* @returns {Object}
|
|
260
269
|
* @memberof module:Internationalization
|
|
261
270
|
*/
|
|
262
|
-
|
|
263
271
|
export function mergeMessages() {
|
|
264
272
|
var messagesArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
265
273
|
return Array.isArray(messagesArray) ? merge.apply(void 0, [{}].concat(_toConsumableArray(messagesArray))) : {};
|
|
266
274
|
}
|
|
275
|
+
|
|
267
276
|
/**
|
|
268
277
|
* Configures the i18n library with messages for your application.
|
|
269
278
|
*
|
|
@@ -276,21 +285,20 @@ export function mergeMessages() {
|
|
|
276
285
|
* @param {Object} options.messages
|
|
277
286
|
* @memberof module:Internationalization
|
|
278
287
|
*/
|
|
279
|
-
|
|
280
288
|
export function configure(options) {
|
|
281
|
-
PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');
|
|
282
|
-
|
|
283
|
-
loggingService = options.loggingService;
|
|
284
|
-
|
|
289
|
+
PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');
|
|
290
|
+
// eslint-disable-next-line prefer-destructuring
|
|
291
|
+
loggingService = options.loggingService;
|
|
292
|
+
// eslint-disable-next-line prefer-destructuring
|
|
285
293
|
config = options.config;
|
|
286
294
|
messages = Array.isArray(options.messages) ? mergeMessages(options.messages) : options.messages;
|
|
287
|
-
|
|
288
295
|
if (config.ENVIRONMENT !== 'production') {
|
|
289
296
|
Object.keys(messages).forEach(function (key) {
|
|
290
297
|
if (supportedLocales.indexOf(key) < 0) {
|
|
291
298
|
console.warn("Unexpected locale: ".concat(key)); // eslint-disable-line no-console
|
|
292
299
|
}
|
|
293
300
|
});
|
|
301
|
+
|
|
294
302
|
supportedLocales.forEach(function (key) {
|
|
295
303
|
if (messages[key] === undefined) {
|
|
296
304
|
console.warn("Missing locale: ".concat(key)); // eslint-disable-line no-console
|
package/i18n/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","names":["PropTypes","Cookies","merge","cookies","supportedLocales","rtlLocales","config","loggingService","messages","intlShape","object","getLoggingService","LOCALE_TOPIC","LOCALE_CHANGED","getCookies","getPrimaryLanguageSubtag","code","split","findSupportedLocale","locale","undefined","getLocale","Error","cookieLangPref","get","LANGUAGE_PREFERENCE_COOKIE_NAME","toLowerCase","global","navigator","language","getMessages","isRtl","includes","handleRtl","document","getElementsByTagName","setAttribute","messagesShape","ar","objectOf","string","en","fr","ca","he","id","pl","ru","th","uk","optionsShape","isRequired","shape","logError","func","oneOfType","arrayOf","mergeMessages","messagesArray","Array","isArray","configure","options","checkPropTypes","ENVIRONMENT","Object","keys","forEach","key","indexOf","console","warn"],"sources":["../../src/i18n/lib.js"],"sourcesContent":["import PropTypes from 'prop-types';\nimport Cookies from 'universal-cookie';\nimport merge from 'lodash.merge';\n\nimport '@formatjs/intl-pluralrules/polyfill';\nimport '@formatjs/intl-pluralrules/locale-data/ar';\nimport '@formatjs/intl-pluralrules/locale-data/en';\nimport '@formatjs/intl-pluralrules/locale-data/es';\nimport '@formatjs/intl-pluralrules/locale-data/fr';\nimport '@formatjs/intl-pluralrules/locale-data/zh';\nimport '@formatjs/intl-pluralrules/locale-data/ca';\nimport '@formatjs/intl-pluralrules/locale-data/he';\nimport '@formatjs/intl-pluralrules/locale-data/id';\nimport '@formatjs/intl-pluralrules/locale-data/ko';\nimport '@formatjs/intl-pluralrules/locale-data/pl';\nimport '@formatjs/intl-pluralrules/locale-data/pt';\nimport '@formatjs/intl-pluralrules/locale-data/ru';\nimport '@formatjs/intl-pluralrules/locale-data/th';\nimport '@formatjs/intl-pluralrules/locale-data/uk';\n\nimport '@formatjs/intl-relativetimeformat/polyfill';\nimport '@formatjs/intl-relativetimeformat/locale-data/ar';\nimport '@formatjs/intl-relativetimeformat/locale-data/en';\nimport '@formatjs/intl-relativetimeformat/locale-data/es';\nimport '@formatjs/intl-relativetimeformat/locale-data/fr';\nimport '@formatjs/intl-relativetimeformat/locale-data/zh';\nimport '@formatjs/intl-relativetimeformat/locale-data/ca';\nimport '@formatjs/intl-relativetimeformat/locale-data/he';\nimport '@formatjs/intl-relativetimeformat/locale-data/id';\nimport '@formatjs/intl-relativetimeformat/locale-data/ko';\nimport '@formatjs/intl-relativetimeformat/locale-data/pl';\nimport '@formatjs/intl-relativetimeformat/locale-data/pt';\nimport '@formatjs/intl-relativetimeformat/locale-data/ru';\nimport '@formatjs/intl-relativetimeformat/locale-data/th';\nimport '@formatjs/intl-relativetimeformat/locale-data/uk';\n\nconst cookies = new Cookies();\nconst supportedLocales = [\n 'ar', // Arabic\n // NOTE: 'en' is not included in this list intentionally, since it's the fallback.\n 'es-419', // Spanish, Latin American\n 'fa', // Farsi\n 'fa-ir', // Farsi, Iran\n 'fr', // French\n 'zh-cn', // Chinese, Simplified\n 'ca', // Catalan\n 'he', // Hebrew\n 'id', // Indonesian\n 'ko-kr', // Korean (Korea)\n 'pl', // Polish\n 'pt-br', // Portuguese (Brazil)\n 'ru', // Russian\n 'th', // Thai\n 'uk', // Ukrainian\n];\nconst rtlLocales = [\n 'ar', // Arabic\n 'he', // Hebrew\n 'fa', // Farsi (not currently supported)\n 'fa-ir', // Farsi Iran\n 'ur', // Urdu (not currently supported)\n];\n\nlet config = null;\nlet loggingService = null;\nlet messages = null;\n\n/**\n * @memberof module:Internationalization\n *\n * Prior versions of react-intl (our primary implementation of the i18n service) included a\n * PropTypes-based 'shape' for its `intl` object. This has since been removed. For legacy\n * compatibility, we include an `intlShape` export that is set to PropTypes.object. Usage of this\n * export is deprecated.\n *\n * @deprecated\n */\nexport const intlShape = PropTypes.object;\n\n/**\n *\n * @ignore\n * @returns {LoggingService}\n */\nexport const getLoggingService = () => loggingService;\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_TOPIC = 'LOCALE';\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_CHANGED = `${LOCALE_TOPIC}.CHANGED`;\n\n/**\n *\n * @memberof module:Internationalization\n * @returns {Cookies}\n */\nexport function getCookies() {\n return cookies;\n}\n\n/**\n * Some of our dependencies function on primary language subtags, rather than full locales.\n * This function strips a locale down to that first subtag. Depending on the code, this\n * may be 2 or more characters.\n *\n * @param {string} code\n * @memberof module:Internationalization\n */\nexport function getPrimaryLanguageSubtag(code) {\n return code.split('-')[0];\n}\n\n/**\n * Finds the closest supported locale to the one provided. This is done in three steps:\n *\n * 1. Returning the locale itself if its exact language code is supported.\n * 2. Returning the primary language subtag of the language code if it is supported (ar for ar-eg,\n * for instance).\n * 3. Returning 'en' if neither of the above produce a supported locale.\n *\n * @param {string} locale\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function findSupportedLocale(locale) {\n if (messages[locale] !== undefined) {\n return locale;\n }\n\n if (messages[getPrimaryLanguageSubtag(locale)] !== undefined) {\n return getPrimaryLanguageSubtag(locale);\n }\n\n return 'en';\n}\n\n/**\n * Get the locale from the cookie or, failing that, the browser setting.\n * Gracefully fall back to a more general primary language subtag or to English (en)\n * if we don't support that language.\n *\n * @param {string} locale If a locale is provided, returns the closest supported locale. Optional.\n * @throws An error if i18n has not yet been configured.\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function getLocale(locale) {\n if (messages === null) {\n throw new Error('getLocale called before configuring i18n. Call configure with messages first.');\n }\n // 1. Explicit application request\n if (locale !== undefined) {\n return findSupportedLocale(locale);\n }\n // 2. User setting in cookie\n const cookieLangPref = cookies\n .get(config.LANGUAGE_PREFERENCE_COOKIE_NAME);\n if (cookieLangPref) {\n return findSupportedLocale(cookieLangPref.toLowerCase());\n }\n // 3. Browser language (default)\n // Note that some browers prefer upper case for the region part of the locale, while others don't.\n // Thus the toLowerCase, for consistency.\n // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language\n return findSupportedLocale(global.navigator.language.toLowerCase());\n}\n\n/**\n * Returns messages for the provided locale, or the user's preferred locale if no argument is\n * provided.\n *\n * @param {string} [locale=getLocale()]\n * @memberof module:Internationalization\n */\nexport function getMessages(locale = getLocale()) {\n return messages[locale];\n}\n\n/**\n * Determines if the provided locale is a right-to-left language.\n *\n * @param {string} locale\n * @memberof module:Internationalization\n */\nexport function isRtl(locale) {\n return rtlLocales.includes(locale);\n}\n\n/**\n * Handles applying the RTL stylesheet and \"dir=rtl\" attribute to the html tag if the current locale\n * is a RTL language.\n *\n * @memberof module:Internationalization\n */\nexport function handleRtl() {\n if (isRtl(getLocale())) {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');\n } else {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');\n }\n}\n\nconst messagesShape = {\n ar: PropTypes.objectOf(PropTypes.string), // Arabic\n en: PropTypes.objectOf(PropTypes.string),\n 'es-419': PropTypes.objectOf(PropTypes.string), // Spanish, Latin American\n fr: PropTypes.objectOf(PropTypes.string), // French\n 'zh-cn': PropTypes.objectOf(PropTypes.string), // Chinese, Simplified\n ca: PropTypes.objectOf(PropTypes.string), // Catalan\n he: PropTypes.objectOf(PropTypes.string), // Hebrew\n id: PropTypes.objectOf(PropTypes.string), // Indonesian\n 'ko-kr': PropTypes.objectOf(PropTypes.string), // Korean (Korea)\n pl: PropTypes.objectOf(PropTypes.string), // Polish\n 'pt-br': PropTypes.objectOf(PropTypes.string), // Portuguese (Brazil)\n ru: PropTypes.objectOf(PropTypes.string), // Russian\n th: PropTypes.objectOf(PropTypes.string), // Thai\n uk: PropTypes.objectOf(PropTypes.string), // Ukrainian\n};\n\nconst optionsShape = {\n config: PropTypes.object.isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n }).isRequired,\n messages: PropTypes.oneOfType([\n PropTypes.shape(messagesShape),\n PropTypes.arrayOf(PropTypes.shape(messagesShape)),\n ]).isRequired,\n};\n\n/**\n *\n *\n * @param {Array} [messagesArray=[]]\n * @returns {Object}\n * @memberof module:Internationalization\n */\nexport function mergeMessages(messagesArray = []) {\n return Array.isArray(messagesArray) ? merge({}, ...messagesArray) : {};\n}\n\n/**\n * Configures the i18n library with messages for your application.\n *\n * Logs a warning if it detects a locale it doesn't expect (as defined by the supportedLocales list\n * above), or if an expected locale is not provided.\n *\n * @param {Object} options\n * @param {LoggingService} options.loggingService\n * @param {Object} options.config\n * @param {Object} options.messages\n * @memberof module:Internationalization\n */\nexport function configure(options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');\n // eslint-disable-next-line prefer-destructuring\n loggingService = options.loggingService;\n // eslint-disable-next-line prefer-destructuring\n config = options.config;\n messages = Array.isArray(options.messages) ? mergeMessages(options.messages) : options.messages;\n\n if (config.ENVIRONMENT !== 'production') {\n Object.keys(messages).forEach((key) => {\n if (supportedLocales.indexOf(key) < 0) {\n console.warn(`Unexpected locale: ${key}`); // eslint-disable-line no-console\n }\n });\n\n supportedLocales.forEach((key) => {\n if (messages[key] === undefined) {\n console.warn(`Missing locale: ${key}`); // eslint-disable-line no-console\n }\n });\n }\n\n handleRtl();\n}\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,YAAtB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,KAAP,MAAkB,cAAlB;AAEA,OAAO,qCAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AAEA,OAAO,4CAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,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,OAAO,CAACxD,MAAjB;EACAE,QAAQ,GAAGmD,KAAK,CAACC,OAAN,CAAcE,OAAO,CAACtD,QAAtB,IAAkCiD,aAAa,CAACK,OAAO,CAACtD,QAAT,CAA/C,GAAoEsD,OAAO,CAACtD,QAAvF;;EAEA,IAAIF,MAAM,CAAC0D,WAAP,KAAuB,YAA3B,EAAyC;IACvCC,MAAM,CAACC,IAAP,CAAY1D,QAAZ,EAAsB2D,OAAtB,CAA8B,UAACC,GAAD,EAAS;MACrC,IAAIhE,gBAAgB,CAACiE,OAAjB,CAAyBD,GAAzB,IAAgC,CAApC,EAAuC;QACrCE,OAAO,CAACC,IAAR,8BAAmCH,GAAnC,GADqC,CACM;MAC5C;IACF,CAJD;IAMAhE,gBAAgB,CAAC+D,OAAjB,CAAyB,UAACC,GAAD,EAAS;MAChC,IAAI5D,QAAQ,CAAC4D,GAAD,CAAR,KAAkBhD,SAAtB,EAAiC;QAC/BkD,OAAO,CAACC,IAAR,2BAAgCH,GAAhC,GAD+B,CACS;MACzC;IACF,CAJD;EAKD;;EAEDnC,SAAS;AACV"}
|
|
1
|
+
{"version":3,"file":"lib.js","names":["PropTypes","Cookies","merge","cookies","supportedLocales","rtlLocales","config","loggingService","messages","intlShape","object","getLoggingService","LOCALE_TOPIC","LOCALE_CHANGED","concat","getCookies","getPrimaryLanguageSubtag","code","split","findSupportedLocale","locale","undefined","getLocale","Error","cookieLangPref","get","LANGUAGE_PREFERENCE_COOKIE_NAME","toLowerCase","global","navigator","language","getMessages","arguments","length","isRtl","includes","handleRtl","document","getElementsByTagName","setAttribute","messagesShape","ar","objectOf","string","en","fr","ca","he","id","pl","ru","th","uk","optionsShape","isRequired","shape","logError","func","oneOfType","arrayOf","mergeMessages","messagesArray","Array","isArray","apply","_toConsumableArray","configure","options","checkPropTypes","ENVIRONMENT","Object","keys","forEach","key","indexOf","console","warn"],"sources":["../../src/i18n/lib.js"],"sourcesContent":["import PropTypes from 'prop-types';\nimport Cookies from 'universal-cookie';\nimport merge from 'lodash.merge';\n\nimport '@formatjs/intl-pluralrules/polyfill';\nimport '@formatjs/intl-pluralrules/locale-data/ar';\nimport '@formatjs/intl-pluralrules/locale-data/en';\nimport '@formatjs/intl-pluralrules/locale-data/es';\nimport '@formatjs/intl-pluralrules/locale-data/fr';\nimport '@formatjs/intl-pluralrules/locale-data/zh';\nimport '@formatjs/intl-pluralrules/locale-data/ca';\nimport '@formatjs/intl-pluralrules/locale-data/he';\nimport '@formatjs/intl-pluralrules/locale-data/id';\nimport '@formatjs/intl-pluralrules/locale-data/ko';\nimport '@formatjs/intl-pluralrules/locale-data/pl';\nimport '@formatjs/intl-pluralrules/locale-data/pt';\nimport '@formatjs/intl-pluralrules/locale-data/ru';\nimport '@formatjs/intl-pluralrules/locale-data/th';\nimport '@formatjs/intl-pluralrules/locale-data/uk';\n\nimport '@formatjs/intl-relativetimeformat/polyfill';\nimport '@formatjs/intl-relativetimeformat/locale-data/ar';\nimport '@formatjs/intl-relativetimeformat/locale-data/en';\nimport '@formatjs/intl-relativetimeformat/locale-data/es';\nimport '@formatjs/intl-relativetimeformat/locale-data/fr';\nimport '@formatjs/intl-relativetimeformat/locale-data/zh';\nimport '@formatjs/intl-relativetimeformat/locale-data/ca';\nimport '@formatjs/intl-relativetimeformat/locale-data/he';\nimport '@formatjs/intl-relativetimeformat/locale-data/id';\nimport '@formatjs/intl-relativetimeformat/locale-data/ko';\nimport '@formatjs/intl-relativetimeformat/locale-data/pl';\nimport '@formatjs/intl-relativetimeformat/locale-data/pt';\nimport '@formatjs/intl-relativetimeformat/locale-data/ru';\nimport '@formatjs/intl-relativetimeformat/locale-data/th';\nimport '@formatjs/intl-relativetimeformat/locale-data/uk';\n\nconst cookies = new Cookies();\nconst supportedLocales = [\n 'ar', // Arabic\n // NOTE: 'en' is not included in this list intentionally, since it's the fallback.\n 'es-419', // Spanish, Latin American\n 'fa', // Farsi\n 'fa-ir', // Farsi, Iran\n 'fr', // French\n 'zh-cn', // Chinese, Simplified\n 'ca', // Catalan\n 'he', // Hebrew\n 'id', // Indonesian\n 'ko-kr', // Korean (Korea)\n 'pl', // Polish\n 'pt-br', // Portuguese (Brazil)\n 'ru', // Russian\n 'th', // Thai\n 'uk', // Ukrainian\n];\nconst rtlLocales = [\n 'ar', // Arabic\n 'he', // Hebrew\n 'fa', // Farsi (not currently supported)\n 'fa-ir', // Farsi Iran\n 'ur', // Urdu (not currently supported)\n];\n\nlet config = null;\nlet loggingService = null;\nlet messages = null;\n\n/**\n * @memberof module:Internationalization\n *\n * Prior versions of react-intl (our primary implementation of the i18n service) included a\n * PropTypes-based 'shape' for its `intl` object. This has since been removed. For legacy\n * compatibility, we include an `intlShape` export that is set to PropTypes.object. Usage of this\n * export is deprecated.\n *\n * @deprecated\n */\nexport const intlShape = PropTypes.object;\n\n/**\n *\n * @ignore\n * @returns {LoggingService}\n */\nexport const getLoggingService = () => loggingService;\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_TOPIC = 'LOCALE';\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_CHANGED = `${LOCALE_TOPIC}.CHANGED`;\n\n/**\n *\n * @memberof module:Internationalization\n * @returns {Cookies}\n */\nexport function getCookies() {\n return cookies;\n}\n\n/**\n * Some of our dependencies function on primary language subtags, rather than full locales.\n * This function strips a locale down to that first subtag. Depending on the code, this\n * may be 2 or more characters.\n *\n * @param {string} code\n * @memberof module:Internationalization\n */\nexport function getPrimaryLanguageSubtag(code) {\n return code.split('-')[0];\n}\n\n/**\n * Finds the closest supported locale to the one provided. This is done in three steps:\n *\n * 1. Returning the locale itself if its exact language code is supported.\n * 2. Returning the primary language subtag of the language code if it is supported (ar for ar-eg,\n * for instance).\n * 3. Returning 'en' if neither of the above produce a supported locale.\n *\n * @param {string} locale\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function findSupportedLocale(locale) {\n if (messages[locale] !== undefined) {\n return locale;\n }\n\n if (messages[getPrimaryLanguageSubtag(locale)] !== undefined) {\n return getPrimaryLanguageSubtag(locale);\n }\n\n return 'en';\n}\n\n/**\n * Get the locale from the cookie or, failing that, the browser setting.\n * Gracefully fall back to a more general primary language subtag or to English (en)\n * if we don't support that language.\n *\n * @param {string} locale If a locale is provided, returns the closest supported locale. Optional.\n * @throws An error if i18n has not yet been configured.\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function getLocale(locale) {\n if (messages === null) {\n throw new Error('getLocale called before configuring i18n. Call configure with messages first.');\n }\n // 1. Explicit application request\n if (locale !== undefined) {\n return findSupportedLocale(locale);\n }\n // 2. User setting in cookie\n const cookieLangPref = cookies\n .get(config.LANGUAGE_PREFERENCE_COOKIE_NAME);\n if (cookieLangPref) {\n return findSupportedLocale(cookieLangPref.toLowerCase());\n }\n // 3. Browser language (default)\n // Note that some browers prefer upper case for the region part of the locale, while others don't.\n // Thus the toLowerCase, for consistency.\n // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language\n return findSupportedLocale(global.navigator.language.toLowerCase());\n}\n\n/**\n * Returns messages for the provided locale, or the user's preferred locale if no argument is\n * provided.\n *\n * @param {string} [locale=getLocale()]\n * @memberof module:Internationalization\n */\nexport function getMessages(locale = getLocale()) {\n return messages[locale];\n}\n\n/**\n * Determines if the provided locale is a right-to-left language.\n *\n * @param {string} locale\n * @memberof module:Internationalization\n */\nexport function isRtl(locale) {\n return rtlLocales.includes(locale);\n}\n\n/**\n * Handles applying the RTL stylesheet and \"dir=rtl\" attribute to the html tag if the current locale\n * is a RTL language.\n *\n * @memberof module:Internationalization\n */\nexport function handleRtl() {\n if (isRtl(getLocale())) {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');\n } else {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');\n }\n}\n\nconst messagesShape = {\n ar: PropTypes.objectOf(PropTypes.string), // Arabic\n en: PropTypes.objectOf(PropTypes.string),\n 'es-419': PropTypes.objectOf(PropTypes.string), // Spanish, Latin American\n fr: PropTypes.objectOf(PropTypes.string), // French\n 'zh-cn': PropTypes.objectOf(PropTypes.string), // Chinese, Simplified\n ca: PropTypes.objectOf(PropTypes.string), // Catalan\n he: PropTypes.objectOf(PropTypes.string), // Hebrew\n id: PropTypes.objectOf(PropTypes.string), // Indonesian\n 'ko-kr': PropTypes.objectOf(PropTypes.string), // Korean (Korea)\n pl: PropTypes.objectOf(PropTypes.string), // Polish\n 'pt-br': PropTypes.objectOf(PropTypes.string), // Portuguese (Brazil)\n ru: PropTypes.objectOf(PropTypes.string), // Russian\n th: PropTypes.objectOf(PropTypes.string), // Thai\n uk: PropTypes.objectOf(PropTypes.string), // Ukrainian\n};\n\nconst optionsShape = {\n config: PropTypes.object.isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n }).isRequired,\n messages: PropTypes.oneOfType([\n PropTypes.shape(messagesShape),\n PropTypes.arrayOf(PropTypes.shape(messagesShape)),\n ]).isRequired,\n};\n\n/**\n *\n *\n * @param {Array} [messagesArray=[]]\n * @returns {Object}\n * @memberof module:Internationalization\n */\nexport function mergeMessages(messagesArray = []) {\n return Array.isArray(messagesArray) ? merge({}, ...messagesArray) : {};\n}\n\n/**\n * Configures the i18n library with messages for your application.\n *\n * Logs a warning if it detects a locale it doesn't expect (as defined by the supportedLocales list\n * above), or if an expected locale is not provided.\n *\n * @param {Object} options\n * @param {LoggingService} options.loggingService\n * @param {Object} options.config\n * @param {Object} options.messages\n * @memberof module:Internationalization\n */\nexport function configure(options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');\n // eslint-disable-next-line prefer-destructuring\n loggingService = options.loggingService;\n // eslint-disable-next-line prefer-destructuring\n config = options.config;\n messages = Array.isArray(options.messages) ? mergeMessages(options.messages) : options.messages;\n\n if (config.ENVIRONMENT !== 'production') {\n Object.keys(messages).forEach((key) => {\n if (supportedLocales.indexOf(key) < 0) {\n console.warn(`Unexpected locale: ${key}`); // eslint-disable-line no-console\n }\n });\n\n supportedLocales.forEach((key) => {\n if (messages[key] === undefined) {\n console.warn(`Missing locale: ${key}`); // eslint-disable-line no-console\n }\n });\n }\n\n handleRtl();\n}\n"],"mappings":";;;;;;AAAA,OAAOA,SAAS,MAAM,YAAY;AAClC,OAAOC,OAAO,MAAM,kBAAkB;AACtC,OAAOC,KAAK,MAAM,cAAc;AAEhC,OAAO,qCAAqC;AAC5C,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAElD,OAAO,4CAA4C;AACnD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AAEzD,IAAMC,OAAO,GAAG,IAAIF,OAAO,EAAE;AAC7B,IAAMG,gBAAgB,GAAG,CACvB,IAAI;AAAE;AACN;AACA,QAAQ;AAAE;AACV,IAAI;AAAE;AACN,OAAO;AAAE;AACT,IAAI;AAAE;AACN,OAAO;AAAE;AACT,IAAI;AAAE;AACN,IAAI;AAAE;AACN,IAAI;AAAE;AACN,OAAO;AAAE;AACT,IAAI;AAAE;AACN,OAAO;AAAE;AACT,IAAI;AAAE;AACN,IAAI;AAAE;AACN,IAAI,CAAE;AAAA,CACP;;AACD,IAAMC,UAAU,GAAG,CACjB,IAAI;AAAE;AACN,IAAI;AAAE;AACN,IAAI;AAAE;AACN,OAA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gB,CAACsE,OAAO,CAACD,GAAG,CAAC,GAAG,CAAC,EAAE;QACrCE,OAAO,CAACC,IAAI,uBAAA9D,MAAA,CAAuB2D,GAAG,EAAG,CAAC,CAAC;MAC7C;IACF,CAAC,CAAC;;IAEFrE,gBAAgB,CAACoE,OAAO,CAAC,UAACC,GAAG,EAAK;MAChC,IAAIjE,QAAQ,CAACiE,GAAG,CAAC,KAAKpD,SAAS,EAAE;QAC/BsD,OAAO,CAACC,IAAI,oBAAA9D,MAAA,CAAoB2D,GAAG,EAAG,CAAC,CAAC;MAC1C;IACF,CAAC,CAAC;EACJ;;EAEArC,SAAS,EAAE;AACb"}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
2
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
-
|
|
5
3
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
-
|
|
7
4
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
5
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
|
|
11
6
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
-
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
-
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
8
|
var fs = require('fs');
|
|
16
|
-
|
|
17
9
|
var glob = require('glob');
|
|
18
|
-
|
|
19
10
|
var path = require('path');
|
|
11
|
+
|
|
20
12
|
/*
|
|
21
13
|
* See the Makefile for how the required hash file is downloaded from Transifex.
|
|
22
14
|
*/
|
|
@@ -27,8 +19,6 @@ var path = require('path');
|
|
|
27
19
|
*
|
|
28
20
|
*
|
|
29
21
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
22
|
function gatherJson(dir) {
|
|
33
23
|
var ret = [];
|
|
34
24
|
var files = glob.sync("".concat(dir, "/**/*.json"));
|
|
@@ -37,27 +27,23 @@ function gatherJson(dir) {
|
|
|
37
27
|
ret.push.apply(ret, _toConsumableArray(messages));
|
|
38
28
|
});
|
|
39
29
|
return ret;
|
|
40
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// the hash file returns ids whose periods are "escaped" (sort of), like this:
|
|
41
33
|
// "key": "profile\\.sociallinks\\.social\\.links"
|
|
42
34
|
// so our regular messageIds won't match them out of the box
|
|
43
|
-
|
|
44
|
-
|
|
45
35
|
function escapeDots(messageId) {
|
|
46
36
|
return messageId.replace(/\./g, '\\.');
|
|
47
37
|
}
|
|
48
|
-
|
|
49
38
|
var jsonDir = process.argv[2];
|
|
50
39
|
var messageObjects = gatherJson(jsonDir);
|
|
51
|
-
|
|
52
40
|
if (messageObjects.length === 0) {
|
|
53
41
|
process.exitCode = 1;
|
|
54
42
|
throw new Error('Found no messages');
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
if (process.argv[3] === '--comments') {
|
|
58
45
|
// prepare to handle the translator notes
|
|
59
46
|
var loggingPrefix = path.basename("".concat(__filename)); // the name of this JS file
|
|
60
|
-
|
|
61
47
|
var bashScriptsPath = process.argv[4] && process.argv[4] === '--v3-scripts-path' ? './node_modules/@edx/reactifex/bash_scripts' : './node_modules/reactifex/bash_scripts';
|
|
62
48
|
var hashFile = "".concat(bashScriptsPath, "/hashmap.json");
|
|
63
49
|
process.stdout.write("".concat(loggingPrefix, ": reading hash file ").concat(hashFile, "\n"));
|
|
@@ -70,7 +56,6 @@ if (process.argv[3] === '--comments') {
|
|
|
70
56
|
var info = messageInfo.find(function (mi) {
|
|
71
57
|
return mi.key === transifexFormatId;
|
|
72
58
|
});
|
|
73
|
-
|
|
74
59
|
if (info) {
|
|
75
60
|
fs.appendFileSync(outputFile, "".concat(info.string_hash, "|").concat(message.description, "\n"));
|
|
76
61
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transifex-utils.js","names":["fs","require","glob","path","gatherJson","dir","ret","files","sync","forEach","filename","messages","JSON","parse","readFileSync","push","escapeDots","messageId","replace","jsonDir","process","argv","messageObjects","
|
|
1
|
+
{"version":3,"file":"transifex-utils.js","names":["_toConsumableArray","arr","_arrayWithoutHoles","_iterableToArray","_unsupportedIterableToArray","_nonIterableSpread","TypeError","o","minLen","_arrayLikeToArray","n","Object","prototype","toString","call","slice","constructor","name","Array","from","test","iter","Symbol","iterator","isArray","len","length","i","arr2","fs","require","glob","path","gatherJson","dir","ret","files","sync","concat","forEach","filename","messages","JSON","parse","readFileSync","push","apply","escapeDots","messageId","replace","jsonDir","process","argv","messageObjects","exitCode","Error","loggingPrefix","basename","__filename","bashScriptsPath","hashFile","stdout","write","messageInfo","outputFile","writeFileSync","message","transifexFormatId","id","info","find","mi","key","appendFileSync","string_hash","description","output","defaultMessage","stringify"],"sources":["../../../src/i18n/scripts/transifex-utils.js"],"sourcesContent":["#!/usr/bin/env node\n\nconst fs = require('fs');\nconst glob = require('glob');\nconst path = require('path');\n\n/*\n * See the Makefile for how the required hash file is downloaded from Transifex.\n */\n\n/*\n * Expected input: a directory, possibly containing subdirectories, with .json files. Each .json\n * file is an array of translation triplets (id, description, defaultMessage).\n *\n *\n */\nfunction gatherJson(dir) {\n const ret = [];\n const files = glob.sync(`${dir}/**/*.json`);\n\n files.forEach((filename) => {\n const messages = JSON.parse(fs.readFileSync(filename));\n ret.push(...messages);\n });\n return ret;\n}\n\n// the hash file returns ids whose periods are \"escaped\" (sort of), like this:\n// \"key\": \"profile\\\\.sociallinks\\\\.social\\\\.links\"\n// so our regular messageIds won't match them out of the box\nfunction escapeDots(messageId) {\n return messageId.replace(/\\./g, '\\\\.');\n}\n\nconst jsonDir = process.argv[2];\nconst messageObjects = gatherJson(jsonDir);\n\nif (messageObjects.length === 0) {\n process.exitCode = 1;\n throw new Error('Found no messages');\n}\n\nif (process.argv[3] === '--comments') { // prepare to handle the translator notes\n const loggingPrefix = path.basename(`${__filename}`); // the name of this JS file\n const bashScriptsPath = (\n process.argv[4] && process.argv[4] === '--v3-scripts-path'\n ? './node_modules/@edx/reactifex/bash_scripts'\n : './node_modules/reactifex/bash_scripts');\n\n const hashFile = `${bashScriptsPath}/hashmap.json`;\n process.stdout.write(`${loggingPrefix}: reading hash file ${hashFile}\\n`);\n const messageInfo = JSON.parse(fs.readFileSync(hashFile));\n\n const outputFile = `${bashScriptsPath}/hashed_data.txt`;\n process.stdout.write(`${loggingPrefix}: writing to output file ${outputFile}\\n`);\n fs.writeFileSync(outputFile, '');\n\n messageObjects.forEach((message) => {\n const transifexFormatId = escapeDots(message.id);\n\n const info = messageInfo.find(mi => mi.key === transifexFormatId);\n if (info) {\n fs.appendFileSync(outputFile, `${info.string_hash}|${message.description}\\n`);\n } else {\n process.stdout.write(`${loggingPrefix}: string ${message.id} does not yet exist on transifex!\\n`);\n }\n });\n} else {\n const output = {};\n\n messageObjects.forEach((message) => {\n output[message.id] = message.defaultMessage;\n });\n fs.writeFileSync(process.argv[3], JSON.stringify(output, null, 2));\n}\n"],"mappings":"AAAA;AAAmB,SAAAA,mBAAAC,GAAA,WAAAC,kBAAA,CAAAD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AACC,IAAI,CAAC,CAAC,CAAC,EAAEV,IAAI,CAACoC,SAAS,CAACF,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACpE"}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["modifyObjectKeys","camelCaseObject","snakeCaseObject","convertKeyNames","getQueryParameters","ensureDefinedConfig","APP_TOPIC","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","CONFIG_TOPIC","CONFIG_CHANGED","initialize","history","initError","auth","publish","subscribe","unsubscribe","getConfig","setConfig","mergeConfig","ensureConfig","initializeMockApp","mockMessages"],"sources":["../src/index.js"],"sourcesContent":["export {\n modifyObjectKeys,\n camelCaseObject,\n snakeCaseObject,\n convertKeyNames,\n getQueryParameters,\n ensureDefinedConfig,\n} from './utils';\nexport {\n APP_TOPIC,\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY,\n APP_INIT_ERROR,\n CONFIG_TOPIC,\n CONFIG_CHANGED,\n} from './constants';\nexport {\n initialize,\n history,\n initError,\n auth,\n} from './initialize';\nexport {\n publish,\n subscribe,\n unsubscribe,\n} from './pubSub';\nexport {\n getConfig,\n setConfig,\n mergeConfig,\n ensureConfig,\n} from './config';\nexport {\n initializeMockApp,\n mockMessages,\n} from './testing';\n"],"mappings":"AAAA,SACEA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["modifyObjectKeys","camelCaseObject","snakeCaseObject","convertKeyNames","getQueryParameters","ensureDefinedConfig","APP_TOPIC","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","CONFIG_TOPIC","CONFIG_CHANGED","initialize","history","initError","auth","publish","subscribe","unsubscribe","getConfig","setConfig","mergeConfig","ensureConfig","initializeMockApp","mockMessages"],"sources":["../src/index.js"],"sourcesContent":["export {\n modifyObjectKeys,\n camelCaseObject,\n snakeCaseObject,\n convertKeyNames,\n getQueryParameters,\n ensureDefinedConfig,\n} from './utils';\nexport {\n APP_TOPIC,\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY,\n APP_INIT_ERROR,\n CONFIG_TOPIC,\n CONFIG_CHANGED,\n} from './constants';\nexport {\n initialize,\n history,\n initError,\n auth,\n} from './initialize';\nexport {\n publish,\n subscribe,\n unsubscribe,\n} from './pubSub';\nexport {\n getConfig,\n setConfig,\n mergeConfig,\n ensureConfig,\n} from './config';\nexport {\n initializeMockApp,\n mockMessages,\n} from './testing';\n"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,kBAAkB,EAClBC,mBAAmB,QACd,SAAS;AAChB,SACEC,SAAS,EACTC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,oBAAoB,EACpBC,uBAAuB,EACvBC,yBAAyB,EACzBC,SAAS,EACTC,cAAc,EACdC,YAAY,EACZC,cAAc,QACT,aAAa;AACpB,SACEC,UAAU,EACVC,OAAO,EACPC,SAAS,EACTC,IAAI,QACC,cAAc;AACrB,SACEC,OAAO,EACPC,SAAS,EACTC,WAAW,QACN,UAAU;AACjB,SACEC,SAAS,EACTC,SAAS,EACTC,WAAW,EACXC,YAAY,QACP,UAAU;AACjB,SACEC,iBAAiB,EACjBC,YAAY,QACP,WAAW"}
|