Update country-coder to 2.0.0 (close #7029)

Localize address field in walkthrough without overwriting country coder function
This commit is contained in:
Quincy Morgan
2019-11-07 18:45:46 +01:00
parent 2a4841f517
commit d89996e52c
8 changed files with 21 additions and 22 deletions
+10 -4
View File
@@ -1,9 +1,9 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { dataAddressFormats } from '../../../data';
import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
@@ -208,9 +208,15 @@ export function uiFieldAddress(field, context) {
.attr('class', 'form-field-input-wrap form-field-input-' + field.type)
.merge(wrap);
if (services.countryCoder && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
if (_entity) {
var countryCode;
if (context.inIntro()) {
// localize the address format for the walkthrough
countryCode = t('intro.graph.countrycode');
} else {
var center = _entity.extent(context.graph()).center();
countryCode = countryCoder.iso1A2Code(center);
}
if (countryCode) updateForCountryCode(countryCode);
}
}
+2 -2
View File
@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { event as d3_event, select as d3_select } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { osmEntity } from '../../osm/entity';
import { t } from '../../util/locale';
@@ -17,7 +18,6 @@ export {
export function uiFieldCombo(field, context) {
var dispatch = d3_dispatch('change');
var countryCoder = services.countryCoder;
var taginfo = services.taginfo;
var isMulti = (field.type === 'multiCombo');
var isNetwork = (field.type === 'networkCombo');
@@ -351,7 +351,7 @@ export function uiFieldCombo(field, context) {
.call(initCombo, selection)
.merge(input);
if (isNetwork && countryCoder && _entity) {
if (isNetwork && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = countryCoder.iso1A2Code(center);
_countryCode = countryCode && countryCode.toLowerCase();
+3 -2
View File
@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select, event as d3_event } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { t, textDirection } from '../../util/locale';
import { dataPhoneFormats } from '../../../data';
@@ -55,9 +56,9 @@ export function uiFieldText(field, context) {
.on('change', change());
if (field.type === 'tel' && services.countryCoder && _entity) {
if (field.type === 'tel' && _entity) {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
var countryCode = countryCoder.iso1A2Code(center);
var format = countryCode && dataPhoneFormats[countryCode.toLowerCase()];
if (format) {
wrap.selectAll('#' + fieldID)
+2 -1
View File
@@ -1,5 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select, event as d3_event } from 'd3-selection';
import * as countryCoder from 'country-coder';
import { currentLocale, t, languageName } from '../../util/locale';
import { dataLanguages } from '../../../data';
@@ -574,7 +575,7 @@ export function uiFieldLocalized(field, context) {
function loadCountryCode() {
var center = _entity.extent(context.graph()).center();
var countryCode = services.countryCoder.iso1A2Code(center);
var countryCode = countryCoder.iso1A2Code(center);
_countryCode = countryCode && countryCode.toLowerCase();
}