From 43c65bf9945495c54953fcdf0049fa894e77efbf Mon Sep 17 00:00:00 2001 From: Sam Ho Date: Tue, 16 Jul 2024 12:38:06 +0100 Subject: [PATCH 1/2] Fix localized field hidden despite nonempty subkeys (Closes#10323) --- modules/ui/field.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/ui/field.js b/modules/ui/field.js index c7f0f2ca5..b05b8d5de 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -97,6 +97,15 @@ export function uiField(context, presetField, entityIDs, options) { } return false; } + if (field.type === 'localized') { + for (let tagKey in _tags) { + // matches for field:, where is a BCP 47 locale code + let match = tagKey.match(/^(.*):([a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-[A-Z]{2})?)$/); + if (match && match[1] === field.key && match[2]) { + return true; + } + } + } return _tags[key] !== undefined; }); } From 42f274f73ff0f989333b652418b2528b567ef927 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Tue, 16 Jul 2024 17:04:49 +0200 Subject: [PATCH 2/2] move reused regex to exported constant --- modules/ui/field.js | 3 ++- modules/ui/fields/localized.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ui/field.js b/modules/ui/field.js index b05b8d5de..ca6932a8f 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -8,6 +8,7 @@ import { uiTooltip } from './tooltip'; import { geoExtent } from '../geo/extent'; import { uiFieldHelp } from './field_help'; import { uiFields } from './fields'; +import { LANGUAGE_SUFFIX_REGEX } from './fields/localized'; import { uiTagReference } from './tag_reference'; import { utilRebind, utilUniqueDomId } from '../util'; @@ -100,7 +101,7 @@ export function uiField(context, presetField, entityIDs, options) { if (field.type === 'localized') { for (let tagKey in _tags) { // matches for field:, where is a BCP 47 locale code - let match = tagKey.match(/^(.*):([a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-[A-Z]{2})?)$/); + let match = tagKey.match(LANGUAGE_SUFFIX_REGEX); if (match && match[1] === field.key && match[2]) { return true; } diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index 8726ce8c5..8d5850e8d 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -14,6 +14,7 @@ import { uiLengthIndicator } from '../length_indicator'; var _languagesArray = []; +export const LANGUAGE_SUFFIX_REGEX = /^(.*):([a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-[A-Z]{2})?)$/; export function uiFieldLocalized(field, context) { var dispatch = d3_dispatch('change', 'input'); @@ -127,7 +128,7 @@ export function uiFieldLocalized(field, context) { // matches for field:, where is a BCP 47 locale code // motivation is to avoid matching on similarly formatted tags that are // not for languages, e.g. name:left, name:source, etc. - var m = k.match(/^(.*):([a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-[A-Z]{2})?)$/); + var m = k.match(LANGUAGE_SUFFIX_REGEX); if (m && m[1] === field.key && m[2]) { var item = { lang: m[2], value: tags[k] }; if (existingLangs.has(item.lang)) {