Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, []);
}
const result: Entry[] = [];
const len = raw.length;
for (let i = 0; i < len; i++) {
const id = raw[i].trim();
const tag = parseLanguageTag(id);
// Preserve 'und' undefined locale. If we resolve it, adding
// likely subtags will expand it to 'en-Latn-US'.
if (tag.hasLanguage() || tag.hasScript() || tag.hasRegion()) {
result.push(new Entry(id, LanguageResolver.resolve(tag)));
} else {
// Preserve undefined core fields, but include input's extensions
result.push(new Entry(id, new LanguageTag(
undefined, undefined, undefined, undefined, tag.extensions(), tag.privateUse()
)));
}
}
return result;
};
const returnTag = (real: LanguageTag, fast: FastTag): LanguageTag => {
const language = fast[Tag.LANGUAGE];
const script = fast[Tag.SCRIPT];
const region = fast[Tag.REGION];
return new LanguageTag(
typeof language === 'number' ? undefined : language,
typeof script === 'number' ? undefined : script,
typeof region === 'number' ? undefined : region,
real.variant(),
real.extensions(),
real.privateUse()
);
};
import { parseLanguageTag, LanguageTag } from '@phensley/language-tag';
import { LanguageResolver } from './resolver';
const UNDEFINED = new LanguageTag();
/**
* Wrapper pairing an application's opaque locale identifier with a
* parsed and resolved language tag object.
*
* @alpha
*/
export interface Locale {
/**
* Application's own identifier for the locale, e.g. 'en_US', 'fr-CA', etc.
* We preserve this since applications may use it as a unique key to
* resolve translated messages, and may be forced to use a legacy
* identifier.
*/
readonly id: string;
}
for (let j = 0; j < this.count; j++) {
const supported = this.supported[j];
const distance = getDistance(desired.tag, supported.tag, threshold);
if (bestDistance === U || distance < bestDistance) {
bestDistance = distance;
bestMatch = supported;
bestDesired = desired;
}
}
}
const extensions = bestDesired.tag.extensions();
const privateUse = bestDesired.tag.privateUse();
const { id, tag } = bestMatch === U ? this.default : bestMatch;
const result = new LanguageTag(tag.language(), tag.script(), tag.region(), tag.variant(), extensions, privateUse);
return {
locale: { id, tag: result },
distance: bestMatch === U ? MAX_DISTANCE : bestDistance
};
}
}