From 67bd692bc02c7fbf9a39792ca5dd1c9c70702a5f Mon Sep 17 00:00:00 2001 From: William Edmisten Date: Sat, 21 May 2022 18:09:41 -0400 Subject: [PATCH] Add multilingual field exceptions (#9124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add multilingual field exceptions * Add name:etymology * Match language code in regex * Restrict ISO 15924 code to 4 letters * Allow country codes in name subkeys; match key case sensitively Co-authored-by: Minh Nguyễn --- modules/ui/fields/localized.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index 547eed76b..b59a55aa0 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -122,7 +122,10 @@ export function uiFieldLocalized(field, context) { var existingLangs = new Set(existingLangsOrdered.filter(Boolean)); for (var k in tags) { - var m = k.match(/^(.*):(.*)$/); + // 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})?)$/); if (m && m[1] === field.key && m[2]) { var item = { lang: m[2], value: tags[k] }; if (existingLangs.has(item.lang)) {