+ /**
+ * Returns the language string object corresponding to the provided
+ * value and language.
+ */
+ const getLangString = (value, language = "") => {
+ const valueMap = languageMap[language] ??= Object.create(null);
+ const literal = valueMap[value]?.deref();
+ if (literal != null) {
+ // There is already an object corresponding to the provided value
+ // and language.
+ return literal;
+ } else {
+ // No object already exists corresponding to the provided value
+ // and language; create one.
+ const result = Object.preventExtensions(
+ Object.create(String.prototype, {
+ "@value": {
+ enumerable: true,
+ value,
+ },
+ "@language": {
+ enumerable: !!language,
+ value: language || null,
+ },
+ language: { enumerable: false, get: getLanguage },
+ toString: { enumerable: false, value: toString },
+ valueOf: { enumerable: false, value: valueOf },
+ }),
+ );
+ const ref = new WeakRef(result);
+ langStringRegistry.register(result, { ref, language, value });
+ valueMap[value] = ref;
+ return result;
+ }
+ };
+