@formatjs/intl-localematcher 0.5.2 → 0.5.4
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/abstract/utils.js +6 -5
- package/lib/abstract/utils.js +6 -5
- package/package.json +1 -1
package/abstract/utils.js
CHANGED
|
@@ -12,8 +12,8 @@ function invariant(condition, message, Err) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.invariant = invariant;
|
|
15
|
-
// This is effectively 2 languages in 2 different regions
|
|
16
|
-
var DEFAULT_MATCHING_THRESHOLD =
|
|
15
|
+
// This is effectively 2 languages in 2 different regions in the same cluster
|
|
16
|
+
var DEFAULT_MATCHING_THRESHOLD = 838;
|
|
17
17
|
var PROCESSED_DATA;
|
|
18
18
|
function processData() {
|
|
19
19
|
var _a, _b;
|
|
@@ -149,10 +149,11 @@ function findBestMatch(requestedLocales, supportedLocales, threshold) {
|
|
|
149
149
|
if (!result.distances[desired]) {
|
|
150
150
|
result.distances[desired] = {};
|
|
151
151
|
}
|
|
152
|
-
supportedLocales.forEach(function (supported
|
|
152
|
+
supportedLocales.forEach(function (supported) {
|
|
153
153
|
// Add some weight to the distance based on the order of the supported locales
|
|
154
|
-
// Add penalty for the order of the requested locales
|
|
155
|
-
|
|
154
|
+
// Add penalty for the order of the requested locales, which currently is 0 since ECMA-402
|
|
155
|
+
// doesn't really have room for weighted locales like `en; q=0.1`
|
|
156
|
+
var distance = findMatchingDistance(desired, supported) + 0 + i * 40;
|
|
156
157
|
result.distances[desired][supported] = distance;
|
|
157
158
|
if (distance < lowestDistance) {
|
|
158
159
|
lowestDistance = distance;
|
package/lib/abstract/utils.js
CHANGED
|
@@ -8,8 +8,8 @@ export function invariant(condition, message, Err) {
|
|
|
8
8
|
throw new Err(message);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
// This is effectively 2 languages in 2 different regions
|
|
12
|
-
var DEFAULT_MATCHING_THRESHOLD =
|
|
11
|
+
// This is effectively 2 languages in 2 different regions in the same cluster
|
|
12
|
+
var DEFAULT_MATCHING_THRESHOLD = 838;
|
|
13
13
|
var PROCESSED_DATA;
|
|
14
14
|
function processData() {
|
|
15
15
|
var _a, _b;
|
|
@@ -144,10 +144,11 @@ export function findBestMatch(requestedLocales, supportedLocales, threshold) {
|
|
|
144
144
|
if (!result.distances[desired]) {
|
|
145
145
|
result.distances[desired] = {};
|
|
146
146
|
}
|
|
147
|
-
supportedLocales.forEach(function (supported
|
|
147
|
+
supportedLocales.forEach(function (supported) {
|
|
148
148
|
// Add some weight to the distance based on the order of the supported locales
|
|
149
|
-
// Add penalty for the order of the requested locales
|
|
150
|
-
|
|
149
|
+
// Add penalty for the order of the requested locales, which currently is 0 since ECMA-402
|
|
150
|
+
// doesn't really have room for weighted locales like `en; q=0.1`
|
|
151
|
+
var distance = findMatchingDistance(desired, supported) + 0 + i * 40;
|
|
151
152
|
result.distances[desired][supported] = distance;
|
|
152
153
|
if (distance < lowestDistance) {
|
|
153
154
|
lowestDistance = distance;
|